ff58afffe2829dcbf19200b43f7e7e53ff0503d3
[atutor.git] / mods / phpdoc2 / include / classes / phpdoc2_images.class.php
1 <?php
2
3
4 class Phpdoc_images {
5         // Variables
6         var $imap       = array();      //Hash,  <key>:type, <value>: array
7         var $max_col = 0;               //Max column for the display, TODO: define in constance instead?
8
9         // Constructor
10         function Phpdoc_images() {
11                 /* 
12                  * $imap_<type> defines the definition of each of the images 
13                  * <key>        :       The definition of the image
14                  * <value>      :       File name of the image; images must be in the same folder
15                  */
16                  //class related
17                 $imap_class             = array(
18                                                         'Class'                                         => 'class.png', 
19                                                         'Private Class'                         => 'private_class.png', 
20                                                         'Abstract Class'                        => 'abstract_class.png', 
21                                                         'Abstract Private Class'        => 'abstract_private_class.png'
22                                                         );
23
24                 //method related
25                 $imap_method    = array(
26                                                         'Method'                                        => 'method.png', 
27                                                         'Private Method'                        => 'private_method.png', 
28                                                         'Abstract Method'                       => 'abstract_method.png', 
29                                                         'Constructor'                           => 'constructor_method.png', 
30                                                         'Destructor'                            => 'destructor_method.png', 
31                                                         'Function'                                      => 'function.png'
32                                                         );
33
34                 //folder related
35                 $imap_folder    = array(
36                                                         'Folder'                                        => 'folder.png', 
37                                                         'Class Folder'                          => 'class_folder.png', 
38                                                         'Function Folder'                       => 'function_folder.png', 
39                                                         'Tutorial Folder'                       => 'tutorial_folder.png', 
40                                                         'Package Folder'                        => 'package_folder.png'
41                                                         );
42
43                 //variables
44                 $imap_variable  = array(
45                                                         'Variables'                                     => 'variable.png', 
46                                                         'Private Variable'                      => 'private_variable.png', 
47                                                         'Global Variable'                       => 'global.png', 
48                                                         'Constant'                                      => 'constant.png'
49                                                         );
50
51                 //others 
52                 $imap_others    = array( 
53                                                         'File'                                          => 'file.png', 
54                                                         'Index'                                         => 'index.png', 
55                                                         'Tutorial'                                      => 'tutorial.png', 
56                                                         'Package'                                       => 'package.png'
57                                                         );
58
59                 //Instantiate variables
60                 $this->max_col  = 3;
61                 $this->imap             = array(
62                                                         'Class'                                         => $imap_class,
63                                                         'Method'                                        => $imap_method,
64                                                         'Folder'                                        => $imap_folder,
65                                                         'Variable'                                      => $imap_variable,
66                                                         'Others'                                        => $imap_others
67                                                         );
68         }
69
70
71         /**
72          * Generate images dynamically.
73          * @param       the path to the image, used by the <a> tag
74          */
75         function printImageTable($image_dir){
76                 $html = '';     //html code
77                 $counter = 1;   //row counter
78                 $html = '<table id="api_legend_outter"><tr>';
79
80                 //Loop through level
81                 foreach ($this->imap as $type=>$type_array){
82                         if ($counter > $this->max_col){
83                                 $html .= "</tr><tr>";
84                                 $counter = 1;           //reset counter once it overloads
85                         }
86                         $html .= "<td>";
87
88                         //Run a loop through each of the images inside the array
89                         $html .= '<table id="api_legend_inner">';
90                         $html .= '<tr><th colspan="2">'.$type.'</th></tr>';
91                         foreach($type_array as $image_name => $file_name){
92                                 $html .= '<tr><td>'.$image_name.'</td>';
93                                 $html .= '<td>'.$this->getImgTag($image_name, $image_dir.$file_name).'</td></tr>';
94                         }
95                         $html .= '</table>';
96                         
97                         $html .= "</td>";
98                         $counter++;
99                 }
100                 $html .= "</tr></table>";
101                 return $html;
102         }
103
104
105         /**
106          * Get image tag
107          * @param       String  the name of the image which will be shown in the title and alt
108          * @param       String  the path for the image
109          */
110         function getImgTag($image_name, $file_name, $width='16'){
111                 return '<img src="'.$file_name.'" title="'.$image_name.'" title="'.$image_name.'" width="'.$width.'" />';
112         }
113 }
114 ?>