Merge lp:~gregfr/phpdevshell/TablesAndFilters-v1.0.0-trunk into lp:~titan-phpdevshell/phpdevshell/main
- TablesAndFilters-v1.0.0-trunk
- Merge into main
Proposed by
ignatia
Status: | Needs review |
---|---|
Proposed branch: | lp:~gregfr/phpdevshell/TablesAndFilters-v1.0.0-trunk |
Merge into: | lp:~titan-phpdevshell/phpdevshell/main |
Diff against target: |
1201 lines (+1134/-0) 11 files modified
TablesAndFilters/config/plugin.config.xml (+116/-0) TablesAndFilters/controllers/index.php (+16/-0) TablesAndFilters/includes/TaF_excerpt.class.php (+32/-0) TablesAndFilters/includes/TaF_filteredQuery.class.php (+398/-0) TablesAndFilters/includes/TaF_table.class.php (+302/-0) TablesAndFilters/models/tableTest.query.php (+12/-0) TablesAndFilters/scripts/tableTest.php (+158/-0) TablesAndFilters/tests/taf.Test.php (+82/-0) nbproject/private/private.properties (+2/-0) nbproject/project.properties (+7/-0) nbproject/project.xml (+9/-0) |
To merge this branch: | bzr merge lp:~gregfr/phpdevshell/TablesAndFilters-v1.0.0-trunk |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
TitanKing | Pending | ||
Review via email: mp+163637@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'TablesAndFilters' | |||
2 | === added directory 'TablesAndFilters/config' | |||
3 | === added file 'TablesAndFilters/config/plugin.config.xml' | |||
4 | --- TablesAndFilters/config/plugin.config.xml 1970-01-01 00:00:00 +0000 | |||
5 | +++ TablesAndFilters/config/plugin.config.xml 2013-05-14 05:06:25 +0000 | |||
6 | @@ -0,0 +1,116 @@ | |||
7 | 1 | <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
8 | 2 | <!-- Please see http://phpdevshell.org for documentation on plugin config xml files. --> | ||
9 | 3 | <config type="plugin"> | ||
10 | 4 | |||
11 | 5 | <!-- Use a proper plugin name without using special characters. --> | ||
12 | 6 | <name>TablesAndFilters</name> | ||
13 | 7 | |||
14 | 8 | <!-- Human readable version number of your plugin. --> | ||
15 | 9 | <version>3.0</version> | ||
16 | 10 | |||
17 | 11 | <!-- a Short description of your plugin. --> | ||
18 | 12 | <description>This plugin provides easy to use tables based on query results.</description> | ||
19 | 13 | |||
20 | 14 | <!-- If the plugin/script is modification by you, place the original authors names here. --> | ||
21 | 15 | <founder>Greg Reitter</founder> | ||
22 | 16 | |||
23 | 17 | <!-- Name of the developer for this plugin. --> | ||
24 | 18 | <author>Greg Reitter</author> | ||
25 | 19 | |||
26 | 20 | <!-- Email address of the developer for this plugin. --> | ||
27 | 21 | <email>greg@phpdevshell.org</email> | ||
28 | 22 | |||
29 | 23 | <!-- Plugin developers web address. --> | ||
30 | 24 | <homepage>http://www.phpdevshell.org</homepage> | ||
31 | 25 | |||
32 | 26 | <!-- Date the plugin was developed, modified etc, this is up to you. --> | ||
33 | 27 | <date>July 2010</date> | ||
34 | 28 | |||
35 | 29 | <!-- Copyright notice you would like to amend to your plugin. --> | ||
36 | 30 | <copyright>Copyright 2010 PHPDevShell.org All rights reserved.</copyright> | ||
37 | 31 | |||
38 | 32 | <!-- License this plugin is released under. --> | ||
39 | 33 | <license>http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html GNU/LGPL</license> | ||
40 | 34 | <!-- Code Version XML URL check. --> | ||
41 | 35 | <!-- Version (current) below is used to check for new releases and has little to do with database version. --> | ||
42 | 36 | <versionurl current="3000">http://version.phpdevshell.org/TablesAndFilters.xml</versionurl> | ||
43 | 37 | |||
44 | 38 | <!-- Detailed information and help for this plugin. --> | ||
45 | 39 | <info> | ||
46 | 40 | <![CDATA[ | ||
47 | 41 | <p> | ||
48 | 42 | This plugin provides easy to use tables based on query results. | ||
49 | 43 | </p> | ||
50 | 44 | ]]> | ||
51 | 45 | </info> | ||
52 | 46 | <!-- Version here represents the database version that should be install. --> | ||
53 | 47 | <!-- If your database version needs no update, this number can stay the same. --> | ||
54 | 48 | <!-- Upgrades further down will only be executed up to this number. --> | ||
55 | 49 | <!-- This is the current database version that will be installed. --> | ||
56 | 50 | <!-- Below is a series of example upgrade procedures. --> | ||
57 | 51 | <install version="3000"> | ||
58 | 52 | <!-- | ||
59 | 53 | [contains][All query, menu, hooks, settings installation tags.] | ||
60 | 54 | [param][version][int][mandatory][The latest database version in numbers only.] | ||
61 | 55 | [note][This is how the plugin manager will know to what version upgrade scripts should be executed.] | ||
62 | 56 | [note][Always keep install maintained to the latest menu, query, hooks and setting versions.] | ||
63 | 57 | --> | ||
64 | 58 | <menus> | ||
65 | 59 | <!-- | ||
66 | 60 | [contains][All types of menu items that needs to be installed.] | ||
67 | 61 | [note][Tags inside menus can be nested and repeated.] | ||
68 | 62 | --> | ||
69 | 63 | <menu name="testTable" type="1" link="scripts/tableTest.php" hide="0" rank="last" newwindow="" plugin="TablesAndFilters" > | ||
70 | 64 | <!-- | ||
71 | 65 | [contains][Menu items can be contained in itself, this will create a menu tree.] | ||
72 | 66 | [param][name][string][not-mandatory][The name of the menu item, if empty the pluginName.menu.lang.php will be used.] | ||
73 | 67 | [param][type][int][not-mandatory][There are 8 menu types, 1 is the default if left empty.] | ||
74 | 68 | [1][Plugin script] normal plugin menu item in your plugin folder. | ||
75 | 69 | [2][Link existing menu] item while staying in its own menu group when clicked. | ||
76 | 70 | [3][Link existing menu] item while jumping to original scripts menu group when clicked. | ||
77 | 71 | [4][External file] Include external PHP web applications into PHPDevShell. | ||
78 | 72 | [5][HTTP URL] Normal url to outside web. | ||
79 | 73 | [6][Empty Place Holder] This item will only serve as a unclickable menu place holder. | ||
80 | 74 | [7][iFrame] Link url to both external url or onsite url. | ||
81 | 75 | [8][Cronjob Menu Type] The same as a plugin script but is set as cronjob. | ||
82 | 76 | [param][link][string][mandatory][The url, script location or symlink holder will be entered here depending on type.] | ||
83 | 77 | [param][hide][int][not-mandatory][There are 4 hide types, 0 is the default if left empty.] | ||
84 | 78 | [0] Do not hide menu item. | ||
85 | 79 | [1] Hide menu item from both Menu System and Control Panel. | ||
86 | 80 | [2] Hide menu item from Control Panel only. | ||
87 | 81 | [3] Hide menu item from Menu System only. | ||
88 | 82 | [4] Hide menu only when inactive. | ||
89 | 83 | [param][rank][string][not-mandatory][If you want to ensure ranking positions, will auto rank if left empty.] | ||
90 | 84 | [int] Can be ranked with integer. | ||
91 | 85 | [last] Will be ranked last in a menu group. | ||
92 | 86 | [first] Will be ranked first in a menu group. | ||
93 | 87 | [param][newwindow][int][not-mandatory][To make item open in new window set to 1, will not open in new if left empty.] | ||
94 | 88 | [param][plugin][string][not-mandatory][Plugin name, use to install menu item to a different plugins menu structure.] | ||
95 | 89 | [param][alias][string][not-mandatory][When switching on friendly urls in the settings and renaming rename.htaccess in the root, sef url will use this alias.] | ||
96 | 90 | [param][parentlink][string][not-mandatory][Use with [param][plugin] or without to install in different structure.] | ||
97 | 91 | [param][symlink][string][not-mandatory][Url or location with [param][plugin] or without to link to another menu item duplicating its use.] | ||
98 | 92 | [note][Symlink is mandatory for menu types 1,2,6] | ||
99 | 93 | [param][template][string][not-mandatory][Set template to use with plugin, if template is unavailable it will be installed.] | ||
100 | 94 | [param][template][string][not-mandatory][Set the height of an iframe menu type.] | ||
101 | 95 | [note][Height is mandatory for menu types 7] | ||
102 | 96 | [param][layout][string][not-mandatory][Set a custom template.tpl location for a certain script.] | ||
103 | 97 | [param][noautopermission][int][not-mandatory][Set to 1 to not add the installer of the plugin to permit menu item access.] | ||
104 | 98 | --> | ||
105 | 99 | </menu> | ||
106 | 100 | </menus> | ||
107 | 101 | <classes> | ||
108 | 102 | <class name="TaF_table" alias="TaF_table" plugin="TablesAndFilters" rank="last" /> | ||
109 | 103 | <class name="TaF_html_table@TaF_table" alias="TaF_table" plugin="TablesAndFilters" rank="last" /> | ||
110 | 104 | |||
111 | 105 | <class name="TaF_filteredQuery" alias="TaF_filteredQuery" plugin="TablesAndFilters" rank="last" /> | ||
112 | 106 | <class name="TaF_html_filteredQuery@TaF_filteredQuery" alias="TaF_html_filteredQuery" plugin="TablesAndFilters" rank="last" /> | ||
113 | 107 | <class name="TaF_html_filteredTable@TaF_filteredQuery" alias="TaF_html_filteredTable" plugin="TablesAndFilters" rank="last" /> | ||
114 | 108 | <class name="TaF_html_queryFilter@TaF_filteredQuery" alias="TaF_html_filteredTable" plugin="TablesAndFilters" rank="last" /> | ||
115 | 109 | <class name="TaF_list_queryFilter@TaF_filteredQuery" alias="TaF_html_filteredTable" plugin="TablesAndFilters" rank="last" /> | ||
116 | 110 | <class name="TaF_queryFilter@TaF_filteredQuery" alias="TaF_html_filteredTable" plugin="TablesAndFilters" rank="last" /> | ||
117 | 111 | <class name="TaF_radio_queryFilter@TaF_filteredQuery" alias="TaF_html_filteredTable" plugin="TablesAndFilters" rank="last" /> | ||
118 | 112 | <class name="TaF_select_queryFilter@TaF_filteredQuery" alias="TaF_html_filteredTable" plugin="TablesAndFilters" rank="last" /> | ||
119 | 113 | |||
120 | 114 | </classes> | ||
121 | 115 | </install> | ||
122 | 116 | </config> | ||
123 | 0 | 117 | ||
124 | === added directory 'TablesAndFilters/controllers' | |||
125 | === added file 'TablesAndFilters/controllers/index.php' | |||
126 | --- TablesAndFilters/controllers/index.php 1970-01-01 00:00:00 +0000 | |||
127 | +++ TablesAndFilters/controllers/index.php 2013-05-14 05:06:25 +0000 | |||
128 | @@ -0,0 +1,16 @@ | |||
129 | 1 | <?php | ||
130 | 2 | /** | ||
131 | 3 | * PHPDevShell is a RAD Framework aimed at developing administrative applications. | ||
132 | 4 | * | ||
133 | 5 | * @package PHPDevShell | ||
134 | 6 | * @link http://www.phpdevshell.org | ||
135 | 7 | * @copyright Copyright (C) 2007 Jason Schoeman, All rights reserved. | ||
136 | 8 | * @license GNU/LGPL, see readme/licensed_under_lgpl or http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html | ||
137 | 9 | * @author Jason Schoeman, Contact: titan [at] phpdevshell [dot] org. | ||
138 | 10 | * | ||
139 | 11 | * Copyright notice: See readme/notice | ||
140 | 12 | * By using PHPDevShell you agree to notice and license, if you dont agree to this notice/license you are not allowed to use PHPDevShell. | ||
141 | 13 | */ | ||
142 | 14 | // Directory listing not allowed. | ||
143 | 15 | exit('Access Denied!'); | ||
144 | 16 | ?> | ||
145 | 0 | \ No newline at end of file | 17 | \ No newline at end of file |
146 | 1 | 18 | ||
147 | === added directory 'TablesAndFilters/includes' | |||
148 | === added file 'TablesAndFilters/includes/TaF_excerpt.class.php' | |||
149 | --- TablesAndFilters/includes/TaF_excerpt.class.php 1970-01-01 00:00:00 +0000 | |||
150 | +++ TablesAndFilters/includes/TaF_excerpt.class.php 2013-05-14 05:06:25 +0000 | |||
151 | @@ -0,0 +1,32 @@ | |||
152 | 1 | <?php | ||
153 | 2 | |||
154 | 3 | |||
155 | 4 | |||
156 | 5 | class TaF_excerpt extends PHPDS_dependant | ||
157 | 6 | { | ||
158 | 7 | protected $data = array(); | ||
159 | 8 | protected $strip = true; | ||
160 | 9 | |||
161 | 10 | |||
162 | 11 | public function addArray(array $query_result) | ||
163 | 12 | { | ||
164 | 13 | //$strip = empty($options['strip']) ? $this->strip : true; | ||
165 | 14 | foreach($query_result as $key => $value) { | ||
166 | 15 | $this->data[$key] = $this->strip ? true : $value; | ||
167 | 16 | } | ||
168 | 17 | } | ||
169 | 18 | |||
170 | 19 | public function addResult($query_name) | ||
171 | 20 | { | ||
172 | 21 | $params = func_get_args(); | ||
173 | 22 | array_shift($params); // first parameter of this function is $query_name | ||
174 | 23 | $query = $this->db->makeQuery($query_name); | ||
175 | 24 | $result = $query->invoke($params); | ||
176 | 25 | if (is_array($result)) return $this->addArray($result); else return false; | ||
177 | 26 | } | ||
178 | 27 | |||
179 | 28 | public function dump() | ||
180 | 29 | { | ||
181 | 30 | print_r($this->data); | ||
182 | 31 | } | ||
183 | 32 | } | ||
184 | 0 | \ No newline at end of file | 33 | \ No newline at end of file |
185 | 1 | 34 | ||
186 | === added file 'TablesAndFilters/includes/TaF_filteredQuery.class.php' | |||
187 | --- TablesAndFilters/includes/TaF_filteredQuery.class.php 1970-01-01 00:00:00 +0000 | |||
188 | +++ TablesAndFilters/includes/TaF_filteredQuery.class.php 2013-05-14 05:06:25 +0000 | |||
189 | @@ -0,0 +1,398 @@ | |||
190 | 1 | <?php | ||
191 | 2 | |||
192 | 3 | |||
193 | 4 | |||
194 | 5 | /** | ||
195 | 6 | * FILTERED QUERIES AND TABLE - EXPERIMENTAL | ||
196 | 7 | * | ||
197 | 8 | * The basic idea is to take the winning couple PHPDS_query + PHPDS_table and add multilayers of user-provided constraints (ie filters) to it | ||
198 | 9 | * | ||
199 | 10 | * @author greg completly stolen ideas from Jason | ||
200 | 11 | * | ||
201 | 12 | */ | ||
202 | 13 | |||
203 | 14 | class TaF_queryFilter extends PHPDS_dependant | ||
204 | 15 | { | ||
205 | 16 | protected $table; // TaF_html_filteredTable | ||
206 | 17 | protected $sql = ''; // a snipet in include into the WHERE clause | ||
207 | 18 | |||
208 | 19 | protected $field = ''; // filters are usualy (but not always) in the form: "field operator value" (ie. "age > 18") | ||
209 | 20 | protected $value = ''; | ||
210 | 21 | protected $operator = '='; | ||
211 | 22 | |||
212 | 23 | public function __construct(TaF_html_filteredTable $table, TaF_filteredQuery $dependance) | ||
213 | 24 | { | ||
214 | 25 | parent::__construct($dependance); // our dependancy is the query | ||
215 | 26 | $this->table = $table; | ||
216 | 27 | |||
217 | 28 | $this->init(); | ||
218 | 29 | } | ||
219 | 30 | |||
220 | 31 | /** | ||
221 | 32 | * Give the filter a chance to alter the given query to do its job | ||
222 | 33 | * | ||
223 | 34 | * @param PHPDS_query $query | ||
224 | 35 | * @param unknown_type $mode | ||
225 | 36 | * @return unknown_type | ||
226 | 37 | */ | ||
227 | 38 | public function alterQuery(PHPDS_query $query, $mode) | ||
228 | 39 | { | ||
229 | 40 | $sql = $this->sql(); | ||
230 | 41 | if ($sql) $query->addWhere($this->sql, $mode); | ||
231 | 42 | return true; | ||
232 | 43 | } | ||
233 | 44 | |||
234 | 45 | /** | ||
235 | 46 | * return a piece of sql to be added to the WHERE clause | ||
236 | 47 | * | ||
237 | 48 | * @param unknown_type $sql | ||
238 | 49 | * @return unknown_type | ||
239 | 50 | */ | ||
240 | 51 | public function sql($sql = null) | ||
241 | 52 | { | ||
242 | 53 | if (!empty($sql)) $this->sql = $sql; | ||
243 | 54 | if (empty($this->sql) && !empty($this->field) && !empty($this->value)) $this->sql = $this->field.' '.$this->operator.' '.$this->value; | ||
244 | 55 | return $this->sql; | ||
245 | 56 | } | ||
246 | 57 | |||
247 | 58 | public function init() | ||
248 | 59 | { | ||
249 | 60 | return true; | ||
250 | 61 | } | ||
251 | 62 | } | ||
252 | 63 | |||
253 | 64 | |||
254 | 65 | |||
255 | 66 | /** | ||
256 | 67 | * Add an html presentation layer to a filter | ||
257 | 68 | * | ||
258 | 69 | * @author greg | ||
259 | 70 | * | ||
260 | 71 | */ | ||
261 | 72 | class TaF_html_queryFilter extends TaF_queryFilter | ||
262 | 73 | { | ||
263 | 74 | protected $id = ''; | ||
264 | 75 | protected $label = ''; | ||
265 | 76 | |||
266 | 77 | public function __construct(TaF_html_filteredTable $table, TaF_filteredQuery $dependance) | ||
267 | 78 | { | ||
268 | 79 | if (empty($this->id)) $this->id = $table->id().'_'.get_class($this); | ||
269 | 80 | parent::__construct($table, $dependance); | ||
270 | 81 | } | ||
271 | 82 | |||
272 | 83 | public function label($label = null) | ||
273 | 84 | { | ||
274 | 85 | if (!empty($label)) $this->label = $label; | ||
275 | 86 | return $this->label; | ||
276 | 87 | } | ||
277 | 88 | |||
278 | 89 | public function id() | ||
279 | 90 | { | ||
280 | 91 | return $this->id; | ||
281 | 92 | } | ||
282 | 93 | |||
283 | 94 | /** | ||
284 | 95 | * This should ouput some html to be added before the table | ||
285 | 96 | * | ||
286 | 97 | * @return unknown_type | ||
287 | 98 | */ | ||
288 | 99 | public function toHTML() | ||
289 | 100 | { | ||
290 | 101 | return '<p>'.$this->sql.'</p>'; | ||
291 | 102 | } | ||
292 | 103 | |||
293 | 104 | /** | ||
294 | 105 | * Support for dynamic reload: bind the javascript function in a way you want it to be called for reloading the table | ||
295 | 106 | * | ||
296 | 107 | * @return javascript code to add inside a <script> clause | ||
297 | 108 | */ | ||
298 | 109 | public function toJSbind() | ||
299 | 110 | { | ||
300 | 111 | return ''; | ||
301 | 112 | } | ||
302 | 113 | |||
303 | 114 | /** | ||
304 | 115 | * | ||
305 | 116 | * This should return a pair key=value to add to the request to ensure the filtering | ||
306 | 117 | * | ||
307 | 118 | * @return string in the form " key=value " suitable for html request (such as GET or POST) | ||
308 | 119 | */ | ||
309 | 120 | public function toJSdata() | ||
310 | 121 | { | ||
311 | 122 | return ''; | ||
312 | 123 | } | ||
313 | 124 | } | ||
314 | 125 | |||
315 | 126 | |||
316 | 127 | |||
317 | 128 | |||
318 | 129 | |||
319 | 130 | /** | ||
320 | 131 | * A filter based on a list of key=>value pairs, possibly from a secondary query | ||
321 | 132 | * | ||
322 | 133 | * @author greg | ||
323 | 134 | * | ||
324 | 135 | */ | ||
325 | 136 | class TaF_list_queryFilter extends TaF_html_queryFilter | ||
326 | 137 | { | ||
327 | 138 | protected $list = array(); | ||
328 | 139 | protected $listQuery; | ||
329 | 140 | |||
330 | 141 | public function init () | ||
331 | 142 | { | ||
332 | 143 | if (!empty($this->listQuery)) { | ||
333 | 144 | $dep = array_pop(func_get_args()); | ||
334 | 145 | |||
335 | 146 | $this->list = $this->buildList(); | ||
336 | 147 | } | ||
337 | 148 | |||
338 | 149 | //if ($this->select($this->select) != $this->select) | ||
339 | 150 | $select = isset($_POST[$this->id()]) ? $_POST[$this->id()] : $this->defValue(); | ||
340 | 151 | // $this->select(VeM_GetFromRequest($this->id, $this->defValue())); | ||
341 | 152 | $this->value($select); | ||
342 | 153 | //TODO: get parameter is a nicer way | ||
343 | 154 | } | ||
344 | 155 | |||
345 | 156 | public function buildList() | ||
346 | 157 | { | ||
347 | 158 | return is_a($this->listQuery, PHPDS_query) ? $dep->db->invokeQuery($this->listQuery): array(); | ||
348 | 159 | } | ||
349 | 160 | |||
350 | 161 | public function value($value = null) | ||
351 | 162 | { | ||
352 | 163 | if (!is_null($value)) { | ||
353 | 164 | if (is_array($this->list) && isset($this->list[$value])) $this->value = $value; | ||
354 | 165 | } | ||
355 | 166 | return $this->value; | ||
356 | 167 | } | ||
357 | 168 | |||
358 | 169 | public function defValue() | ||
359 | 170 | { | ||
360 | 171 | if (!empty($this->value)) return $this->value; | ||
361 | 172 | |||
362 | 173 | $a = array_keys($this->list); | ||
363 | 174 | $b = array_shift(array_keys($this->list)); | ||
364 | 175 | if (is_array($this->list)) return array_shift(array_keys($this->list)); | ||
365 | 176 | } | ||
366 | 177 | } | ||
367 | 178 | |||
368 | 179 | |||
369 | 180 | |||
370 | 181 | /** | ||
371 | 182 | * | ||
372 | 183 | * @author greg | ||
373 | 184 | * | ||
374 | 185 | */ | ||
375 | 186 | class TaF_select_queryFilter extends TaF_list_queryFilter | ||
376 | 187 | { | ||
377 | 188 | public function toHTML() | ||
378 | 189 | { | ||
379 | 190 | $fct_name = $this->table->makeName('js_reload'); | ||
380 | 191 | $html = "<label for=\"{$this->id}\">".$this->label()."</label>"; | ||
381 | 192 | $html .= "<select id=\"{$this->id}\" name=\"{$this->id}\" onChange=\"$fct_name()\" >"; | ||
382 | 193 | foreach($this->list as $key => $value) $html .= "<option value=\"$key\"".($this->value == $key ? 'selected' : '').">$value</option>"; | ||
383 | 194 | $html .= '</select>'; | ||
384 | 195 | |||
385 | 196 | return $html; | ||
386 | 197 | } | ||
387 | 198 | |||
388 | 199 | /*public function toJSbind() | ||
389 | 200 | { | ||
390 | 201 | $js = "$('#{$this->id}').change(function() { alert('toto'); $fct_name });"; | ||
391 | 202 | return $js; | ||
392 | 203 | }*/ | ||
393 | 204 | |||
394 | 205 | /*public function toJSdata() | ||
395 | 206 | { | ||
396 | 207 | return "'&{$this->id}=' + $('#{$this->id}').val()"; | ||
397 | 208 | }*/ | ||
398 | 209 | |||
399 | 210 | } | ||
400 | 211 | |||
401 | 212 | |||
402 | 213 | |||
403 | 214 | |||
404 | 215 | |||
405 | 216 | |||
406 | 217 | |||
407 | 218 | class TaF_radio_queryFilter extends TaF_list_queryFilter | ||
408 | 219 | |||
409 | 220 | { | ||
410 | 221 | protected $classes = array('line' => 'filterline', 'input' => 'filterinput'); | ||
411 | 222 | |||
412 | 223 | public function toHTML() | ||
413 | 224 | { | ||
414 | 225 | $html = '<div class="'.$this->classes['line'].'">'; | ||
415 | 226 | $html .= '<label>'.$this->label().'</label>'; | ||
416 | 227 | foreach($this->list as $key => $value) { | ||
417 | 228 | $name = $this->id; | ||
418 | 229 | $id = $name.'_'.$value; | ||
419 | 230 | $html .= "<input type=\"radio\" id=\"$id\" name=\"$name\" class=\"{$this->classes['input']}\" value=\"$key\" "; | ||
420 | 231 | if ($key == $this->value) $html .= 'checked '; | ||
421 | 232 | $html .= "/><label for=\"$id\">$value</label>"; | ||
422 | 233 | } | ||
423 | 234 | $html .= '</div>'; | ||
424 | 235 | return $html; | ||
425 | 236 | } | ||
426 | 237 | |||
427 | 238 | public function toJSbind($fct_name = '') | ||
428 | 239 | { | ||
429 | 240 | return "$('input[name={$this->id}]').click(function() { $fct_name; });"; | ||
430 | 241 | } | ||
431 | 242 | |||
432 | 243 | public function toJSdata() | ||
433 | 244 | { | ||
434 | 245 | return "'&{$this->id}=' + $('input:radio[name={$this->id}]:checked').val()"; | ||
435 | 246 | } | ||
436 | 247 | } | ||
437 | 248 | |||
438 | 249 | |||
439 | 250 | |||
440 | 251 | |||
441 | 252 | |||
442 | 253 | |||
443 | 254 | |||
444 | 255 | class TaF_filteredQuery extends PHPDS_query | ||
445 | 256 | { | ||
446 | 257 | |||
447 | 258 | protected $filters = array(); | ||
448 | 259 | protected $mode = 'AND'; | ||
449 | 260 | |||
450 | 261 | /* | ||
451 | 262 | * filter can be a TaF_queryFilter object or a TaF_queryFilter-descendant class name | ||
452 | 263 | */ | ||
453 | 264 | public function addFilter($filter, TaF_html_filteredTable $table) | ||
454 | 265 | { | ||
455 | 266 | if (is_a($filter, 'TaF_queryFilter')) $this->filters[] = $filter; | ||
456 | 267 | else { | ||
457 | 268 | $params = func_get_args(); | ||
458 | 269 | array_shift($params); // shift-off $filter class name | ||
459 | 270 | $this->filters[] = $this->_factory($filter, $params); | ||
460 | 271 | } | ||
461 | 272 | return $this; | ||
462 | 273 | } | ||
463 | 274 | |||
464 | 275 | /** | ||
465 | 276 | * Construct the extra part of the query (WHERE ... GROUP BY ... ORDER BY...) | ||
466 | 277 | * Doesn't change $this->sql but DOES alter the query (our local clone) | ||
467 | 278 | * | ||
468 | 279 | * @param array $parameters | ||
469 | 280 | * @return string (sql) | ||
470 | 281 | */ | ||
471 | 282 | public function extra_build($parameters = null) | ||
472 | 283 | { | ||
473 | 284 | foreach ($this->filters as $filter) $filter->alterQuery($this, $this->mode); | ||
474 | 285 | |||
475 | 286 | return parent::extra_build($parameters); | ||
476 | 287 | } | ||
477 | 288 | } | ||
478 | 289 | |||
479 | 290 | |||
480 | 291 | |||
481 | 292 | |||
482 | 293 | |||
483 | 294 | |||
484 | 295 | |||
485 | 296 | class TaF_html_filteredQuery extends TaF_filteredQuery | ||
486 | 297 | { | ||
487 | 298 | public function filtersAsHTML() | ||
488 | 299 | { | ||
489 | 300 | $html = ''; | ||
490 | 301 | foreach($this->filters as $filter) $html .= $filter->toHTML(); | ||
491 | 302 | return $html; | ||
492 | 303 | } | ||
493 | 304 | |||
494 | 305 | public function filtersAsJSbind() | ||
495 | 306 | { | ||
496 | 307 | $js = ''; | ||
497 | 308 | foreach($this->filters as $filter) $js .= $filter->toJSbind()."\n"; | ||
498 | 309 | return $js; | ||
499 | 310 | } | ||
500 | 311 | |||
501 | 312 | public function filtersAsJSdata() | ||
502 | 313 | { | ||
503 | 314 | $js = array(); | ||
504 | 315 | foreach($this->filters as $filter) $js[] = $filter->toJSdata(); | ||
505 | 316 | return implode(' + ', $js); | ||
506 | 317 | } | ||
507 | 318 | |||
508 | 319 | } | ||
509 | 320 | |||
510 | 321 | |||
511 | 322 | |||
512 | 323 | |||
513 | 324 | |||
514 | 325 | |||
515 | 326 | |||
516 | 327 | |||
517 | 328 | |||
518 | 329 | |||
519 | 330 | |||
520 | 331 | |||
521 | 332 | class TaF_html_filteredTable extends TaF_html_table | ||
522 | 333 | { | ||
523 | 334 | /* | ||
524 | 335 | * filter can be a TaF_queryFilter object or a TaF_queryFilter-descendant class name | ||
525 | 336 | */ | ||
526 | 337 | public function addFilter($filter) | ||
527 | 338 | { | ||
528 | 339 | if (is_a($this->query, 'TaF_html_filteredQuery')) $this->query->addFilter($filter, $this); | ||
529 | 340 | } | ||
530 | 341 | |||
531 | 342 | public function makeName($action) | ||
532 | 343 | { | ||
533 | 344 | switch ($action) { | ||
534 | 345 | case 'js_reload': return 'TaFReload_'.$this->id; | ||
535 | 346 | } | ||
536 | 347 | } | ||
537 | 348 | |||
538 | 349 | public function make_html($forceLoad = false) | ||
539 | 350 | { | ||
540 | 351 | // first fetch the data | ||
541 | 352 | $data_html = parent::make_html($forceLoad); | ||
542 | 353 | |||
543 | 354 | // then add some headers | ||
544 | 355 | $html = $this->make_tag('div', $this->id.'_container', array('class' => 'slidingTable')); | ||
545 | 356 | $url = PU_BuildURL(); | ||
546 | 357 | $html .= $this->make_tag('form', $this->id.'_form', array('action' => $url)); | ||
547 | 358 | if (is_a($this->query, 'TaF_html_filteredQuery')) $html .= $this->filtersAsHTML($this); // this is actually calling the query's method "filtersAsHTML()", at least if it's not overriden by the table | ||
548 | 359 | $html .= $data_html; | ||
549 | 360 | |||
550 | 361 | //and some footers | ||
551 | 362 | $html .= $this->make_tag(); // _form | ||
552 | 363 | $html .= $this->make_tag(); // _container | ||
553 | 364 | if (is_a($this->query, 'TaF_html_filteredQuery')) $html .= $this->make_js($this); | ||
554 | 365 | |||
555 | 366 | return $html; | ||
556 | 367 | } | ||
557 | 368 | |||
558 | 369 | public function make_js() | ||
559 | 370 | { | ||
560 | 371 | $fct_name = $this->makeName('js_reload'); | ||
561 | 372 | |||
562 | 373 | if ($js_filters = $this->query->filtersASJSdata()) $js_filters .= ' + '.$js_filters; | ||
563 | 374 | |||
564 | 375 | $js = '<script type="text/javascript" language="javascript">'; | ||
565 | 376 | $js .= "\n//<![CDATA[\n"; | ||
566 | 377 | $js .= <<<EndOfJavascript | ||
567 | 378 | |||
568 | 379 | |||
569 | 380 | function $fct_name(opt) | ||
570 | 381 | { | ||
571 | 382 | url = $('#{$this->id}_form').attr('action'); | ||
572 | 383 | params = $('#{$this->id}_form').serializeArray(); // so it's sent as POST | ||
573 | 384 | if (opt) params[params.length] = opt; | ||
574 | 385 | $('#{$this->id}_container').load(url + ' #{$this->id}_form', params); | ||
575 | 386 | } | ||
576 | 387 | |||
577 | 388 | |||
578 | 389 | EndOfJavascript; | ||
579 | 390 | |||
580 | 391 | $js .= $this->query->filtersAsJSbind($fct_name); | ||
581 | 392 | |||
582 | 393 | $js .= "\n//]]>\n</script>"; | ||
583 | 394 | |||
584 | 395 | return $js; | ||
585 | 396 | } | ||
586 | 397 | } | ||
587 | 398 | |||
588 | 0 | 399 | ||
589 | === added file 'TablesAndFilters/includes/TaF_table.class.php' | |||
590 | --- TablesAndFilters/includes/TaF_table.class.php 1970-01-01 00:00:00 +0000 | |||
591 | +++ TablesAndFilters/includes/TaF_table.class.php 2013-05-14 05:06:25 +0000 | |||
592 | @@ -0,0 +1,302 @@ | |||
593 | 1 | <?php | ||
594 | 2 | |||
595 | 3 | |||
596 | 4 | |||
597 | 5 | /** | ||
598 | 6 | * Basic class to link a table (i.e. tabular data) to a query result | ||
599 | 7 | * | ||
600 | 8 | * Usage 1 (implict instanciation of the class given its name): | ||
601 | 9 | * $params = array( | ||
602 | 10 | * 'query' => 'my_query_class', | ||
603 | 11 | * 'showHeaders' => true, | ||
604 | 12 | * 'headers' => array('ref' => 'Reference', 'name' => 'User name') | ||
605 | 13 | * ); | ||
606 | 14 | * $t = $this->factory('TaF_table', $params); | ||
607 | 15 | * | ||
608 | 16 | * Usage 2 (you already have instanciated the class, you pass the object): | ||
609 | 17 | * $query = $this->db->makeQuery('my_query_class', $query_parameters); | ||
610 | 18 | * $params = array( | ||
611 | 19 | * 'query' => 'my_query_class', | ||
612 | 20 | * 'showHeaders' => true, | ||
613 | 21 | * 'headers' => array('ref' => 'Reference', 'name' => 'User name') | ||
614 | 22 | * ); | ||
615 | 23 | * $t = $this->factory($query, $params); | ||
616 | 24 | * | ||
617 | 25 | * Note: all unknown method class are routed to the query so you can actually do something like: $t->sql('SELECT * FROM mytable'); | ||
618 | 26 | * | ||
619 | 27 | * @author greg | ||
620 | 28 | * | ||
621 | 29 | */ | ||
622 | 30 | class TaF_table extends PHPDS_dependant | ||
623 | 31 | { | ||
624 | 32 | /** | ||
625 | 33 | * These are the parameters used to customize the table: | ||
626 | 34 | * - query (optional): name of the query to instanciate or query object to use; if blank a useless empty PHPDS_query is created | ||
627 | 35 | * - query_parameters (optional): parameters to pass on to the query when it's actually invokated | ||
628 | 36 | * @var unknown_type | ||
629 | 37 | */ | ||
630 | 38 | protected $parameters; // array | ||
631 | 39 | |||
632 | 40 | protected $parent = 'query'; | ||
633 | 41 | protected $query; // PHPDS_query | ||
634 | 42 | protected $data; // array | ||
635 | 43 | |||
636 | 44 | protected $request; | ||
637 | 45 | |||
638 | 46 | protected $headers; | ||
639 | 47 | protected $classes; | ||
640 | 48 | |||
641 | 49 | protected static $defaults = array('showHeaders' => false); | ||
642 | 50 | |||
643 | 51 | |||
644 | 52 | public function construct ($parameters = null) | ||
645 | 53 | { | ||
646 | 54 | $this->parameters = is_array($parameters) ? array_merge(self::$defaults, $parameters) : self::$defaults; | ||
647 | 55 | |||
648 | 56 | $query = empty($this->parameters['query']) ? 'PHPDS_query' : $this->parameters['query']; | ||
649 | 57 | $this->query = (is_a($query, 'PHPDS_query')) ? clone $query : $this->db->makeQuery($query); | ||
650 | 58 | // TODO: is "clone" enough??? | ||
651 | 59 | |||
652 | 60 | if (!empty($this->parameters->sql)) $this->query->sql($this->parameters->sql); | ||
653 | 61 | } | ||
654 | 62 | |||
655 | 63 | |||
656 | 64 | /** | ||
657 | 65 | * Use the query to load all data into memory | ||
658 | 66 | * | ||
659 | 67 | * Unless forced, if the data is already in memory, do nothing | ||
660 | 68 | * | ||
661 | 69 | * @version 1.1 | ||
662 | 70 | * @date 20100528 (greg) (v1.1) use the query parameters taken from the table parameters array, if any | ||
663 | 71 | * | ||
664 | 72 | * @param boolean $force | ||
665 | 73 | * @return array the data | ||
666 | 74 | */ | ||
667 | 75 | public function load($force = false) | ||
668 | 76 | { | ||
669 | 77 | if (empty($this->data) || $force) { | ||
670 | 78 | $this->data = empty($this->parameters['query_parameters']) ? $this->query->invoke() : $this->query->invoke($this->parameters['query_parameters']); | ||
671 | 79 | |||
672 | 80 | $this->purge(); | ||
673 | 81 | } | ||
674 | 82 | |||
675 | 83 | return $this->data; | ||
676 | 84 | } | ||
677 | 85 | |||
678 | 86 | public function make_request() | ||
679 | 87 | { | ||
680 | 88 | $this->request = $this->query->query(); | ||
681 | 89 | } | ||
682 | 90 | |||
683 | 91 | public function purge() | ||
684 | 92 | { | ||
685 | 93 | } | ||
686 | 94 | |||
687 | 95 | public function next() | ||
688 | 96 | { | ||
689 | 97 | } | ||
690 | 98 | |||
691 | 99 | public function count() | ||
692 | 100 | { | ||
693 | 101 | if (empty($data)) return $this->query->count(); | ||
694 | 102 | else return count($this->data); | ||
695 | 103 | } | ||
696 | 104 | |||
697 | 105 | public function scan($line) | ||
698 | 106 | { | ||
699 | 107 | return $line; | ||
700 | 108 | |||
701 | 109 | } | ||
702 | 110 | |||
703 | 111 | /*public function __call($name, $arguments) | ||
704 | 112 | { | ||
705 | 113 | if (method_exists($this->query, $name)) return call_user_func_array(array($this->query, $name), $arguments); | ||
706 | 114 | else trigger_error("Table's query doesn't have a \"$name\"() method."); | ||
707 | 115 | }*/ | ||
708 | 116 | |||
709 | 117 | public function data($data = null) | ||
710 | 118 | { | ||
711 | 119 | if (is_array($data)) $this->data = $data; | ||
712 | 120 | return $this->data; | ||
713 | 121 | } | ||
714 | 122 | } | ||
715 | 123 | |||
716 | 124 | |||
717 | 125 | /** | ||
718 | 126 | * An easy way to turn a query into a flexible HTML table | ||
719 | 127 | * | ||
720 | 128 | * @author greg | ||
721 | 129 | * | ||
722 | 130 | */ | ||
723 | 131 | class TaF_html_table extends TaF_table | ||
724 | 132 | { | ||
725 | 133 | protected $alternate_styles = array('alt1', 'alt1', 'alt1', 'alt2', 'alt2', 'alt2'); | ||
726 | 134 | protected $tag_styles = array( | ||
727 | 135 | 'table' => 'inside_table', 'tr'=> 'highlight', 'th' => 'head' | ||
728 | 136 | ); | ||
729 | 137 | protected $id = ''; | ||
730 | 138 | |||
731 | 139 | protected $tag_stack = array(); | ||
732 | 140 | |||
733 | 141 | protected $empty_content = ' '; // default value in case we have to value to display | ||
734 | 142 | |||
735 | 143 | |||
736 | 144 | public function construct ($parameters = null) | ||
737 | 145 | { | ||
738 | 146 | if (empty($this->id)) $this->id = get_class($this); | ||
739 | 147 | //call_user_func_array(array($this, 'parent::__construct'), func_get_args()); | ||
740 | 148 | parent::construct ($parameters); | ||
741 | 149 | } | ||
742 | 150 | |||
743 | 151 | public function id() | ||
744 | 152 | { | ||
745 | 153 | return $this->id; | ||
746 | 154 | } | ||
747 | 155 | |||
748 | 156 | /** | ||
749 | 157 | * Creates an array with the key and the labels of the headers | ||
750 | 158 | * | ||
751 | 159 | * @date 20100428 (v1.0) (greg) | ||
752 | 160 | * @version 1.0 | ||
753 | 161 | * @author greg | ||
754 | 162 | * @param array $data an row of data | ||
755 | 163 | * @return array | ||
756 | 164 | */ | ||
757 | 165 | public function build_headers($data) | ||
758 | 166 | { | ||
759 | 167 | $result = array(); | ||
760 | 168 | |||
761 | 169 | if (!empty($this->parameters['headers'])) { | ||
762 | 170 | // field list is given as a parameter | ||
763 | 171 | $result = $this->parameters['headers']; | ||
764 | 172 | /*foreach ($this->parameters['headers'] as $key => $value) { | ||
765 | 173 | $result .= $this->make_tag('th'); | ||
766 | 174 | $result .= $value; | ||
767 | 175 | $result .= $this->make_tag(); | ||
768 | 176 | }*/ | ||
769 | 177 | } elseif (!empty($this->query->fields)) { | ||
770 | 178 | // fields are explicitly listed | ||
771 | 179 | foreach ($this->query->fields as $key => $value) { | ||
772 | 180 | // $key is column field name (from the DB point of view, $value is what's displayed | ||
773 | 181 | $result[$key] = $value; | ||
774 | 182 | } | ||
775 | 183 | } elseif (is_array($data)) { | ||
776 | 184 | // we're on our own, so we try to get the field names from the database result | ||
777 | 185 | $first_line = $data[array_shift(array_keys($data))]; | ||
778 | 186 | if (is_array($first_line)) { | ||
779 | 187 | $keys = array_keys($first_line); | ||
780 | 188 | $result = array_combine($keys, $keys); | ||
781 | 189 | } else $result = array('#', '_'); | ||
782 | 190 | } | ||
783 | 191 | |||
784 | 192 | return $result; | ||
785 | 193 | } | ||
786 | 194 | |||
787 | 195 | /** | ||
788 | 196 | * Takes a header array and make an html string out of it | ||
789 | 197 | * | ||
790 | 198 | * @date 20100428 (v1.0) (greg) | ||
791 | 199 | * @version 1.0 | ||
792 | 200 | * @author greg | ||
793 | 201 | * @param array $headers | ||
794 | 202 | * @return string | ||
795 | 203 | */ | ||
796 | 204 | public function make_headers($headers) | ||
797 | 205 | { | ||
798 | 206 | $result = ''; | ||
799 | 207 | if (!empty($this->parameters['showHeaders'])) { | ||
800 | 208 | $result .= $this->make_tag('thead'); | ||
801 | 209 | $result .= $this->make_tag('tr'); | ||
802 | 210 | |||
803 | 211 | if(is_array($headers)) { | ||
804 | 212 | foreach ($headers as $key => $value) { | ||
805 | 213 | // $key is column field name (from the DB point of view, $value is what's displayed | ||
806 | 214 | $result .= $this->make_tag('th'); | ||
807 | 215 | $result .= $value; | ||
808 | 216 | $result .= $this->make_tag(); // th | ||
809 | 217 | } | ||
810 | 218 | } | ||
811 | 219 | $result .= $this->make_tag(); //tr | ||
812 | 220 | $result .= $this->make_tag(); //theader | ||
813 | 221 | } | ||
814 | 222 | return $result; | ||
815 | 223 | } | ||
816 | 224 | |||
817 | 225 | |||
818 | 226 | public function make_html($forceLoad = false) | ||
819 | 227 | { | ||
820 | 228 | $this->load($forceLoad); | ||
821 | 229 | $result = $this->make_tag('table', $this->id.'_table'); | ||
822 | 230 | |||
823 | 231 | if (is_array($this->data) && count($this->data) > 0) { | ||
824 | 232 | $headers = $this->build_headers($this->data); | ||
825 | 233 | $result .= $this->make_headers($headers); | ||
826 | 234 | |||
827 | 235 | $line_index = 0; | ||
828 | 236 | |||
829 | 237 | $result .= $this->make_tag('tbody'); | ||
830 | 238 | foreach($this->data as $idx => $line) { | ||
831 | 239 | $style = $this->alternate_styles[$line_index % count($this->alternate_styles)]; | ||
832 | 240 | $result .= $this->make_tag('tr', '', array('class' => $style)); | ||
833 | 241 | |||
834 | 242 | foreach($headers as $key => $value) $result .= $this->make_cell($key, $line_index, $line, $idx); | ||
835 | 243 | $result .= $this->make_tag(); // tr | ||
836 | 244 | $line_index++; | ||
837 | 245 | } | ||
838 | 246 | $result .= $this->make_tag(); // tbody | ||
839 | 247 | } | ||
840 | 248 | |||
841 | 249 | $result .= $this->make_tag(); // table | ||
842 | 250 | |||
843 | 251 | return $result; | ||
844 | 252 | } | ||
845 | 253 | |||
846 | 254 | |||
847 | 255 | public function make_cell($key, $line_index, $line, $idx) | ||
848 | 256 | { | ||
849 | 257 | $result = $this->make_tag('td'); | ||
850 | 258 | $matches = array(); | ||
851 | 259 | if (preg_match('/.+ as (?<alias>.+)/', $key, $matches)) $key = $matches['alias']; | ||
852 | 260 | if (is_array($line)) { | ||
853 | 261 | $value = empty($line[$key]) ? '' : $line[$key]; | ||
854 | 262 | } else $value = $line; | ||
855 | 263 | $content = $this->chew($key, $line_index, $line, $value, $idx); | ||
856 | 264 | if (empty($content)) $content = $this->empty_content; | ||
857 | 265 | $result .= $content; | ||
858 | 266 | $result .= $this->make_tag(); | ||
859 | 267 | return $result; | ||
860 | 268 | } | ||
861 | 269 | |||
862 | 270 | /** | ||
863 | 271 | * Placeholder to give you the opportunity to alter a cell content before it's displayed | ||
864 | 272 | * | ||
865 | 273 | * @param string $column_key | ||
866 | 274 | * @param integer $line_index | ||
867 | 275 | * @param array $line | ||
868 | 276 | * @param mixed $value | ||
869 | 277 | * @return striing | ||
870 | 278 | */ | ||
871 | 279 | public function chew($column_key, $line_index, $line, $value) | ||
872 | 280 | { | ||
873 | 281 | return $value; | ||
874 | 282 | } | ||
875 | 283 | |||
876 | 284 | public function make_tag($tag = null, $id = '', array $attributes = array(), $single = false) | ||
877 | 285 | { | ||
878 | 286 | if (empty($tag)) { | ||
879 | 287 | $html = '</'.array_pop($this->tag_stack).'>'; | ||
880 | 288 | } else { | ||
881 | 289 | $class_tag = empty($this->tag_styles[$tag]) ? array() : array('class' => $this->tag_styles[$tag]); | ||
882 | 290 | $attr = PU_BuildAttrString(array_merge($class_tag, $attributes)); | ||
883 | 291 | if ($id) $id = " id=\"$id\" "; | ||
884 | 292 | if ($single) { | ||
885 | 293 | $html ="<$tag$id$attr />"; | ||
886 | 294 | }else { | ||
887 | 295 | array_push($this->tag_stack, $tag); | ||
888 | 296 | $html ="<$tag$id$attr>"; | ||
889 | 297 | } | ||
890 | 298 | } | ||
891 | 299 | |||
892 | 300 | return $html; | ||
893 | 301 | } | ||
894 | 302 | } | ||
895 | 0 | \ No newline at end of file | 303 | \ No newline at end of file |
896 | 1 | 304 | ||
897 | === added directory 'TablesAndFilters/models' | |||
898 | === added file 'TablesAndFilters/models/tableTest.query.php' | |||
899 | --- TablesAndFilters/models/tableTest.query.php 1970-01-01 00:00:00 +0000 | |||
900 | +++ TablesAndFilters/models/tableTest.query.php 2013-05-14 05:06:25 +0000 | |||
901 | @@ -0,0 +1,12 @@ | |||
902 | 1 | <?php | ||
903 | 2 | //require_once 'includes/query.class.php'; | ||
904 | 3 | |||
905 | 4 | class testTableQuery extends TaF_html_filteredQuery | ||
906 | 5 | { | ||
907 | 6 | protected $sql = 'SELECT SQL_CALC_FOUND_ROWS * FROM _db_core_menu_items'; | ||
908 | 7 | protected $keyField = 'user_name'; | ||
909 | 8 | |||
910 | 9 | } | ||
911 | 10 | |||
912 | 11 | |||
913 | 12 | |||
914 | 0 | 13 | ||
915 | === added directory 'TablesAndFilters/scripts' | |||
916 | === added file 'TablesAndFilters/scripts/tableTest.php' | |||
917 | --- TablesAndFilters/scripts/tableTest.php 1970-01-01 00:00:00 +0000 | |||
918 | +++ TablesAndFilters/scripts/tableTest.php 2013-05-14 05:06:25 +0000 | |||
919 | @@ -0,0 +1,158 @@ | |||
920 | 1 | <?php | ||
921 | 2 | |||
922 | 3 | //(is_object($security)) ? $this->security->load_security(true) : exit('Access Denied!'); //////////////////////////////////////// | ||
923 | 4 | |||
924 | 5 | ?> | ||
925 | 6 | |||
926 | 7 | <style type="text/css"> | ||
927 | 8 | .navigBtn { | ||
928 | 9 | padding: 3px; | ||
929 | 10 | outline: 1px solid black; | ||
930 | 11 | } | ||
931 | 12 | </style> | ||
932 | 13 | |||
933 | 14 | <?php | ||
934 | 15 | |||
935 | 16 | |||
936 | 17 | class_exists('TaF_table'); | ||
937 | 18 | class_exists('TaF_filteredQuery'); | ||
938 | 19 | class_exists('PHPDS_user'); | ||
939 | 20 | |||
940 | 21 | |||
941 | 22 | |||
942 | 23 | |||
943 | 24 | class pagingFilter extends TaF_html_queryFilter | ||
944 | 25 | { | ||
945 | 26 | protected $pageSize = 10; | ||
946 | 27 | protected $pageNumber = 1; | ||
947 | 28 | |||
948 | 29 | protected $foundRows = 0; | ||
949 | 30 | protected $numRows = 0; | ||
950 | 31 | protected $lastPage = 0; | ||
951 | 32 | |||
952 | 33 | public function init() | ||
953 | 34 | { | ||
954 | 35 | $pageNo = empty($_POST['pageNo']) ? 1 :intval($_POST['pageNo']); | ||
955 | 36 | if ($pageNo > 0) $this->pageNumber = $pageNo; | ||
956 | 37 | |||
957 | 38 | $pageSize = empty($_POST['pageSize']) ? 10 : intval($_POST['pageSize']); | ||
958 | 39 | if ($pageSize > 0) $this->pageSize = $pageSize; | ||
959 | 40 | } | ||
960 | 41 | |||
961 | 42 | public function makeNavigBtn($label, $pageNo, $fct_name, $extra = '') | ||
962 | 43 | { | ||
963 | 44 | $html = '<button class="navigBtn" onClick="'.$fct_name.'({name:\'pageNo\',value:\''.$pageNo.'\'})"'; | ||
964 | 45 | $html .= ' type="button" value="'.$pageNo.'" name="'.$this->id().'" '.$extra.' >'.$label.'</button>'; | ||
965 | 46 | |||
966 | 47 | return $html; | ||
967 | 48 | } | ||
968 | 49 | |||
969 | 50 | public function toHTML() | ||
970 | 51 | { | ||
971 | 52 | $this->numRows = $this->count(); | ||
972 | 53 | $this->foundRows = mysql_result($this->db->connector->query('SELECT FOUND_ROWS()'), 0 ,0); | ||
973 | 54 | |||
974 | 55 | $this->lastPage = intval($this->foundRows / $this->pageSize) + 1; | ||
975 | 56 | |||
976 | 57 | $fct_name = $this->table->makeName('js_reload'); | ||
977 | 58 | |||
978 | 59 | $html = '<p>Paging by '.$this->pageSize.' rows - '.time().'</p>'; | ||
979 | 60 | $html .= '<p>Rows on page '.$this->pageNumber.' (for a total of '.$this->foundRows.' rows on '.$this->lastPage.' pages)</p>'; | ||
980 | 61 | |||
981 | 62 | $disabled = ($this->pageNumber < 2) ? 'disabled' : ''; | ||
982 | 63 | $html .= $this->makeNavigBtn('First', 1, $fct_name, $disabled); | ||
983 | 64 | $html .= $this->makeNavigBtn('Prev', $this->pageNumber - 1, $fct_name, $disabled); | ||
984 | 65 | |||
985 | 66 | $disabled = ($this->pageNumber >= $this->lastPage) ? 'disabled' : ''; | ||
986 | 67 | $html .= $this->makeNavigBtn('Next', $this->pageNumber + 1, $fct_name, $disabled); | ||
987 | 68 | $html .= $this->makeNavigBtn('Last', $this->lastPage, $fct_name, $disabled); | ||
988 | 69 | |||
989 | 70 | return $html; | ||
990 | 71 | } | ||
991 | 72 | |||
992 | 73 | public function alterQuery(PHPDS_query $query, $mode) | ||
993 | 74 | { | ||
994 | 75 | if ($this->pageSize < 1) $this->pageSize = 1; | ||
995 | 76 | if ($this->pageNumber < 1) $this->pageNumber = 1; | ||
996 | 77 | |||
997 | 78 | $query->limit($this->pageSize * ($this->pageNumber -1).', '.$this->pageSize); | ||
998 | 79 | return true; | ||
999 | 80 | } | ||
1000 | 81 | } | ||
1001 | 82 | |||
1002 | 83 | |||
1003 | 84 | |||
1004 | 85 | class testTable extends TaF_html_filteredTable | ||
1005 | 86 | { | ||
1006 | 87 | /*public function _make_js() | ||
1007 | 88 | { | ||
1008 | 89 | $fct_name = 'TaFReload_'.$this->id; | ||
1009 | 90 | |||
1010 | 91 | if ($js_filters = $this->query->filtersASJSdata()) $js_filters .= ' + '.$js_filters; | ||
1011 | 92 | |||
1012 | 93 | $js = '<script type="text/javascript" language="javascript">'; | ||
1013 | 94 | $js .= "\n//<![CDATA[\n"; | ||
1014 | 95 | $js .= <<<EOS | ||
1015 | 96 | |||
1016 | 97 | |||
1017 | 98 | function $fct_name(url, dir) | ||
1018 | 99 | { | ||
1019 | 100 | if (dir < 0) { | ||
1020 | 101 | jQuery.get(url{$js_filters} + ' #{$this->id}_div', function (data, textStatus, XMLHttpRequest) { | ||
1021 | 102 | $('#{$this->id}_container').prepend($(data).find('#testTable_div')); | ||
1022 | 103 | previous = $('#{$this->id}_container div:last-child'); | ||
1023 | 104 | //previous.slideDown(function() { previous.remove(); }); | ||
1024 | 105 | }); | ||
1025 | 106 | } else { | ||
1026 | 107 | jQuery.get(url{$js_filters} + ' #{$this->id}_div', function (data, textStatus, XMLHttpRequest) { | ||
1027 | 108 | $('#{$this->id}_container').append($(data).find('#testTable_div')); | ||
1028 | 109 | previous = $('#{$this->id}_container div:first-child'); | ||
1029 | 110 | previous.slideUp(function() { previous.remove(); }); | ||
1030 | 111 | }); | ||
1031 | 112 | } | ||
1032 | 113 | } | ||
1033 | 114 | |||
1034 | 115 | |||
1035 | 116 | EOS; | ||
1036 | 117 | |||
1037 | 118 | $js .= '$(document).ready(function() {'; | ||
1038 | 119 | $js .= $this->query->filtersAsJSbind($fct_name.'();'); | ||
1039 | 120 | $js .=' });'; | ||
1040 | 121 | |||
1041 | 122 | $js .= "\n//]]>\n</script>"; | ||
1042 | 123 | |||
1043 | 124 | return $js; | ||
1044 | 125 | }*/ | ||
1045 | 126 | } | ||
1046 | 127 | |||
1047 | 128 | class f1 extends TaF_select_queryFilter | ||
1048 | 129 | { | ||
1049 | 130 | protected $field = 'user_role'; | ||
1050 | 131 | protected $list = array(1 => 'one', 2 => 'two'); | ||
1051 | 132 | protected $value = 2; | ||
1052 | 133 | } | ||
1053 | 134 | |||
1054 | 135 | class tableTestController extends PHPDS_controller | ||
1055 | 136 | { | ||
1056 | 137 | |||
1057 | 138 | protected $params = array( | ||
1058 | 139 | 'query' => 'testTableQuery', | ||
1059 | 140 | 'showHeaders' => true | ||
1060 | 141 | ); | ||
1061 | 142 | |||
1062 | 143 | public function execute() | ||
1063 | 144 | { | ||
1064 | 145 | $t = $this->factory('testTable', $this->params); | ||
1065 | 146 | /*$t->addFilter('pagingFilter'); | ||
1066 | 147 | $t->addFilter('f1');*/ | ||
1067 | 148 | echo '<tr><td>'; | ||
1068 | 149 | echo $t->make_html(); | ||
1069 | 150 | echo '</td></tr>'; | ||
1070 | 151 | } | ||
1071 | 152 | } | ||
1072 | 153 | |||
1073 | 154 | return 'tableTestController'; | ||
1074 | 155 | |||
1075 | 156 | |||
1076 | 157 | |||
1077 | 158 | |||
1078 | 0 | 159 | ||
1079 | === added directory 'TablesAndFilters/tests' | |||
1080 | === added file 'TablesAndFilters/tests/taf.Test.php' | |||
1081 | --- TablesAndFilters/tests/taf.Test.php 1970-01-01 00:00:00 +0000 | |||
1082 | +++ TablesAndFilters/tests/taf.Test.php 2013-05-14 05:06:25 +0000 | |||
1083 | @@ -0,0 +1,82 @@ | |||
1084 | 1 | <?php | ||
1085 | 2 | |||
1086 | 3 | require_once 'mock_connector.php'; | ||
1087 | 4 | |||
1088 | 5 | require_once BASEPATH.'/plugins/TablesAndFilters/includes/TaF_table.class.php'; | ||
1089 | 6 | require_once BASEPATH.'/plugins/TablesAndFilters/includes/TaF_filteredQuery.class.php'; | ||
1090 | 7 | require_once BASEPATH.'/plugins/TablesAndFilters/includes/TaF_excerpt.class.php'; | ||
1091 | 8 | |||
1092 | 9 | class TAF_testTable extends TaF_html_filteredTable | ||
1093 | 10 | { | ||
1094 | 11 | |||
1095 | 12 | } | ||
1096 | 13 | |||
1097 | 14 | class testTableQuery extends TEST_stubQuery | ||
1098 | 15 | { | ||
1099 | 16 | |||
1100 | 17 | } | ||
1101 | 18 | |||
1102 | 19 | class TAF_tableTest extends PHPUnit_Framework_TestCase | ||
1103 | 20 | { | ||
1104 | 21 | protected $query; | ||
1105 | 22 | protected $stub; | ||
1106 | 23 | protected $table; | ||
1107 | 24 | |||
1108 | 25 | protected function setUp() | ||
1109 | 26 | { | ||
1110 | 27 | $db = PHPDSlib::instance()->my_db(); | ||
1111 | 28 | $this->query = $db->factory('TEST_stubQuery'); | ||
1112 | 29 | $this->stub = $db->factory('TEST_mock_connector'); | ||
1113 | 30 | $this->query->connector($this->stub); | ||
1114 | 31 | } | ||
1115 | 32 | |||
1116 | 33 | public function testDefaults() | ||
1117 | 34 | { | ||
1118 | 35 | $data_in = array( | ||
1119 | 36 | array('col1' => 1, 'col2' => 'one', 'col3' => false, 'col4' => 'abc'), | ||
1120 | 37 | ); | ||
1121 | 38 | $this->stub->data = $data_in; | ||
1122 | 39 | |||
1123 | 40 | $this->table = $this->query->factory('TAF_testTable'); | ||
1124 | 41 | |||
1125 | 42 | $html = $this->table->make_html(); | ||
1126 | 43 | $this->assertEquals('<div id="TAF_testTable_container" class="slidingTable"><form id="TAF_testTable_form" action="http://TEST/test.php"><table id="TAF_testTable_table" class="inside_table"></table></form></div>', $html); | ||
1127 | 44 | } | ||
1128 | 45 | |||
1129 | 46 | |||
1130 | 47 | /** | ||
1131 | 48 | * @dataProvider tableValueProvider | ||
1132 | 49 | * @group TaF | ||
1133 | 50 | */ | ||
1134 | 51 | public function testVariousData($data, $result) | ||
1135 | 52 | { | ||
1136 | 53 | $this->stub->data = $data; | ||
1137 | 54 | |||
1138 | 55 | $params = array( | ||
1139 | 56 | 'query' => $this->query, | ||
1140 | 57 | 'showHeaders' => true | ||
1141 | 58 | ); | ||
1142 | 59 | $this->table = $this->query->factory('TAF_testTable', $params); | ||
1143 | 60 | $html = $this->table->make_html(true); | ||
1144 | 61 | $this->assertEquals($result, $html); | ||
1145 | 62 | } | ||
1146 | 63 | |||
1147 | 64 | public function tableValueProvider() | ||
1148 | 65 | { | ||
1149 | 66 | return array( | ||
1150 | 67 | array( | ||
1151 | 68 | array( | ||
1152 | 69 | array('col1' => 1, 'col2' => 'one', 'col3' => false, 'col4' => 'abc'), | ||
1153 | 70 | ), | ||
1154 | 71 | '<div id="TAF_testTable_container" class="slidingTable"><form id="TAF_testTable_form" action="http://TEST/test.php"><table id="TAF_testTable_table" class="inside_table"><thead><tr class="highlight"><th class="head">col1</th><th class="head">col2</th><th class="head">col3</th><th class="head">col4</th></tr></thead><tbody><tr class="alt1"><td>1</td><td>one</td><td> </td><td>abc</td></tr></tbody></table></form></div>' | ||
1155 | 72 | ), | ||
1156 | 73 | array( | ||
1157 | 74 | array( | ||
1158 | 75 | array('col1' => 1, 'col2' => 'one', 'col3' => false, 'col4' => 'abc'), | ||
1159 | 76 | array('col1' => 2, 'col2' => 'two', 'col3' => true, 'col4' => 'def'), | ||
1160 | 77 | ), | ||
1161 | 78 | '<div id="TAF_testTable_container" class="slidingTable"><form id="TAF_testTable_form" action="http://TEST/test.php"><table id="TAF_testTable_table" class="inside_table"><thead><tr class="highlight"><th class="head">col1</th><th class="head">col2</th><th class="head">col3</th><th class="head">col4</th></tr></thead><tbody><tr class="alt1"><td>1</td><td>one</td><td> </td><td>abc</td></tr><tr class="alt1"><td>2</td><td>two</td><td>1</td><td>def</td></tr></tbody></table></form></div>' | ||
1162 | 79 | ), | ||
1163 | 80 | ); | ||
1164 | 81 | } | ||
1165 | 82 | } | ||
1166 | 0 | \ No newline at end of file | 83 | \ No newline at end of file |
1167 | 1 | 84 | ||
1168 | === added directory 'nbproject' | |||
1169 | === added directory 'nbproject/private' | |||
1170 | === added file 'nbproject/private/private.properties' | |||
1171 | --- nbproject/private/private.properties 1970-01-01 00:00:00 +0000 | |||
1172 | +++ nbproject/private/private.properties 2013-05-14 05:06:25 +0000 | |||
1173 | @@ -0,0 +1,2 @@ | |||
1174 | 1 | index.file=index.php | ||
1175 | 2 | url=http://localhost/TablesAndFilters/ | ||
1176 | 0 | 3 | ||
1177 | === added file 'nbproject/project.properties' | |||
1178 | --- nbproject/project.properties 1970-01-01 00:00:00 +0000 | |||
1179 | +++ nbproject/project.properties 2013-05-14 05:06:25 +0000 | |||
1180 | @@ -0,0 +1,7 @@ | |||
1181 | 1 | include.path=${php.global.include.path} | ||
1182 | 2 | php.version=PHP_53 | ||
1183 | 3 | source.encoding=UTF-8 | ||
1184 | 4 | src.dir=. | ||
1185 | 5 | tags.asp=false | ||
1186 | 6 | tags.short=true | ||
1187 | 7 | web.root=. | ||
1188 | 0 | 8 | ||
1189 | === added file 'nbproject/project.xml' | |||
1190 | --- nbproject/project.xml 1970-01-01 00:00:00 +0000 | |||
1191 | +++ nbproject/project.xml 2013-05-14 05:06:25 +0000 | |||
1192 | @@ -0,0 +1,9 @@ | |||
1193 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
1194 | 2 | <project xmlns="http://www.netbeans.org/ns/project/1"> | ||
1195 | 3 | <type>org.netbeans.modules.php.project</type> | ||
1196 | 4 | <configuration> | ||
1197 | 5 | <data xmlns="http://www.netbeans.org/ns/php-project/1"> | ||
1198 | 6 | <name>TablesAndFilters</name> | ||
1199 | 7 | </data> | ||
1200 | 8 | </configuration> | ||
1201 | 9 | </project> |