remove old readme
[atutor.git] / docs / mods / _core / modules / classes / ModuleListParser.class.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /*                                                                      */
9 /* This program is free software. You can redistribute it and/or        */
10 /* modify it under the terms of the GNU General Public License          */
11 /* as published by the Free Software Foundation.                        */
12 /************************************************************************/
13 // $Id$
14
15 /**
16 * ModuleListParser
17 * Class for parsing XML module list info
18 * @access       public
19 * @author       Cindy Qi Li
20 * @package Admin Module
21 */
22 class ModuleListParser {
23
24         // all private
25         var $parser; // the XML handler
26         var $module_rows = array(); // the module data
27         var $character_data; // tmp variable for storing the data
28         var $element_path; // array of element paths (basically a stack)
29         var $row_num;
30         var $history_num;
31
32         function ModuleListParser() {
33                 $this->parser = xml_parser_create(''); 
34
35                 xml_set_object($this->parser, $this);
36                 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
37                 xml_set_element_handler($this->parser, 'startElement', 'endElement');
38                 xml_set_character_data_handler($this->parser, 'characterData');
39         }
40
41         // public
42         function parse($xml_data) {
43                 $this->element_path   = array();
44                 $this->module_rows  = array();
45                 $this->character_data = '';
46                 $this->row_num        = 0;
47                 $this->history_num    = 0;
48                 xml_parse($this->parser, $xml_data, TRUE);
49         }
50
51         // private
52         function startElement($parser, $name, $attributes) 
53         {
54                 array_push($this->element_path, $name);
55    }
56
57         // private
58         /* called when an element ends */
59         /* removed the current element from the $path */
60         function endElement($parser, $name) {
61                 if ($this->element_path == array('module_list', 'module', 'name')) 
62                 {
63                         $this->module_rows[$this->row_num]['name'] = trim($this->character_data);
64                 } 
65                 else if ($this->element_path === array('module_list', 'module', 'atutor_version')) 
66                 {
67                         $this->module_rows[$this->row_num]['atutor_version'] = trim($this->character_data);
68                 } 
69                 else if ($this->element_path === array('module_list', 'module', 'description')) 
70                 {
71                         $this->module_rows[$this->row_num]['description'] = trim($this->character_data);
72                 } 
73                 else if ($this->element_path === array('module_list', 'module', 'history')) 
74                 {
75                         $this->history_num = 0;
76                 } 
77                 else if ($this->element_path === array('module_list', 'module', 'history', 'release')) 
78                 {
79                         $this->history_num++;
80                 } 
81                 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'version')) 
82                 {
83                         $this->module_rows[$this->row_num]['history'][$this->history_num]['version'] = trim($this->character_data);
84                 } 
85                 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'filename')) 
86                 {
87                         $this->module_rows[$this->row_num]['history'][$this->history_num]['filename'] = trim($this->character_data);
88                 } 
89                 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'location')) 
90                 {
91                         $this->module_rows[$this->row_num]['history'][$this->history_num]['location'] = trim($this->character_data);
92                 } 
93                 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'install_folder')) 
94                 {
95                         $this->module_rows[$this->row_num]['history'][$this->history_num]['install_folder'] = trim($this->character_data);
96                 } 
97                 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'date')) 
98                 {
99                         $this->module_rows[$this->row_num]['history'][$this->history_num]['date'] = trim($this->character_data);
100                 } 
101                 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'state')) 
102                 {
103                         $this->module_rows[$this->row_num]['history'][$this->history_num]['state'] = trim($this->character_data);
104                 } 
105                 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'maintainer')) 
106                 {
107                         $this->module_rows[$this->row_num]['history'][$this->history_num]['maintainer'] = trim($this->character_data);
108                 } 
109                 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'notes')) 
110                 {
111                         $this->module_rows[$this->row_num]['history'][$this->history_num]['notes'] = trim($this->character_data);
112                 } 
113                 else if ($this->element_path === array('module_list', 'module')) 
114                 {
115                         $this->row_num++;
116                 }
117
118                 array_pop($this->element_path);
119                 $this->character_data = '';
120         }
121
122         // private
123         function characterData($parser, $data){
124                 $this->character_data .= $data;
125         }
126
127         // public
128         function getNumOfModules() 
129         {
130                 return count($this->module_rows);
131         }
132
133         // public
134         function getParsedArray() 
135         {
136                 return $this->module_rows;
137         }
138 }
139
140 ?>