<?php
/*=====================================================================*
|| ###################################################################
|| # WebFreeChart
|| # Copyright (c)2002-2007 Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
|| # the Free Software Foundation; version 2 of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/
include_once WFCDIR . '/Data/Abstract/DataSet.php';
include_once WFCDIR . '/Data/ArrayDataSet.php';
/**
* This data set represents a series of data, which in this case is
* an ArrayDataSet, along with a description and name. This is implemented
* as a set, meaning that there cannot be duplicate values
*
* @author rsesek
* @copyright Copyright (c)2002 - 2007, Blue Static
* @package WebFreeChart
*
*/
class SeriesDataSet implements DataSet
{
/**
* The key name
* @var string
*/
private $key;
/**
* Description for this series
* @var string
*/
private $description;
/**
* The actual data for the chart
*/
private $series = array();
// ###################################################################
/**
* Constructor
*
* @param string $key
* @param string $description
*/
public function __construct($key = null, $description = null)
{
$this->key = $key;
$this->description = $description;
}
// ###################################################################
/**
* Returns the key for the data set
*
* @return string
*/
public function getKey()
{
return $this->key;
}
// ###################################################################
/**
* Sets the key
*
* @param string $key
*/
public function setKey($key)
{
$this->key = $key;
}
// ###################################################################
/**
* Returns the description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
// ###################################################################
/**
* Sets the description
*
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
// ###################################################################
/**
* Checks whether or not the series already contains $val
*
* @param mixed $val
*
* @return boolean
*/
public function contains($val)
{
foreach ($this->series AS $_val)
{
if ($val == $_val)
{
return true;
}
}
return false;
}
// ###################################################################
/**
* Adds a given value and returns TRUE if the value was added, or FALSE
* if it already existed and was not added
*
* @return boolean
*/
public function add($val)
{
if ($this->contains($val))
{
return false;
}
$this->series[] = $val;
return true;
}
// ###################################################################
/**
* Removes a given value, returning TRUE if it was removed and FALSE
* if it does not exist in the series
*
* @return boolean
*/
public function remove($val)
{
foreach ($this->series AS $_key => $_val)
{
if ($val == $_val)
{
unset($this->series[$_key]);
return true;
}
}
return false;
}
}
?>