- <?php
-
- /*
- **************************************************
- Class: XMLData_Strategy.php
- **************************************************
- Author: Tsiavos Chris <jaames@freemail.gr>
- Date: October 2004
- **************************************************/
-
- /**
- *Includes the DataStrategy Interface
- */
- require_once("DataStrategy_Interface.php");
-
- /**
- *Strategy for importing chart data from XML files
- *@author Tsiavos Chris <jaames@freemail.gr>
- *@uses SimpleXML Extension
- *@license http://opensource.org/licenses/gpl-license.php GNU Public License
- */
-
- class XMLData_Strategy implements DataStrategy_Interface {
-
- private $XMLHandler;
-
- public function initialize($params=NULL) {
-
- $filename=$params["filename"];
-
- if (!file_exists($filename))
- throw new DataStrategy_Exception("DataStrategy: Filename $filename not found");
-
- $this->XMLHandler=simplexml_load_file($filename);
- }
-
- public function perform($params=NULL) {
- $Groups=array();
-
- foreach ($this->XMLHandler->group as $group) {
-
- array_push($Groups,new Group());
-
- $CurrentGroup=count($Groups)-1;
-
- $Groups[$CurrentGroup]->GroupName=(string)$group['name'];
-
- foreach ($group->item as $item) {
-
- array_push($Groups[$CurrentGroup]->GroupItems,new GroupItem());
-
- $CurrentGroupItem=count($Groups[$CurrentGroup]->GroupItems)-1;
-
- $Groups[$CurrentGroup]->GroupItems[$CurrentGroupItem]->ItemName=(string)$item->name;
- $Groups[$CurrentGroup]->GroupItems[$CurrentGroupItem]->ItemValue=(float)$item->value;
- }
-
- }
-
- return $Groups;
- }
-
- public function finalize() {
- return;
- }
- }