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

Source for file TXTData_Strategy.php

Documentation is available at TXTData_Strategy.php

  1. <?php
  2.  
  3. /*
  4. **************************************************
  5. Class: TXTData_Strategy.php
  6. **************************************************
  7. Author: Tsiavos Chris <jaames@freemail.gr>
  8. Date: October 2004
  9. **************************************************/
  10.  
  11. /**
  12. *Includes the DataStrategy Interface
  13. */
  14. require_once("DataStrategy_Interface.php");
  15.  
  16. /**
  17. *Reads chart data from text files
  18. *This class should be used when you want to import chart data from text files. The indicated file should
  19. *have the following structure (per line) for parsing to be successfull: group=$group_name//$Item,$Value:$Item,$Value
  20. *@author Tsiavos Chris <jaames@freemail.gr>
  21. *@license http://opensource.org/licenses/gpl-license.php GNU Public License
  22. */
  23. class TXTData_Strategy implements DataStrategy_Interface {
  24. /**
  25. *Holds the file handler
  26. *@access private
  27. */
  28. private $File_Handler;
  29. /**
  30. *Initializes the strategy object
  31. *@access public
  32. *@params string[assoc] $params["filename"]
  33. *@throws DataStrategy_Exception
  34. */
  35. public function initialize($params=NULL)
  36. {
  37. $filename=$params["filename"];
  38. if (!file_exists($filename))
  39. throw new DataStrategy_Exception("TXTData_Strategy: File $filename not found");
  40. $this->File_Handler=@fopen($filename,"r");
  41. }
  42. /**
  43. *Performs the required action for parsing the data from the text file
  44. *@access public
  45. *@return Group[] Common communication structure between DataStrategy objects and DataParser
  46. *@param NULL $params
  47. */
  48. public function perform($params=NULL)
  49. {
  50. $line=NULL;
  51. $line_num=0;
  52. $Groups=array();
  53. while(!feof($this->File_Handler)) {
  54. $line=fgets($this->File_Handler,255);
  55. if (strlen(trim($line))==0) continue;
  56. $line_data=split("=",trim($line));
  57. $line_data_contents=split("//",$line_data[1]);
  58. $group_name=$line_data_contents[0];
  59. $Groups[$line_num]=new Group();
  60. $Groups[$line_num]->GroupName=$group_name;
  61. $Items=split(":",$line_data_contents[1]);
  62. for ($i=0;$i<count($Items);$i++) {
  63. $Item=split(",",$Items[$i]);
  64. $Groups[$line_num]->GroupItems[$i]=new GroupItem();
  65. $Groups[$line_num]->GroupItems[$i]->ItemName=$Item[0];
  66. $Groups[$line_num]->GroupItems[$i]->ItemValue=$Item[1];
  67. }
  68. $line_num++;
  69. }
  70. return $Groups;
  71. }
  72. /**
  73. *Finalizes the DataStrategy object.
  74. *@access public
  75. *@return void
  76. */
  77. public function finalize()
  78. {
  79. fclose($this->File_Handler);
  80. }
  81. }
  82.  
  83. ?>

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