cdeAllVariables.php source code
Contents of file
helpers/contentsGenerators/default/cdeAllVariables.php
1
<?php
2 // This file is part of phpSimpleDoc - released under the terms of GNU General Public License version 3 or later.
3 // Full copyright notice applying to this file can be found in file copyright.txt, distributed with this file.
4 /******************************************************************************
5 Variable lists : generates the contents of pages <b>1.lists/variables*.html'</b>
6
7 @license GPL
8 @author <a href="http://www.tig12.net">Thierry Graff</a>
9 @history 2009.02.02 16:43:10 : Creation
10 ********************************************************************************/
11
12 class cdeAllVariables extends ContentsGenerator{
13
14 /**
15 Alphabetical array of variables
16 Array containing the sorted indices of $this->docu->data['variables']
17 Ex : if $this->docu->data['variables'][0] contains 'insert'
18 [1] contains 'abort'
19 [2] contains 'delete'
20 $sortedVariables will be array(1, 2, 0)
21 */
22 protected $sortedVariables;
23
24 /**
25 Array containing first and last variable names, for each displayed page
26 Each entry is an associative array with 2 elements : 'first' and 'last'
27 */
28 protected $firstLast = '';
29
30 /** Part of 'page index' (links to other variable pages) common to all pages */
31 protected $pageIndex2 = '';
32
33
34 // *************************** generateContents ***************************
35 /**
36 Generates pages containing non-object variables lists
37 */
38 public function generateContents(){
39 $this->sortVariables();
40 //
41 $n = count($this->docu->data['variables']);
42 $nbPerPage = $this->docu->userConfig['methodListsPage']['maxNbPerPage']; // nb max of method per page
43 $nbPages = ceil($n / $nbPerPage);
44 //
45 $this->computeFirstLast($n, $nbPerPage, $nbPages);
46 //
47 // Main loop, on pages
48 //
49 for($i=0; $i < $nbPages; $i++){
50 $pageIndex = $this->computeIndex($i, $n, $nbPerPage, $nbPages);
51 $res = '';
52 $res .= "<div id='contents'>\n";
53 $res .= "<h1>" . $this->docu->userConfig['essential']['title'] . " global variables</h1>";
54 if($nbPages > 1){
55 $res .= "<div style='margin-bottom:10px;'>From <b>\$" . $this->firstLast[$i]['first'] . "</b> to <b>\$" . $this->firstLast[$i]['last'] . "</b></div>\n";
56 }
57 $res .= "<div id='variableListPage' class='multiplePageList'>\n";
58 // page index
59 $res .= $pageIndex;
60 //
61 $res .= "<table class='tableList'>\n";
62 $res .= "<tr>
63 <th>File</th>
64 <th>Variable</th>
65 <th>Comment</th>
66 </tr>\n";
67 //
68 // loop on the variables of current page
69 //
70 for($j=0; $j < $nbPerPage && $j < $n; $j++){
71 $idx = $i * $nbPerPage + $j;
72 if($idx >= $n){
73 // case of the last page, nb of variable < $nbPerPage
74 break;
75 }
76 $variable =& $this->docu->data['variables'][$this->sortedVariables[$idx]];
77 // echo "<pre>"; print_r($variable); echo "</pre>"; exit;
78 $variableName = (
79 $variable['commentObject']->tags_deprecated
80 ? "<span class='deprecated'>" . $variable['name'] . "</span>"
81 : $variable['name']
82 );
83 $fileName = $this->docu->data['files'][$variable['fileIndex']]['name'];
84 // here, obliged to give a unexisting filename to linkToClass --------------- @todo Refactor
85 $href = '../' . $this->docu->data['files'][$variable['fileIndex']]['relativePath'] . '.file.html';
86 $cssClass =$j%2;
87 $res .= "<tr>\n"
88 . "<td class='row$cssClass'><a href='$href'>$fileName</a></td>"
89 . "<td class='row$cssClass'><a href='$href#det_fields_{$variable['name']}'>\$$variableName</a></td>"
90 . "<td class='row$cssClass'>" . $variable['commentObject']->firstSentence . "</td>"
91 . "</tr>\n";
92 }// end for $j
93
94 $res .= "</table>\n";
95 // page index
96 $res .= $pageIndex;
97 //
98 $res .= "</div><!-- end id='variableListsPage' -->\n";
99 $res .= "</div><!-- end id='contents' -->\n";
100 //
101 $pgOptions['title'] = $this->docu->userConfig['essential']['title'] . " variables"
102 . ($nbPages > 1 ? ' : $' . $this->firstLast[$i]['first'] . ' to $' . $this->firstLast[$i]['last'] : '');
103 $pgOptions['prefix'] = '../';
104 $pgOptions['description'] = $pgOptions['title'];
105 $pgOptions['keywords'] = "{$this->docu->userConfig['essential']['title']}, variables, list, non-object";
106 $pgOptions['filename'] = $this->docu->userConfig['essential']['outputDir'] . "/1.lists/variables$i.html";
107 //
108 $this->docu->pg->generatePage($res, $pgOptions); // here page generation
109 }// end for $i
110 }// end generateContents
111
112
113 // ================================================================
114 // Private variables
115 // ================================================================
116
117 //********************* sortVariables ******************************
118 /**
119 Computes {@link $sortedVariables}
120 */
121 protected function sortVariables(){
122 $res = array();
123 for($i=0; $i < count($this->docu->data['variables']); $i++){
124 $res[] = $this->docu->data['variables'][$i]['name'];
125 }
126 $res = array_map('strtolower', $res);
127 asort($res);
128 $this->sortedVariables = array_keys($res);
129 }// end sortVariables
130
131
132 // *************************** computeIndex ***************************
133 /**
134 Computes {@link $first_last}
135 @param $n Nb of variables in the documented API
136 @param $nbPerPage Number of variables listed in a page
137 @param $nbPages Nb of pages containing variables lists
138 */
139 protected function computeFirstLast($n, $nbPerPage, $nbPages){
140 // If only one page, no index, so useless
141 if($nbPages == 1) return;
142 //
143 $this->firstLast = array();
144 for($i=0; $i < $nbPages; $i++){
145 // first and last variable listed in current page
146 $first = $this->docu->data['variables'][$this->sortedVariables[$i * $nbPerPage]]['name'];
147 $idx = ($i+1) * $nbPerPage - 1;
148 if($idx >= $n){
149 $idx = $n - 1; // case of last page
150 }
151 $last = $this->docu->data['variables'][$this->sortedVariables[$idx]]['name'];
152 $this->firstLast[] = array('first' => $first, 'last' => $last);
153 }
154 }// end computeFirstLast
155
156
157 // *************************** computeIndex ***************************
158 /**
159 Returns the HTML code of variable index (links to other pages containing variables)
160 Note : this index is variable only because of prev / next links
161 @param $n Nb of class variables in the documented API
162 @param $nbPerPage Number of variable listed in a page
163 @param $nbPages Nb of pages containing variable lists
164 @pre {@link $firstLast} must have been computed
165 */
166 protected function computeIndex($i, $n, $nbPerPage, $nbPages){
167 // If only one page, no index, so useless
168 if($nbPages == 1) return;
169 //
170 $res = "<div class='alphabeticalIndex'>";
171 $linkToPrev = ($i > 0 ? $i-1 : $i);
172 $linkToNext = ($i < $nbPages - 1 ? $i+1 : $i);
173 $res .= "<table width='100%'><tr>";
174 // links to prev / first variable page
175 $res .= "<td>";
176 $res .= "<a href='variables0.html' title='First' style=padding-right:10px;><<</a>"; // first
177 $res .= "<a href='variables$linkToPrev.html' title='Previous' style=padding-right:10px;><</a>"; // prev
178 $res .= "</td>";
179 // central part of the index
180 $res .= "<td width='100%'>";
181 $res .= $this->computeIndex2($n, $nbPerPage, $nbPages);
182 $res .= "</td>";
183 // links to next / last variable page
184 $res .= "<td>";
185 $res .= "<a href='variables$linkToNext.html' title = 'Next' style=padding-left:10px;>></a>"; // next
186 $lastIndex = $nbPages - 1;
187 $res .= "<a href='variables$lastIndex.html' title = 'Last' style=padding-left:10px;>>></a>"; // last
188 $res .= "</td>";
189 //
190 $res .= "</tr></table>";
191 $res .= "</div><!-- end class='alphabeticalIndex' -->";
192 return $res;
193 }// end computeIndex
194
195
196 // *************************** computeIndex2 ***************************
197 /**
198 Auxiliary variable of {@link computeIndex()}
199 Computes the fixed part of page index (common to all variable pages).
200 */
201 protected function computeIndex2($n, $nbPerPage, $nbPages){
202 if($this->pageIndex2 != '') return $this->pageIndex2; // cache, compute only once
203 // index-max-nb-per-line
204 // if there are 81 pages of variables lists, and index-max-nb-per-line = 25,
205 // we need 4 lines ; for a more regular distribution, we take 81 / 4 as index-max-nb-per-line.
206 $original = $this->docu->userConfig['methodListsPage']['maxNbPerPage'];
207 $nbLines = ceil($nbPages / $original);
208 $nbPerLine = ceil($nbPages / $nbLines);
209 $this->pageIndex2 = '';
210 for($i=0; $i < $nbPages; $i++){
211 if($i%$nbPerLine == 0 && $i != 0){
212 $this->pageIndex2 .= '<br/>';
213 }
214 else if($i != $nbPages){
215 $this->pageIndex2 .= ' | ';
216 }
217 $label = substr($this->firstLast[$i]['first'], 0, 2);
218 $title = '$' . $this->firstLast[$i]['first'] . ' - ' . $this->firstLast[$i]['last'];
219 $this->pageIndex2 .= "<a href='variables$i.html' title='$title'>$label</a>";
220 }
221 return $this->pageIndex2;
222 }// end computeIndex2
223
224
225 }//end class
226
227 ?>
228