changed git call from https to git readonly
[atutor.git] / mods / phpdoc / PHPDoc / renderer / html / PhpdocHTMLIndexRenderer.php
1 <?php
2 /**
3 * Renders Index lists.
4 */
5 class PhpdocHTMLIndexRenderer extends PhpdocHTMLRenderer {
6
7         /**
8         * Some container in the package list.
9         *
10         * @var  array
11         * @see  renderPackagelist()
12         */
13         var $packageFields = array("class", "module");
14
15         /**
16         * Packagelist from the PhpdocIndexAccessor
17         *
18         * @var  array
19         */
20         var $packages = array();
21
22         /**
23         * Array with classtree informations
24         *
25         * @var  array
26         */
27         var $classtree = array();
28
29         /**
30         * IntegratedTemplate Object used be renderClasstree()
31         *
32         * @var  object  IntegratedTemplate
33         * @see  renderClasstree()
34         */
35         var $treeTpl;
36
37         /**
38         * IntegratedTemplateObject used by renderModulegroup()
39         * 
40         * @var object   IntegratedTemplate
41         * @see  renderModulegroup()
42         */
43         var $moduleTpl;
44
45         /**
46         * Sets the xml and template root directory.
47         * 
48         * @param        string  XML file path
49         * @param        string  Template file path
50         * @param        string  Name of the application
51         * @param        string  Filename extension
52         * @see  setPath(), setTemplateRoot()
53         */
54         function PhpdocHTMLIndexRenderer($path, $templateRoot, $application, $extension = ".html") {
55
56                 $this->setPath($path);
57                 $this->setTemplateRoot($templateRoot);
58                 $this->application = $application;
59                 $this->file_extension = $extension;
60
61                 $this->accessor = new PhpdocIndexAccessor;
62                 $this->tpl = new IntegratedTemplate($this->templateRoot);
63                 $this->fileHandler = new PhpdocFileHandler;
64
65         } // end constructor
66
67         /**
68         * Builds all index files phpdoc needs assuming that the xml files have default names
69         * 
70         * @access       public
71         * @see  renderElementlist(), renderPackagelist(), renderFramelementlist(), renderFramePackageSummary()
72         */
73         function generate() {
74
75                 $this->renderElementlist("elementlist.xml");
76                 $this->renderFrameElementlist("elementlist.xml");
77                 $this->renderPackagelist("packagelist.xml");
78                 $this->renderFramePackageSummary("packagelist.xml");
79                 $this->renderFrameElementlist("packagelist.xml");
80
81         } // end function generate
82
83         /**
84         * Saves the generated classtree summary to disk.
85         * 
86         * @see          renderClasstree()
87         * @access       public
88         */
89         function finishClasstree() {
90
91                 if (!is_object($this->treeTpl)) 
92                         return;
93
94                 $this->treeTpl->setVariable("APPNAME", $this->application);
95                 $this->fileHandler->createFile($this->path."phpdoc_classtree".$this->file_extension, $this->treeTpl->get() );
96                 $this->treeTpl = "";
97
98         }       // end func finishClasstree
99
100         /**
101         * Adds a classtree to the classtree summary template.
102         * 
103         * @param        string  XML Classtree file
104         * @see          finishClasstree()
105         * @access       public
106         */
107         function addClasstree($xmlfile) {
108
109                 $this->accessor->loadXMLFile($this->path.$xmlfile);
110
111                 if (!is_object($this->treeTpl)) {
112                         $this->treeTpl = new IntegratedTemplate($this->templateRoot);
113                         $this->treeTpl->loadTemplatefile("classtree.html");
114                 }
115
116                 $this->classtree = $this->accessor->getClasstree();
117                 $this->treeTpl->setCurrentBlock("classtree");
118                 $this->treeTpl->setVariable("BASECLASS", $this->classtree["baseclass"]);
119                 $this->treeTpl->setVariable("TREE", "<ul>".$this->buildClasstreeHTML($this->classtree["baseclass"])."</ul>");
120                 $this->treeTpl->parseCurrentBlock();
121
122                 return true;
123         } // end func addClasstree
124
125         function finishModulegroup() {
126
127                 if (!is_object($this->moduleTpl)) 
128                         return;
129
130                 $this->moduleTpl->setVariable("APPNAME", $this->application);
131                 $this->fileHandler->createFile($this->path."phpdoc_modulegroup".$this->file_extension, $this->moduleTpl->get() );
132                 $this->moduleTpl = "";
133         } // end func finishModulegroups
134
135         /**
136         * Renders a modulegroup xml file.
137         *
138         * @param        string  XML File
139         */      
140         function addModulegroup($xmlfile) {
141
142                 $this->accessor->loadXMLFile($this->path.$xmlfile);
143
144                 if (!is_object($this->moduleTpl)) {
145                         $this->moduleTpl        = new IntegratedTemplate($this->templateRoot);
146                         $this->moduleTpl->loadTemplateFile("modulegroup.html");
147                 }
148
149                 $modulegroup = $this->accessor->getModulegroup();
150                 $modules = "<ul>";
151
152                 reset($modulegroup["modules"]);
153                 while (list($k, $module) = each($modulegroup["modules"])) 
154                         $modules .= sprintf('<li><a href="%s">%s</a>', $this->nameToUrl($module) . $this->file_extension, $module);
155
156                 $modules .= "</ul>";
157
158                 $this->moduleTpl->setCurrentBlock("modulegroup");
159                 $this->moduleTpl->setVariable("MODULEGROUP", $modulegroup["group"]);
160                 $this->moduleTpl->setVariable("MODULES", $modules);
161                 $this->moduleTpl->parseCurrentBlock();          
162
163         } // end func addModulegroup
164
165         /**
166         * Renders the element index list.
167         *
168         * @param        string  XML file
169         * @access       public
170         * @see  generate()
171         */ 
172         function renderElementlist($xmlfile) {
173
174                 $this->accessor->loadXMLFile($this->path.$xmlfile);
175                 $this->tpl->loadTemplatefile("elementlist.html");
176
177                 $chapters = $this->accessor->getChapternames();
178                 if (0 != count($chapters)) {
179
180                         $this->tpl->setCurrentBlock("chaptersummary_loop");
181
182                         reset($chapters);
183                         while (list($k, $chapter) = each($chapters)) {
184                                 $this->tpl->setVariable("CHAPTER", $chapter);
185                                 $this->tpl->parseCurrentBlock();
186                         }
187
188                         $chapters = $this->accessor->getChapters();
189                         reset($chapters);
190                         while (list($name, $elements) = each($chapters)) {
191
192                                 if (!isset($elements["element"][0])) 
193                                         $elements["element"] = array($elements["element"]);
194
195                                 $this->tpl->setCurrentBlock("chapter_loop");
196
197                                 reset($elements["element"]);
198                                 while (list($k, $element) = each($elements["element"])) {
199
200                                         switch($element["type"]) {
201                                                 case "package":
202                                                         $desc = "Package";
203                                                         break;
204
205                                                 case "class":
206                                                         $desc = sprintf('Class <a href="%s">%s</a>.', 
207                                                                                                                                 $this->nameToUrl($element["name"]) . $this->file_extension,
208                                                                                                                                 $element["name"]
209                                                                                                                         );
210                                                         break;
211
212                                                 case "module":
213                                                         $desc = sprintf('Module <a href="%s">%s</a>.',
214                                                                                                                                 $this->nameToUrl($element["name"]) . $this->file_extension,
215                                                                                                                                 $element["name"]
216                                                                                                                         );
217                                                         break;
218
219                                                 case "functions":
220                                                         $desc = sprintf('Function in %s <a href="%s">%s</a>',
221                                                                                                                                 $element["sourcetype"],
222                                                                                                                                 $this->nameToUrl($element["source"]) . $this->file_extension,
223                                                                                                                                 $element["source"]
224                                                                                                                         );
225                                                         break;
226
227                                                 case "variables":
228                                                         $desc = sprintf('Variable in Class <a href="%s">%s</a>',
229                                                                                                                                 $this->nameToUrl($element["source"]) . $this->file_extension,
230                                                                                                                                 $element["source"]
231                                                                                                                         );
232                                                         break;
233
234                                                 case "uses":
235                                                         $desc = sprintf('Included file in %s <a href="%s">%s</a>',
236                                                                                                                                 $element["sourcetype"],
237                                                                                                                                 $this->nameToUrl($element["source"]) . $this->file_extension,
238                                                                                                                                 $element["source"]
239                                                                                                                         );
240                                                         break;
241
242                                                 case "consts":
243                                                         $desc = sprintf('Constant defined in %s <a href="%s">%s</a>',
244                                                                                                                                 $element["sourcetype"],
245                                                                                                                                 $this->nameToUrl($element["source"]) . $this->file_extension,
246                                                                                                                                 $element["source"]
247                                                                                                                         );
248                                                         break;
249
250                                         }
251
252                                         $this->tpl->setVariable("ELEMENTNAME", $element["name"]);
253                                         $this->tpl->setVariable("ELEMENT", $desc);
254                                         $this->tpl->setVariable("SHORTDESCRIPTION", $element["value"]);
255                                         $this->tpl->parseCurrentBlock();
256
257                                 }
258
259                                 $this->tpl->setCurrentBlock("chapter");
260                                 $this->tpl->setVariable("CHAPTER", $name);
261                                 $this->tpl->parseCurrentBlock();
262
263                         }
264
265                 }
266
267                 $this->tpl->setVariable("APPNAME", $this->application);
268                 $this->fileHandler->createFile($this->path . "phpdoc_elementlist" . $this->file_extension, $this->tpl->get() );
269                 $this->tpl->free();
270
271         } // end func renderElementlist
272
273         /**
274         * Renders a complete packagelist.
275         *
276         * @param        string  XML file
277         * @access       public
278         * @see  renderFrameElementlist(), renderFramePackagesummary()
279         */
280         function renderPackagelist($xmlfile) {
281
282                 $this->loadPackagelist($xmlfile);
283                 $this->tpl->loadTemplatefile("packagelist.html");
284
285                 reset($this->packages);
286                 while (list($packagename, $package) = each($this->packages)) {
287
288                         reset($this->packageFields);
289                         while (list($k, $field) = each($this->packageFields)) {
290                                 if (!isset($package[$field]))
291                                         continue;
292
293                                 $this->tpl->setCurrentBlock("package_".$field."_loop"); 
294
295                                 reset($package[$field]);
296                                 while (list($k, $element) = each($package[$field])) {
297
298                                         $this->tpl->setVariable("ELEMENT", sprintf('<a href="%s">%s</a>', 
299                                                                                                                                                                                                                                 $this->nameToUrl($element) . $this->file_extension, 
300                                                                                                                                                                                                                                 $element
301                                                                                                                                                                                                                         )
302                                                                                                                                                                                         );
303
304                                         $this->tpl->parseCurrentBlock();
305                                 }
306
307                                 $this->tpl->setCurrentBlock("package_" . $field);
308                                 $this->tpl->setVariable("EMPTY", "");
309                                 $this->tpl->parseCurrentBlock();
310
311                         }
312
313                         $this->tpl->setCurrentBlock("package");
314                         $this->tpl->setVariable("PACKAGE_NAME", $packagename);
315                         $this->tpl->parseCurrentBlock();
316
317                 }
318
319                 $this->tpl->setVariable("APPNAME", $this->application);
320                 $this->fileHandler->createFile($this->path . "phpdoc_packagelist" . $this->file_extension, $this->tpl->get() );
321                 $this->tpl->free();
322
323         } // end func renderPackagelist
324
325         /**
326         * Renders files for the lower left frame with the elements of a certain file.
327         *
328         * @param        string  This function needs the packagelist.xml to work!
329         * @access       public
330         * @see  renderFramePackagesummary(), renderPackagelist()
331         */
332         function renderFrameElementlist($xmlfile) {
333
334                 $this->loadPackagelist($xmlfile);
335
336                 reset($this->packages);
337                 while (list($packagename, $package) = each($this->packages)) {
338
339                         $this->tpl->loadTemplatefile("frame_packageelementlist.html");
340                         
341                         reset($this->packageFields);
342                         while (list($k, $field) = each($this->packageFields)) {
343
344                                 if (!isset($package[$field]))
345                                         continue;
346
347                                 $this->tpl->setCurrentBlock("package_".$field."_loop"); 
348
349                                 reset($package[$field]);
350                                 while (list($k, $element) = each($package[$field])) {
351
352                                         $this->tpl->setVariable("ELEMENT", sprintf('<a href="%s" target="main">%s</a>', 
353                                                                                                                                                                                                                                 $this->nameToUrl($element) . $this->file_extension, 
354                                                                                                                                                                                                                                 $element
355                                                                                                                                                                                                                         ) 
356                                                                                                                                                                                                 );
357                                         $this->tpl->parseCurrentBlock();
358                                 }
359
360                                 $this->tpl->setCurrentBlock("package_" . $field);
361                                 $this->tpl->setVariable("EMPTY", "");
362                                 $this->tpl->parseCurrentBlock();
363
364                         }
365
366                         $this->tpl->setCurrentBlock("package");
367                         $this->tpl->setVariable("PACKAGE_NAME", $packagename);
368                         $this->tpl->parseCurrentBlock();
369
370                         $this->tpl->setVariable("APPNAME", $this->application);
371                         $packagename = $this->nameToUrl($packagename);
372                         $this->fileHandler->createFile($this->path . "packageelementlist_" . $packagename . $this->file_extension, $this->tpl->get() );                                 
373
374                 }
375
376                 $this->tpl->free();
377
378         } // end func renderFrameElementlist
379
380         /**
381         * Renders a Packagesummary for the frameset.
382         * 
383         * @param        string  XML file.
384         * @access       public
385         * @see  renderPackagelist(), renderFrameElementlist()
386         */
387         function renderFramePackagesummary($xmlfile) {
388
389                 $this->loadPackagelist($xmlfile);
390
391                 $this->tpl->loadTemplatefile("frame_packagelist.html");
392                 $this->tpl->setCurrentBlock("package");
393
394                 reset($this->packages);
395                 while (list($packagename, $v) = each($this->packages)) {
396
397                         $this->tpl->setVariable("PACKAGE", sprintf('<a href="packageelementlist_%s" target="packageelements">%s</a>',
398                                                                                                                                                                                                                 $this->nameToUrl($packagename) . $this->file_extension,
399                                                                                                                                                                                                                 $packagename )
400                                                                                                                         );
401                         $this->tpl->parseCurrentBlock();                                                                                                                        
402                         
403                 }
404
405                 $this->tpl->setVariable("APPNAME", $this->application);
406                 $this->fileHandler->createFile($this->path . "frame_packagelist" . $this->file_extension, $this->tpl->get() );
407                 $this->tpl->free();
408
409         } // end func renderFramePackagesummary
410
411         /**
412         * Imports the packagelist from the PhpdocIndexAccessor if not done previously.
413         * 
414         * @param        string  XMl file.
415         * @see  $packages
416         */      
417         function loadPackagelist($xmlfile) {
418
419                 if (0 == count($this->packages)) {
420                         $this->accessor->loadXMLFile($this->path . $xmlfile);
421                         $this->packages = $this->accessor->getPackagelist();            
422                 }
423
424         } // end func loadPackagelist
425         
426         /**
427         * Recursivly builds an HTML class tree using <ul><li></ul>.
428         *
429         * @param        string  Name of the class the recursive loop starts with
430         * @see  renderClasstree()
431         */
432         function buildClasstreeHTML($class) {
433
434                 $html = "";
435                 
436                 if (0 == count($this->classtree["classes"][$class])) {
437
438                         $html .= sprintf('<li><a href="%s">%s</a>', $this->nameToUrl($class) . $this->file_extension, $class);
439
440                 } else {
441
442                         $html .= sprintf('<li><a href="%s">%s</a>', $this->nameToUrl($class) . $this->file_extension, $class);
443                         $html .= "<ul>";
444
445                         reset($this->classtree["classes"][$class]);
446                         while (list($k, $subclass) = each($this->classtree["classes"][$class])) 
447                                 $html .= $this->buildClasstreeHTML($subclass);                                  
448
449                         $html .= "</ul>";
450
451                 }
452
453                 return $html;
454         } // end func buildClasstreeHTML
455
456 } // end class PhpdocHTMLIndexRenderer
457 ?>