d4957164ec5e74ab2f6c28e77c8988e911d71e31
[atutor.git] / mods / atutor_opencaps / opencaps / conversion_service / include / classes / core_XmlTagTraceManager.php
1 <?php\r
2 \r
3 \r
4 class XmlManager\r
5 {\r
6         private $xmlDataString; // the xml data as string\r
7         private $captionCollection; // the Caption Collection\r
8         //\r
9 \r
10         function __construct($theXmlString)\r
11         {\r
12                 $this->xmlDataString = $theXmlString;\r
13                 \r
14                 // create a caption Collection \r
15                 $myCaptionCollcton = new CaptionCollection();\r
16                 $this->captionCollection = $myCaptionCollcton;\r
17                 \r
18                 // start loopXmlData\r
19                 $this->loopXmlData();\r
20                 \r
21         } // end constructor  \r
22 \r
23         /**\r
24          * Parses an XML string into an myltidimentional array\r
25          *\r
26          * @param String $theXmlString The xml file as string\r
27          * @return Array $xmlInArray \r
28          */\r
29         public function loopXmlData()\r
30         {\r
31                 // create XML parser\r
32                 $p = xml_parser_create();\r
33                 \r
34                 //xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);\r
35 \r
36                 xml_parse_into_struct($p, $this->xmlDataString, $vals, $index);\r
37                 \r
38                 // free parser \r
39                 xml_parser_free($p);\r
40                 \r
41                 \r
42                 // create a Xmlparse Object tracing for <P> tags at level 4 (this the case of DFXP files) \r
43                 $myXmlParse = new XmlParse('P','4');\r
44                 \r
45                 \r
46                 // start looping xml array\r
47                 for ($i = 0; $i < count($vals); $i++) \r
48                 {\r
49                         $myXmlParse->setXmlData();\r
50                         \r
51                         \r
52                         // *************************************** GET CAPTION DATA ---- START\r
53                         \r
54                         // if P tag is complete \r
55                         if($ccBuild == 3) \r
56                         {\r
57                                 // get caption value\r
58                                 $ccText = $vals[$i]['value'];\r
59                                 \r
60                                 // get attributes array \r
61                                 $capAttrib = $vals[$i]['attributes'];\r
62                                 \r
63                                 // get time in and out of the caption\r
64                                 $ccTimeIn = $capAttrib['BEGIN'];\r
65                                 $ccTimeOut = $capAttrib['END'];\r
66                                 \r
67                                 $newCaptionDone = 1;\r
68 \r
69                                 $newCaption = new Caption($ccTimeIn,$ccTimeOut,$ccText,$noStyles);\r
70                                 //$new\r
71                                 //$countCC++;\r
72                         \r
73                         }  else if($ccBuild == 1) {\r
74                                 \r
75                                 \r
76                                         \r
77                         // if there are other tags inside P\r
78                         } else if (($ccBuild == 2) && isset($vals[$i]['value'])) {\r
79                                 \r
80                                 // add other parts of the caption text\r
81                                 $ccText .= $vals[$i]['value'];\r
82                         \r
83                         // if is the end of the caption\r
84                         } else if (($ccBuild == 4) && isset($vals[$i]['value'])) {\r
85                                 \r
86                                 // add other parts of the caption text if is set\r
87                                         $ccText .= $vals[$i]['value'];\r
88                         }\r
89                         \r
90                         \r
91                         // *************************************** GET CAPTION DATA ---- END\r
92                         \r
93                         // just print each tag info\r
94                         echo '<br/>Tag: '.$vals[$i]['tag'];\r
95                         echo '<br/>Type: '.$vals[$i]['type'];\r
96                         echo '<br/>Level: '.$vals[$i]['level'];\r
97 \r
98                         if(isset($vals[$i]['attributes']))\r
99                         {\r
100                                 foreach ($vals[$i]['attributes'] as $theAtt => $theVal)\r
101                                 {\r
102                                         //echo '<br/>Attributes: '.$vals[$i]['attributes'];\r
103                                         echo '<br/>------ '.$theAtt.': '.$theVal;\r
104                                 }\r
105                         }\r
106                         \r
107                         if(isset($vals[$i]['value']))\r
108                         {\r
109                                 echo '<br/>Value: '.$vals[$i]['value'];\r
110                         }\r
111                         \r
112                         echo '<hr>';\r
113                 } // end for \r
114                 \r
115                 \r
116                 \r
117                 \r
118                 \r
119                 \r
120                 \r
121                 \r
122                 \r
123                 \r
124                 \r
125                 \r
126                 \r
127                 \r
128                 \r
129                 \r
130                 \r
131                 /*\r
132                 echo "Index array\n";\r
133                 echo "Total in array Index: ".count($index)."\n";\r
134                 print_r($index);\r
135                 echo "\nVals array\n";\r
136                 echo "Total in array vals: ".count($vals)."\n";\r
137                 print_r($vals);\r
138                 */\r
139                 \r
140                 \r
141                 \r
142                 /*\r
143                 foreach($vals as $val)\r
144                 {\r
145                         $totInArr = count($val);\r
146                         echo '<br/>tot in Val = '.$totInArr;\r
147                         //echo '<br/>Val = '.$val;\r
148                         foreach ($val as $theVal)\r
149                         {\r
150                                 echo '<br/>the val = '.$theVal;\r
151                                 \r
152                         }  // end for 2\r
153                         \r
154                 } // end for 1\r
155                 */\r
156                 \r
157                 \r
158                 //return $vals;\r
159                 \r
160         } // end loopXmlData()\r
161         \r
162         /**\r
163          * Print class Data\r
164          *\r
165          */\r
166         public function toString()\r
167         {\r
168                 echo '<br/> xmlDataString: '.$this->xmlDataString;\r
169                 echo '<br/> tagToTrace: '.$this->tagToTrace;\r
170                 echo '<br/> tagToTraceLevel: '.$this->tagToTraceLevel;\r
171                 \r
172         }\r
173 } // end XmlManager class \r
174 ?>