[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/library/ezc/Graph/src/data_container/ -> base.php (source)

   1  <?php
   2  /**
   3   * File containing the abstract ezcGraphChartDataContainer class
   4   *
   5   * @package Graph
   6   * @version 1.5
   7   * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
   8   * @license http://ez.no/licenses/new_bsd New BSD License
   9   */
  10  /**
  11   * Container class for datasets used by the chart classes. Implements usefull
  12   * interfaces for convenient access to the datasets.
  13   *
  14   * @version 1.5
  15   * @package Graph
  16   */
  17  
  18  class ezcGraphChartDataContainer implements ArrayAccess, Iterator, Countable
  19  {
  20      /**
  21       * Contains the data of a chart
  22       * 
  23       * @var array(ezcGraphDataSet)
  24       */
  25      protected $data = array();
  26  
  27      /**
  28       * Chart using this data set storage
  29       * 
  30       * @var ezcGraphChart
  31       */
  32      protected $chart;
  33  
  34      /**
  35       * Constructor
  36       * 
  37       * @param ezcGraphChart $chart 
  38       * @ignore
  39       * @return void
  40       */
  41      public function __construct( ezcGraphChart $chart )
  42      {
  43          $this->chart = $chart;
  44      }
  45  
  46      /**
  47       * Adds a dataset to the charts data
  48       * 
  49       * @param string $name Name of dataset
  50       * @param ezcGraphDataSet $dataSet
  51       * @param mixed $values Values to create dataset with
  52       * @throws ezcGraphTooManyDataSetExceptions
  53       *          If too many datasets are created
  54       * @return ezcGraphDataSet
  55       */
  56      protected function addDataSet( $name, ezcGraphDataSet $dataSet )
  57      {
  58          $this->data[$name] = $dataSet;
  59          
  60          $this->data[$name]->label = $name;
  61          $this->data[$name]->palette = $this->chart->palette;
  62          $this->data[$name]->displayType = $this->chart->getDefaultDisplayType();
  63      }
  64  
  65      /**
  66       * Returns if the given offset exists.
  67       *
  68       * This method is part of the ArrayAccess interface to allow access to the
  69       * data of this object as if it was an array.
  70       * 
  71       * @param string $key Identifier of dataset.
  72       * @return bool True when the offset exists, otherwise false.
  73       */
  74      public function offsetExists( $key )
  75      {
  76          return isset( $this->data[$key] );
  77      }
  78  
  79      /**
  80       * Returns the element with the given offset. 
  81       *
  82       * This method is part of the ArrayAccess interface to allow access to the
  83       * data of this object as if it was an array. 
  84       * 
  85       * @param string $key Identifier of dataset.
  86       * @return ezcGraphDataSet
  87       *
  88       * @throws ezcGraphNoSuchDataSetException
  89       *         If no dataset with identifier exists
  90       */
  91      public function offsetGet( $key )
  92      {
  93          if ( !isset( $this->data[$key] ) )
  94          {
  95              throw new ezcGraphNoSuchDataSetException( $key );
  96          }
  97  
  98          return $this->data[$key];
  99      }
 100  
 101      /**
 102       * Set the element with the given offset. 
 103       *
 104       * This method is part of the ArrayAccess interface to allow access to the
 105       * data of this object as if it was an array. 
 106       * 
 107       * @param string $key
 108       * @param ezcGraphDataSet $value
 109       * @return void
 110       *
 111       * @throws ezcBaseValueException
 112       *         If supplied value is not an ezcGraphDataSet
 113       */
 114      public function offsetSet( $key, $value )
 115      {
 116          if ( !$value instanceof ezcGraphDataSet )
 117          {
 118              throw new ezcBaseValueException( $key, $value, 'ezcGraphDataSet' );
 119          }
 120  
 121          return $this->addDataSet( $key, $value );
 122      }
 123  
 124      /**
 125       * Unset the element with the given offset. 
 126       *
 127       * This method is part of the ArrayAccess interface to allow access to the
 128       * data of this object as if it was an array. 
 129       * 
 130       * @param string $key
 131       * @return void
 132       */
 133      public function offsetUnset( $key )
 134      {
 135          if ( !isset( $this->data[$key] ) )
 136          {
 137              throw new ezcGraphNoSuchDataSetException( $key );
 138          }
 139  
 140          unset( $this->data[$key] );
 141      }
 142  
 143      /**
 144       * Returns the currently selected dataset.
 145       *
 146       * This method is part of the Iterator interface to allow access to the 
 147       * datasets of this row by iterating over it like an array (e.g. using
 148       * foreach).
 149       * 
 150       * @return ezcGraphDataSet The currently selected dataset.
 151       */
 152      public function current()
 153      {
 154          return current( $this->data );
 155      }
 156  
 157      /**
 158       * Returns the next dataset and selects it or false on the last dataset.
 159       *
 160       * This method is part of the Iterator interface to allow access to the 
 161       * datasets of this row by iterating over it like an array (e.g. using
 162       * foreach).
 163       *
 164       * @return mixed ezcGraphDataSet if the next dataset exists, or false.
 165       */
 166      public function next()
 167      {
 168          return next( $this->data );
 169      }
 170  
 171      /**
 172       * Returns the key of the currently selected dataset.
 173       *
 174       * This method is part of the Iterator interface to allow access to the 
 175       * datasets of this row by iterating over it like an array (e.g. using
 176       * foreach).
 177       * 
 178       * @return int The key of the currently selected dataset.
 179       */
 180      public function key()
 181      {
 182          return key( $this->data );
 183      }
 184  
 185      /**
 186       * Returns if the current dataset is valid.
 187       *
 188       * This method is part of the Iterator interface to allow access to the 
 189       * datasets of this row by iterating over it like an array (e.g. using
 190       * foreach).
 191       *
 192       * @return bool If the current dataset is valid
 193       */
 194      public function valid()
 195      {
 196          return ( current( $this->data ) !== false );
 197      }
 198  
 199      /**
 200       * Selects the very first dataset and returns it.
 201       * This method is part of the Iterator interface to allow access to the 
 202       * datasets of this row by iterating over it like an array (e.g. using
 203       * foreach).
 204       *
 205       * @return ezcGraphDataSet The very first dataset.
 206       */
 207      public function rewind()
 208      {
 209          return reset( $this->data );
 210      }
 211  
 212      /**
 213       * Returns the number of datasets in the row.
 214       *
 215       * This method is part of the Countable interface to allow the usage of
 216       * PHP's count() function to check how many datasets exist.
 217       *
 218       * @return int Number of datasets.
 219       */
 220      public function count()
 221      {
 222          return count( $this->data );
 223      }
 224  }
 225  ?>


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7