[ class tree: phpchartPlus ] [ index: phpchartPlus ] [ all elements ]

Source for file DataParser.php

Documentation is available at DataParser.php

  1. <?php
  2.  
  3. /*
  4. ********************************************************************
  5. DataParser.php - phpchartPlus DataParser class
  6. ********************************************************************
  7. Author: Tsiavos Chris
  8. Email: jaames@freemail.gr
  9. Date: October 2004
  10. ********************************************************************
  11. */
  12.  
  13. /**
  14. *Includes the Group class, the common communication structure between
  15. *DataStrategy objects and DataParser
  16. */
  17. require_once("DataStrategy_Interface.php");
  18.  
  19. class DataParser_Exception extends Exception {
  20. function DataParser_Exception($data) {
  21. Exception::__construct($data);
  22. }
  23. }
  24.  
  25. /**
  26. *Class for importing chart data to the application
  27. *This class can be strategized with the appropriate Strategy Object to support the collection and
  28. *parsing of data in a way independent of the data source implementation details. This
  29. *feature allows the run-time selection of the data source based on some used-defined
  30. *parameters.
  31. *@final
  32. *@author Tsiavos Chris <jaames@freemail.gr>
  33. *@license http://opensource.org/licenses/gpl-license.php GNU Public License
  34. */
  35. final class DataParser {
  36. /**
  37. *reference to the selected DataStrategy instance
  38. *@access private
  39. *@var mixed
  40. */
  41. private $Parser_Strategy;
  42. /**
  43. *array of Group[] objects containing the parsed chart data returned by the selected Strategy Object
  44. *@access private
  45. *@var Group[]
  46. */
  47. private $Parser_Results=array();
  48. /**
  49. *Constructor
  50. */
  51. function __construct() { }
  52. /**
  53. *Instructs the selected Strategy Object to collect and return the chart data
  54. *to DataParser for analysis
  55. *@access public
  56. *@return void
  57. *@throws DataParser_Exception
  58. *@param mixed $params Specifies an arbitrary number of parameters passed to the
  59. *sselected Strategy Object during data parsing
  60. */
  61. public function parse($params=NULL) {
  62. if (!is_object($this->Parser_Strategy))
  63. throw new DataParser_Exception("DataParser: No strategy found");
  64. $this->Parser_Results=$this->Parser_Strategy->perform($params);
  65. }
  66. /**
  67. *Returns the names of all data groups
  68. *@access public
  69. *@return string[]
  70. */
  71. public function get_GroupsName() {
  72. $groups_name=array();
  73. for ($i=0;$i<$this->get_GroupsNum();$i++)
  74. array_push($groups_name,$this->Parser_Results[$i]->GroupName);
  75. return $groups_name;
  76. }
  77. /**
  78. *Returns the number of group members
  79. *@access public
  80. *@return integer
  81. */
  82. public function get_GroupItemsNum() {
  83. return count($this->Parser_Results[0]->GroupItems);
  84. }
  85. /**
  86. *Returns the name of all group members
  87. *@access public
  88. *@return string
  89. */
  90. public function get_GroupItemsName() {
  91. $groupitems_name=array();
  92. for ($i=0;$i<$this->get_GroupItemsNum();$i++)
  93. array_push($groupitems_name,$this->Parser_Results[0]->GroupItems[$i]->ItemName);
  94. return $groupitems_name;
  95. }
  96. /**
  97. *Returns the values of the specified member from all groups
  98. *@access public
  99. *@return integer[]
  100. *@param string $item
  101. */
  102. public function get_ItemFromGroups($item) {
  103. $Item=array();
  104. for ($i=0;$i<$this->get_GroupsNum();$i++) {
  105. for ($j=0;$j<$this->get_GroupItemsNum();$j++) {
  106. if ($this->Parser_Results[$i]->GroupItems[$j]->ItemName==$item)
  107. array_push($Item,$this->Parser_Results[$i]->GroupItems[$j]->ItemValue);
  108. }
  109. }
  110. return $Item;
  111. }
  112. /**
  113. *Returns the number of data groups
  114. *@access public
  115. *@return integer
  116. */
  117. public function get_GroupsNum() {
  118. return count($this->Parser_Results);
  119. }
  120. /**
  121. *Strategizes the DataParser with the specified DataStrategy Object
  122. *@access public
  123. *@return void
  124. *@param mixed $Strategy_Object
  125. *@param mixed $params Passes an arbitrary number of parameters to the Strategy object
  126. */
  127. public function strategize(&$Strategy_Object,$params=NULL) {
  128. $this->Parser_Strategy=$Strategy_Object;
  129. $this->Parser_Strategy->initialize($params);
  130. }
  131. /**
  132. *Destructor.Calls the finalize method of the selected Strategy Object for clean-up
  133. */
  134. function __destruct() {
  135. $this->Parser_Strategy->finalize();
  136. }
  137. }
  138.  
  139. ?>

Documentation generated on Sun, 3 Oct 2004 14:59:12 +0300 by phpDocumentor 1.3.0RC3