Documentation is available at DataParser.php
<?php /* ******************************************************************** DataParser.php - phpchartPlus DataParser class ******************************************************************** Author: Tsiavos Chris Email: jaames@freemail.gr Date: October 2004 ******************************************************************** */ /** *Includes the Group class, the common communication structure between *DataStrategy objects and DataParser */ require_once("DataStrategy_Interface.php"); class DataParser_Exception extends Exception { function DataParser_Exception($data) { Exception::__construct($data); } } /** *Class for importing chart data to the application *This class can be strategized with the appropriate Strategy Object to support the collection and *parsing of data in a way independent of the data source implementation details. This *feature allows the run-time selection of the data source based on some used-defined *parameters. *@final *@author Tsiavos Chris <jaames@freemail.gr> *@license http://opensource.org/licenses/gpl-license.php GNU Public License */ final class DataParser { /** *reference to the selected DataStrategy instance *@access private *@var mixed */ private $Parser_Strategy; /** *array of Group[] objects containing the parsed chart data returned by the selected Strategy Object *@access private *@var Group[] */ private $Parser_Results=array(); /** *Constructor */ function __construct() { } /** *Instructs the selected Strategy Object to collect and return the chart data *to DataParser for analysis *@access public *@return void *@throws DataParser_Exception *@param mixed $params Specifies an arbitrary number of parameters passed to the *sselected Strategy Object during data parsing */ public function parse($params=NULL) { if (!is_object($this->Parser_Strategy)) throw new DataParser_Exception("DataParser: No strategy found"); $this->Parser_Results=$this->Parser_Strategy->perform($params); } /** *Returns the names of all data groups *@access public *@return string[] */ public function get_GroupsName() { $groups_name=array(); for ($i=0;$i<$this->get_GroupsNum();$i++) array_push($groups_name,$this->Parser_Results[$i]->GroupName); return $groups_name; } /** *Returns the number of group members *@access public *@return integer */ public function get_GroupItemsNum() { return count($this->Parser_Results[0]->GroupItems); } /** *Returns the name of all group members *@access public *@return string */ public function get_GroupItemsName() { $groupitems_name=array(); for ($i=0;$i<$this->get_GroupItemsNum();$i++) array_push($groupitems_name,$this->Parser_Results[0]->GroupItems[$i]->ItemName); return $groupitems_name; } /** *Returns the values of the specified member from all groups *@access public *@return integer[] *@param string $item */ public function get_ItemFromGroups($item) { $Item=array(); for ($i=0;$i<$this->get_GroupsNum();$i++) { for ($j=0;$j<$this->get_GroupItemsNum();$j++) { if ($this->Parser_Results[$i]->GroupItems[$j]->ItemName==$item) array_push($Item,$this->Parser_Results[$i]->GroupItems[$j]->ItemValue); } } return $Item; } /** *Returns the number of data groups *@access public *@return integer */ public function get_GroupsNum() { return count($this->Parser_Results); } /** *Strategizes the DataParser with the specified DataStrategy Object *@access public *@return void *@param mixed $Strategy_Object *@param mixed $params Passes an arbitrary number of parameters to the Strategy object */ public function strategize(&$Strategy_Object,$params=NULL) { $this->Parser_Strategy=$Strategy_Object; $this->Parser_Strategy->initialize($params); } /** *Destructor.Calls the finalize method of the selected Strategy Object for clean-up */ function __destruct() { $this->Parser_Strategy->finalize(); } } ?>