@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | $this->portable_hashes = $portable_hashes; |
50 | 50 | |
51 | - $this->random_state = microtime() . uniqid(mt_rand(), true); |
|
51 | + $this->random_state = microtime().uniqid(mt_rand(), true); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $output = ''; |
69 | 69 | for ($i = 0; $i < $count; $i += 16) { |
70 | 70 | $this->random_state = |
71 | - md5(microtime() . $this->random_state); |
|
71 | + md5(microtime().$this->random_state); |
|
72 | 72 | $output .= |
73 | 73 | pack('H*', md5($this->random_state)); |
74 | 74 | } |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | // consequently in lower iteration counts and hashes that are |
161 | 161 | // quicker to crack (by non-PHP code). |
162 | 162 | |
163 | - $hash = md5($salt . $password, true); |
|
163 | + $hash = md5($salt.$password, true); |
|
164 | 164 | do { |
165 | - $hash = md5($hash . $password, true); |
|
165 | + $hash = md5($hash.$password, true); |
|
166 | 166 | } while (--$count); |
167 | 167 | |
168 | 168 | $output = substr($setting, 0, 12); |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | { |
86 | 86 | global $_lang, $_style; |
87 | 87 | |
88 | - $filename = trim($view_name) . '.tpl.phtml'; |
|
89 | - $file = self::get('views_dir') . $filename; |
|
88 | + $filename = trim($view_name).'.tpl.phtml'; |
|
89 | + $file = self::get('views_dir').$filename; |
|
90 | 90 | $view = &$this; |
91 | 91 | |
92 | 92 | if (is_file($file) |
@@ -111,14 +111,14 @@ discard block |
||
111 | 111 | { |
112 | 112 | |
113 | 113 | $_update = array( |
114 | - 'id' => (int)$element_id, |
|
115 | - 'category' => (int)$category_id |
|
114 | + 'id' => (int) $element_id, |
|
115 | + 'category' => (int) $category_id |
|
116 | 116 | ); |
117 | 117 | |
118 | 118 | $this->getDatabase()->update( |
119 | 119 | $_update, |
120 | 120 | $this->db_tbl[$element], |
121 | - "`id` = '" . (int)$element_id . "'" |
|
121 | + "`id` = '".(int) $element_id."'" |
|
122 | 122 | ); |
123 | 123 | |
124 | 124 | return $this->getDatabase()->getAffectedRows() === 1; |
@@ -2,4 +2,6 @@ |
||
2 | 2 | |
3 | 3 | use Exception; |
4 | 4 | |
5 | -class ServiceNotFoundException extends Exception{} |
|
5 | +class ServiceNotFoundException extends Exception |
|
6 | +{ |
|
7 | +} |
@@ -2,4 +2,6 @@ |
||
2 | 2 | |
3 | 3 | use Exception; |
4 | 4 | |
5 | -class ContainerException extends Exception{} |
|
5 | +class ContainerException extends Exception |
|
6 | +{ |
|
7 | +} |
@@ -373,7 +373,8 @@ discard block |
||
373 | 373 | * @return bool|mixed|mysqli_result |
374 | 374 | */ |
375 | 375 | public function save($fields, $table, $where = '') |
376 | - { // This is similar to "replace into table". |
|
376 | + { |
|
377 | +// This is similar to "replace into table". |
|
377 | 378 | |
378 | 379 | if ($where === '') { |
379 | 380 | $mode = 'insert'; |
@@ -490,7 +491,7 @@ discard block |
||
490 | 491 | { |
491 | 492 | $out = false; |
492 | 493 | if ($ds instanceof mysqli_result) { |
493 | - switch($mode){ |
|
494 | + switch($mode) { |
|
494 | 495 | case 'assoc': |
495 | 496 | $out = $ds->fetch_assoc(); |
496 | 497 | break; |
@@ -225,13 +225,13 @@ discard block |
||
225 | 225 | $orderBy = trim($orderBy); |
226 | 226 | $limit = trim($limit); |
227 | 227 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
228 | - $where = "WHERE {$where}"; |
|
228 | + $where = "where {$where}"; |
|
229 | 229 | } |
230 | 230 | if ($orderBy !== '' && stripos($orderBy, 'ORDER BY') !== 0) { |
231 | 231 | $orderBy = "ORDER BY {$orderBy}"; |
232 | 232 | } |
233 | 233 | if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) { |
234 | - $limit = "LIMIT {$limit}"; |
|
234 | + $limit = "limit {$limit}"; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | $out = $this->query("DELETE FROM {$from} {$where} {$orderBy} {$limit}"); |
@@ -272,16 +272,16 @@ discard block |
||
272 | 272 | $orderBy = trim($orderBy); |
273 | 273 | $limit = trim($limit); |
274 | 274 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
275 | - $where = "WHERE {$where}"; |
|
275 | + $where = "where {$where}"; |
|
276 | 276 | } |
277 | 277 | if ($orderBy !== '' && stripos($orderBy, 'ORDER') !== 0) { |
278 | 278 | $orderBy = "ORDER BY {$orderBy}"; |
279 | 279 | } |
280 | 280 | if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) { |
281 | - $limit = "LIMIT {$limit}"; |
|
281 | + $limit = "limit {$limit}"; |
|
282 | 282 | } |
283 | 283 | |
284 | - return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderBy} {$limit}"); |
|
284 | + return $this->query("select {$fields} FROM {$from} {$where} {$orderBy} {$limit}"); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -349,10 +349,10 @@ discard block |
||
349 | 349 | $where = trim($where); |
350 | 350 | $limit = trim($limit); |
351 | 351 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
352 | - $where = "WHERE {$where}"; |
|
352 | + $where = "where {$where}"; |
|
353 | 353 | } |
354 | 354 | if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) { |
355 | - $limit = "LIMIT {$limit}"; |
|
355 | + $limit = "limit {$limit}"; |
|
356 | 356 | } |
357 | 357 | $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}"); |
358 | 358 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | - * @param null $key |
|
47 | + * @param string $key |
|
48 | 48 | * @return mixed |
49 | 49 | */ |
50 | 50 | public function getConfig($key = null) |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | |
381 | 381 | /** |
382 | 382 | * @param $fields |
383 | - * @param $table |
|
383 | + * @param string $table |
|
384 | 384 | * @param string $where |
385 | 385 | * @return bool|mixed|mysqli_result |
386 | 386 | */ |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
528 | - * @param $name |
|
528 | + * @param string $name |
|
529 | 529 | * @param mysqli_result|string $dsq |
530 | 530 | * @return array |
531 | 531 | */ |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
669 | - * @param $tbl |
|
669 | + * @param string $tbl |
|
670 | 670 | * @return string |
671 | 671 | */ |
672 | 672 | public function getFullTableName($tbl) |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $pre = null, |
34 | 34 | $charset = '', |
35 | 35 | $connection_method = 'SET CHARACTER SET' |
36 | - ) { |
|
36 | + ){ |
|
37 | 37 | $this->config['host'] = $host ? $host : $GLOBALS['database_server']; |
38 | 38 | $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase']; |
39 | 39 | $this->config['user'] = $uid ? $uid : $GLOBALS['database_user']; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $ua = $modx->getPhpCompat()->htmlspecialchars($_SERVER['HTTP_USER_AGENT']); |
83 | 83 | $referer = $modx->getPhpCompat()->htmlspecialchars($_SERVER['HTTP_REFERER']); |
84 | 84 | $modx->sendmail(array( |
85 | - 'subject' => 'Missing to create the database connection! from ' . $modx->getPhpCompat()->entities($modx->config['site_name']), |
|
85 | + 'subject' => 'Missing to create the database connection! from '.$modx->getPhpCompat()->entities($modx->config['site_name']), |
|
86 | 86 | 'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}", |
87 | 87 | 'type' => 'text' |
88 | 88 | )); |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | $tend = $modx->getMicroTime(); |
98 | 98 | $totaltime = $tend - $tstart; |
99 | 99 | if ($modx->dumpSQL) { |
100 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>" . sprintf("Database connection was created in %2.4f s", |
|
101 | - $totaltime) . "</fieldset><br />"; |
|
100 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>".sprintf("Database connection was created in %2.4f s", |
|
101 | + $totaltime)."</fieldset><br />"; |
|
102 | 102 | } |
103 | 103 | $this->conn->set_charset($this->getConfig('charset')); |
104 | 104 | $this->isConnected = true; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | if (1000 < $safeCount) { |
132 | 132 | exit("Too many loops '{$safeCount}'"); |
133 | 133 | } |
134 | - if ( ! ($this->conn instanceof mysqli)) { |
|
134 | + if (!($this->conn instanceof mysqli)) { |
|
135 | 135 | $this->connect(); |
136 | 136 | } |
137 | 137 | if (is_array($s)) { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | public function query($sql, $watchError = true) |
158 | 158 | { |
159 | 159 | $modx = evolutionCMS(); |
160 | - if ( ! ($this->conn instanceof mysqli)) { |
|
160 | + if (!($this->conn instanceof mysqli)) { |
|
161 | 161 | $this->connect(); |
162 | 162 | } |
163 | 163 | $tStart = $modx->getMicroTime(); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | case 1091: |
178 | 178 | break; |
179 | 179 | default: |
180 | - $modx->messageQuit('Execution of a query to the database failed - ' . $this->getLastError(), $sql); |
|
180 | + $modx->messageQuit('Execution of a query to the database failed - '.$this->getLastError(), $sql); |
|
181 | 181 | } |
182 | 182 | } else { |
183 | 183 | $tend = $modx->getMicroTime(); |
@@ -191,24 +191,24 @@ discard block |
||
191 | 191 | $debug_path[] = $line['function']; |
192 | 192 | } |
193 | 193 | $debug_path = implode(' > ', array_reverse($debug_path)); |
194 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", |
|
195 | - $totalTime * 1000) . "</legend>"; |
|
196 | - $modx->queryCode .= $sql . '<br><br>'; |
|
194 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query ".($modx->executedQueries + 1)." - ".sprintf("%2.2f ms", |
|
195 | + $totalTime * 1000)."</legend>"; |
|
196 | + $modx->queryCode .= $sql.'<br><br>'; |
|
197 | 197 | if ($modx->event->name) { |
198 | - $modx->queryCode .= 'Current Event => ' . $modx->event->name . '<br>'; |
|
198 | + $modx->queryCode .= 'Current Event => '.$modx->event->name.'<br>'; |
|
199 | 199 | } |
200 | 200 | if ($modx->event->activePlugin) { |
201 | - $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>'; |
|
201 | + $modx->queryCode .= 'Current Plugin => '.$modx->event->activePlugin.'<br>'; |
|
202 | 202 | } |
203 | 203 | if ($modx->currentSnippet) { |
204 | - $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>'; |
|
204 | + $modx->queryCode .= 'Current Snippet => '.$modx->currentSnippet.'<br>'; |
|
205 | 205 | } |
206 | 206 | if (stripos($sql, 'select') === 0) { |
207 | - $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>'; |
|
207 | + $modx->queryCode .= 'Record Count => '.$this->getRecordCount($result).'<br>'; |
|
208 | 208 | } else { |
209 | - $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>'; |
|
209 | + $modx->queryCode .= 'Affected Rows => '.$this->getAffectedRows().'<br>'; |
|
210 | 210 | } |
211 | - $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>'; |
|
211 | + $modx->queryCode .= 'Functions Path => '.$debug_path.'<br>'; |
|
212 | 212 | $modx->queryCode .= "</fieldset><br />"; |
213 | 213 | } |
214 | 214 | $modx->executedQueries++; |
@@ -315,9 +315,9 @@ discard block |
||
315 | 315 | if ($value === null || strtolower($value) === 'null') { |
316 | 316 | $f = 'NULL'; |
317 | 317 | } else { |
318 | - $f = "'" . $value . "'"; |
|
318 | + $f = "'".$value."'"; |
|
319 | 319 | } |
320 | - $fields[$key] = "`{$key}` = " . $f; |
|
320 | + $fields[$key] = "`{$key}` = ".$f; |
|
321 | 321 | } |
322 | 322 | $fields = implode(',', $fields); |
323 | 323 | } |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | $this->query("INSERT INTO {$intotable} {$fields}"); |
353 | 353 | } else { |
354 | 354 | if (empty($fromtable)) { |
355 | - $fields = "(`" . implode("`, `", array_keys($fields)) . "`) VALUES('" . implode("', '", |
|
356 | - array_values($fields)) . "')"; |
|
355 | + $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", |
|
356 | + array_values($fields))."')"; |
|
357 | 357 | $this->query("INSERT INTO {$intotable} {$fields}"); |
358 | 358 | } else { |
359 | 359 | $fromtable = $this->replaceFullTableName($fromtable); |
360 | - $fields = "(" . implode(",", array_keys($fields)) . ")"; |
|
360 | + $fields = "(".implode(",", array_keys($fields)).")"; |
|
361 | 361 | $where = trim($where); |
362 | 362 | $limit = trim($limit); |
363 | 363 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | */ |
452 | 452 | public function getInsertId($conn = null) |
453 | 453 | { |
454 | - if (! ($conn instanceof mysqli)) { |
|
455 | - $conn =& $this->conn; |
|
454 | + if (!($conn instanceof mysqli)) { |
|
455 | + $conn = & $this->conn; |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | return $conn->insert_id; |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | */ |
465 | 465 | public function getAffectedRows($conn = null) |
466 | 466 | { |
467 | - if (! ($conn instanceof mysqli)) { |
|
468 | - $conn =& $this->conn; |
|
467 | + if (!($conn instanceof mysqli)) { |
|
468 | + $conn = & $this->conn; |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | return $conn->affected_rows; |
@@ -477,8 +477,8 @@ discard block |
||
477 | 477 | */ |
478 | 478 | public function getLastError($conn = null) |
479 | 479 | { |
480 | - if (! ($conn instanceof mysqli)) { |
|
481 | - $conn =& $this->conn; |
|
480 | + if (!($conn instanceof mysqli)) { |
|
481 | + $conn = & $this->conn; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | return $conn->error; |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | { |
503 | 503 | $out = false; |
504 | 504 | if ($ds instanceof mysqli_result) { |
505 | - switch($mode){ |
|
505 | + switch ($mode) { |
|
506 | 506 | case 'assoc': |
507 | 507 | $out = $ds->fetch_assoc(); |
508 | 508 | break; |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | public function getColumn($name, $dsq) |
533 | 533 | { |
534 | 534 | $col = array(); |
535 | - if ( ! ($dsq instanceof mysqli_result)) { |
|
535 | + if (!($dsq instanceof mysqli_result)) { |
|
536 | 536 | $dsq = $this->query($dsq); |
537 | 537 | } |
538 | 538 | if ($dsq) { |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | public function getColumnNames($dsq) |
552 | 552 | { |
553 | 553 | $names = array(); |
554 | - if ( ! ($dsq instanceof mysqli_result)) { |
|
554 | + if (!($dsq instanceof mysqli_result)) { |
|
555 | 555 | $dsq = $this->query($dsq); |
556 | 556 | } |
557 | 557 | if ($dsq) { |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | public function getValue($dsq) |
572 | 572 | { |
573 | 573 | $out = false; |
574 | - if ( ! ($dsq instanceof mysqli_result)) { |
|
574 | + if (!($dsq instanceof mysqli_result)) { |
|
575 | 575 | $dsq = $this->query($dsq); |
576 | 576 | } |
577 | 577 | if ($dsq) { |
@@ -661,8 +661,8 @@ discard block |
||
661 | 661 | |
662 | 662 | public function getTableName($table, $escape = true) |
663 | 663 | { |
664 | - $out = $this->getConfig('table_prefix') . $table; |
|
665 | - return $escape ? '`' . $out . '`' : $out; |
|
664 | + $out = $this->getConfig('table_prefix').$table; |
|
665 | + return $escape ? '`'.$out.'`' : $out; |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | */ |
672 | 672 | public function getFullTableName($tbl) |
673 | 673 | { |
674 | - return $this->getConfig('dbase') . "." . $this->getTableName($tbl); |
|
674 | + return $this->getConfig('dbase').".".$this->getTableName($tbl); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | /** |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | $tableName = trim($tableName); |
685 | 685 | $dbase = trim($this->getConfig('dbase'), '`'); |
686 | 686 | $prefix = $this->getConfig('table_prefix'); |
687 | - if ((bool)$force === true) { |
|
687 | + if ((bool) $force === true) { |
|
688 | 688 | $result = "`{$dbase}`.`{$prefix}{$tableName}`"; |
689 | 689 | } elseif (strpos($tableName, '[+prefix+]') !== false) { |
690 | 690 | $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $tableName); |
@@ -1,3 +1,5 @@ |
||
1 | 1 | <?php namespace EvolutionCMS\Interfaces; |
2 | 2 | |
3 | -interface ManagerApiInterface{} |
|
3 | +interface ManagerApiInterface |
|
4 | +{ |
|
5 | +} |
@@ -1,3 +1,5 @@ |
||
1 | 1 | <?php namespace EvolutionCMS\Interfaces; |
2 | 2 | |
3 | -interface ServiceProviderInterface{} |
|
3 | +interface ServiceProviderInterface |
|
4 | +{ |
|
5 | +} |
@@ -1,3 +1,5 @@ |
||
1 | 1 | <?php namespace EvolutionCMS\Interfaces; |
2 | 2 | |
3 | -interface PasswordHashInterface{} |
|
3 | +interface PasswordHashInterface |
|
4 | +{ |
|
5 | +} |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | class DataGrid implements DataGridInterface{ |
15 | 15 | |
16 | - public $ds; // datasource |
|
16 | + public $ds; // datasource |
|
17 | 17 | public $id; |
18 | 18 | public $pageSize; // pager settings |
19 | 19 | public $pageNumber; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public $colWraps; |
38 | 38 | public $colColors; |
39 | 39 | public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m |
40 | - // data type: integer,float,currency,date |
|
40 | + // data type: integer,float,currency,date |
|
41 | 41 | |
42 | 42 | public $header; |
43 | 43 | public $footer; |
@@ -76,236 +76,236 @@ discard block |
||
76 | 76 | public static $dataGridCnt; |
77 | 77 | |
78 | 78 | public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
79 | - // set id |
|
80 | - self::$dataGridCnt++; |
|
81 | - $this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt; |
|
79 | + // set id |
|
80 | + self::$dataGridCnt++; |
|
81 | + $this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt; |
|
82 | 82 | |
83 | - // set datasource |
|
84 | - $this->ds = $ds; |
|
83 | + // set datasource |
|
84 | + $this->ds = $ds; |
|
85 | 85 | |
86 | - // set pager |
|
87 | - $this->pageSize = $pageSize; |
|
88 | - $this->pageNumber = $pageNumber; // by setting pager to -1 will cause pager to load it's last page number |
|
89 | - $this->pagerLocation = 'top-right'; |
|
90 | - } |
|
86 | + // set pager |
|
87 | + $this->pageSize = $pageSize; |
|
88 | + $this->pageNumber = $pageNumber; // by setting pager to -1 will cause pager to load it's last page number |
|
89 | + $this->pagerLocation = 'top-right'; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | public function setDataSource($ds) { |
93 | - $this->ds = $ds; |
|
94 | - } |
|
93 | + $this->ds = $ds; |
|
94 | + } |
|
95 | 95 | |
96 | 96 | public function render() { |
97 | 97 | $modx = evolutionCMS(); |
98 | - $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
|
99 | - $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
|
100 | - $cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : ''; |
|
101 | - $cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : ''; |
|
102 | - |
|
103 | - $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : ''; |
|
104 | - $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'"; |
|
105 | - |
|
106 | - $this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : ''; |
|
107 | - $this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : ''; |
|
108 | - $this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : ''; |
|
109 | - $this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : ''; |
|
110 | - |
|
111 | - $this->_alt = 0; |
|
112 | - $this->_total = 0; |
|
113 | - |
|
114 | - $this->_isDataset = $modx->getDatabase()->isResult($this->ds); // if not dataset then treat as array |
|
115 | - |
|
116 | - if(!$cssStyle && !$cssClass) { |
|
117 | - $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'"; |
|
118 | - } |
|
119 | - if(!$columnHeaderStyle && !$columnHeaderClass) { |
|
120 | - $columnHeaderStyle = "style='color:black;background-color:silver'"; |
|
121 | - } |
|
122 | - if(!$this->_itemStyle && !$this->_itemClass) { |
|
123 | - $this->_itemStyle = "style='color:black;'"; |
|
124 | - } |
|
125 | - if(!$this->_altItemStyle && !$this->_altItemClass) { |
|
126 | - $this->_altItemStyle = "style='color:black;background-color:#eeeeee'"; |
|
127 | - } |
|
128 | - |
|
129 | - if($this->_isDataset && !$this->columns) { |
|
130 | - $cols = $modx->getDatabase()->numFields($this->ds); |
|
131 | - for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
132 | - } |
|
133 | - |
|
134 | - // start grid |
|
135 | - $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>"; |
|
136 | - $tblEnd = "</table>"; |
|
137 | - |
|
138 | - // build column header |
|
139 | - $this->_colnames = explode((strstr($this->columns, "||") !== false ? "||" : ","), $this->columns); |
|
140 | - $this->_colwidths = explode((strstr($this->colWidths, "||") !== false ? "||" : ","), $this->colWidths); |
|
141 | - $this->_colaligns = explode((strstr($this->colAligns, "||") !== false ? "||" : ","), $this->colAligns); |
|
142 | - $this->_colwraps = explode((strstr($this->colWraps, "||") !== false ? "||" : ","), $this->colWraps); |
|
143 | - $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors); |
|
144 | - $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes); |
|
145 | - $this->_colcount = count($this->_colnames); |
|
146 | - if(!$this->_isDataset) { |
|
147 | - $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds); |
|
148 | - $this->ds = array_chunk($this->ds, $this->_colcount); |
|
149 | - } |
|
150 | - $tblColHdr = "<thead><tr>"; |
|
151 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
152 | - $name = $this->_colnames[$c]; |
|
153 | - $width = $this->_colwidths[$c]; |
|
154 | - $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>"; |
|
155 | - } |
|
156 | - $tblColHdr .= "</tr></thead>\n"; |
|
157 | - |
|
158 | - // build rows |
|
159 | - $rowcount = $this->_isDataset ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds); |
|
160 | - $this->_fieldnames = explode(",", $this->fields); |
|
161 | - if($rowcount == 0) { |
|
162 | - $tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n"; |
|
163 | - } else { |
|
164 | - // render grid items |
|
165 | - if($this->pageSize <= 0) { |
|
166 | - for($r = 0; $r < $rowcount; $r++) { |
|
167 | - $row = $this->_isDataset ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$r]; |
|
168 | - $tblRows .= $this->RenderRowFnc($r + 1, $row); |
|
169 | - } |
|
170 | - } else { |
|
171 | - if(!$this->pager) { |
|
172 | - $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber); |
|
173 | - $this->pager->setRenderRowFnc($this); // pass this object |
|
174 | - $this->pager->cssStyle = $pagerStyle; |
|
175 | - $this->pager->cssClass = $pagerClass; |
|
176 | - } else { |
|
177 | - $this->pager->pageSize = $this->pageSize; |
|
178 | - $this->pager->pageNumber = $this->pageNumber; |
|
179 | - } |
|
180 | - |
|
181 | - $this->pager->render(); |
|
182 | - $tblRows = $this->pager->getRenderedRows(); |
|
183 | - $tblPager = $this->pager->getRenderedPager(); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - // setup header,pager and footer |
|
188 | - $o = $tblStart; |
|
189 | - $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
190 | - $pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
191 | - if($this->header) { |
|
192 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>"; |
|
193 | - } |
|
194 | - if($tblPager && $ptop) { |
|
195 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
196 | - } |
|
197 | - $o .= $tblColHdr . $tblRows; |
|
198 | - if($tblPager && $pbot) { |
|
199 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
200 | - } |
|
201 | - if($this->footer) { |
|
202 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>"; |
|
203 | - } |
|
204 | - $o .= $tblEnd; |
|
205 | - return $o; |
|
206 | - } |
|
207 | - |
|
208 | - // format column values |
|
98 | + $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
|
99 | + $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
|
100 | + $cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : ''; |
|
101 | + $cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : ''; |
|
102 | + |
|
103 | + $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : ''; |
|
104 | + $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'"; |
|
105 | + |
|
106 | + $this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : ''; |
|
107 | + $this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : ''; |
|
108 | + $this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : ''; |
|
109 | + $this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : ''; |
|
110 | + |
|
111 | + $this->_alt = 0; |
|
112 | + $this->_total = 0; |
|
113 | + |
|
114 | + $this->_isDataset = $modx->getDatabase()->isResult($this->ds); // if not dataset then treat as array |
|
115 | + |
|
116 | + if(!$cssStyle && !$cssClass) { |
|
117 | + $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'"; |
|
118 | + } |
|
119 | + if(!$columnHeaderStyle && !$columnHeaderClass) { |
|
120 | + $columnHeaderStyle = "style='color:black;background-color:silver'"; |
|
121 | + } |
|
122 | + if(!$this->_itemStyle && !$this->_itemClass) { |
|
123 | + $this->_itemStyle = "style='color:black;'"; |
|
124 | + } |
|
125 | + if(!$this->_altItemStyle && !$this->_altItemClass) { |
|
126 | + $this->_altItemStyle = "style='color:black;background-color:#eeeeee'"; |
|
127 | + } |
|
128 | + |
|
129 | + if($this->_isDataset && !$this->columns) { |
|
130 | + $cols = $modx->getDatabase()->numFields($this->ds); |
|
131 | + for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
132 | + } |
|
133 | + |
|
134 | + // start grid |
|
135 | + $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>"; |
|
136 | + $tblEnd = "</table>"; |
|
137 | + |
|
138 | + // build column header |
|
139 | + $this->_colnames = explode((strstr($this->columns, "||") !== false ? "||" : ","), $this->columns); |
|
140 | + $this->_colwidths = explode((strstr($this->colWidths, "||") !== false ? "||" : ","), $this->colWidths); |
|
141 | + $this->_colaligns = explode((strstr($this->colAligns, "||") !== false ? "||" : ","), $this->colAligns); |
|
142 | + $this->_colwraps = explode((strstr($this->colWraps, "||") !== false ? "||" : ","), $this->colWraps); |
|
143 | + $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors); |
|
144 | + $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes); |
|
145 | + $this->_colcount = count($this->_colnames); |
|
146 | + if(!$this->_isDataset) { |
|
147 | + $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds); |
|
148 | + $this->ds = array_chunk($this->ds, $this->_colcount); |
|
149 | + } |
|
150 | + $tblColHdr = "<thead><tr>"; |
|
151 | + for($c = 0; $c < $this->_colcount; $c++) { |
|
152 | + $name = $this->_colnames[$c]; |
|
153 | + $width = $this->_colwidths[$c]; |
|
154 | + $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>"; |
|
155 | + } |
|
156 | + $tblColHdr .= "</tr></thead>\n"; |
|
157 | + |
|
158 | + // build rows |
|
159 | + $rowcount = $this->_isDataset ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds); |
|
160 | + $this->_fieldnames = explode(",", $this->fields); |
|
161 | + if($rowcount == 0) { |
|
162 | + $tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n"; |
|
163 | + } else { |
|
164 | + // render grid items |
|
165 | + if($this->pageSize <= 0) { |
|
166 | + for($r = 0; $r < $rowcount; $r++) { |
|
167 | + $row = $this->_isDataset ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$r]; |
|
168 | + $tblRows .= $this->RenderRowFnc($r + 1, $row); |
|
169 | + } |
|
170 | + } else { |
|
171 | + if(!$this->pager) { |
|
172 | + $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber); |
|
173 | + $this->pager->setRenderRowFnc($this); // pass this object |
|
174 | + $this->pager->cssStyle = $pagerStyle; |
|
175 | + $this->pager->cssClass = $pagerClass; |
|
176 | + } else { |
|
177 | + $this->pager->pageSize = $this->pageSize; |
|
178 | + $this->pager->pageNumber = $this->pageNumber; |
|
179 | + } |
|
180 | + |
|
181 | + $this->pager->render(); |
|
182 | + $tblRows = $this->pager->getRenderedRows(); |
|
183 | + $tblPager = $this->pager->getRenderedPager(); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + // setup header,pager and footer |
|
188 | + $o = $tblStart; |
|
189 | + $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
190 | + $pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
191 | + if($this->header) { |
|
192 | + $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>"; |
|
193 | + } |
|
194 | + if($tblPager && $ptop) { |
|
195 | + $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
196 | + } |
|
197 | + $o .= $tblColHdr . $tblRows; |
|
198 | + if($tblPager && $pbot) { |
|
199 | + $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
200 | + } |
|
201 | + if($this->footer) { |
|
202 | + $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>"; |
|
203 | + } |
|
204 | + $o .= $tblEnd; |
|
205 | + return $o; |
|
206 | + } |
|
207 | + |
|
208 | + // format column values |
|
209 | 209 | |
210 | 210 | public function RenderRowFnc($n, $row) { |
211 | - if($this->_alt == 0) { |
|
212 | - $Style = $this->_itemStyle; |
|
213 | - $Class = $this->_itemClass; |
|
214 | - $this->_alt = 1; |
|
215 | - } else { |
|
216 | - $Style = $this->_altItemStyle; |
|
217 | - $Class = $this->_altItemClass; |
|
218 | - $this->_alt = 0; |
|
219 | - } |
|
220 | - $o = "<tr>"; |
|
221 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
222 | - $colStyle = $Style; |
|
223 | - $fld = trim($this->_fieldnames[$c]); |
|
224 | - $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null; |
|
225 | - $align = isset($this->_colaligns[$c]) ? $this->_colaligns[$c] : null; |
|
226 | - $color = isset($this->_colcolors[$c]) ? $this->_colcolors[$c] : null; |
|
227 | - $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null; |
|
228 | - $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null; |
|
229 | - $value = $row[($this->_isDataset && $fld ? $fld : $c)]; |
|
230 | - if($color && $Style) { |
|
231 | - $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'"; |
|
232 | - } |
|
233 | - $value = $this->formatColumnValue($row, $value, $type, $align); |
|
234 | - $o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>"; |
|
235 | - } |
|
236 | - $o .= "</tr>\n"; |
|
237 | - return $o; |
|
238 | - } |
|
211 | + if($this->_alt == 0) { |
|
212 | + $Style = $this->_itemStyle; |
|
213 | + $Class = $this->_itemClass; |
|
214 | + $this->_alt = 1; |
|
215 | + } else { |
|
216 | + $Style = $this->_altItemStyle; |
|
217 | + $Class = $this->_altItemClass; |
|
218 | + $this->_alt = 0; |
|
219 | + } |
|
220 | + $o = "<tr>"; |
|
221 | + for($c = 0; $c < $this->_colcount; $c++) { |
|
222 | + $colStyle = $Style; |
|
223 | + $fld = trim($this->_fieldnames[$c]); |
|
224 | + $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null; |
|
225 | + $align = isset($this->_colaligns[$c]) ? $this->_colaligns[$c] : null; |
|
226 | + $color = isset($this->_colcolors[$c]) ? $this->_colcolors[$c] : null; |
|
227 | + $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null; |
|
228 | + $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null; |
|
229 | + $value = $row[($this->_isDataset && $fld ? $fld : $c)]; |
|
230 | + if($color && $Style) { |
|
231 | + $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'"; |
|
232 | + } |
|
233 | + $value = $this->formatColumnValue($row, $value, $type, $align); |
|
234 | + $o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>"; |
|
235 | + } |
|
236 | + $o .= "</tr>\n"; |
|
237 | + return $o; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | public function formatColumnValue($row, $value, $type, &$align) { |
241 | - if(strpos($type, ":") !== false) { |
|
242 | - list($type, $type_format) = explode(":", $type, 2); |
|
243 | - } |
|
244 | - switch(strtolower($type)) { |
|
245 | - case "integer": |
|
246 | - if($align == "") { |
|
247 | - $align = "right"; |
|
248 | - } |
|
249 | - $value = number_format($value); |
|
250 | - break; |
|
251 | - |
|
252 | - case "float": |
|
253 | - if($align == "") { |
|
254 | - $align = "right"; |
|
255 | - } |
|
256 | - if(!$type_format) { |
|
257 | - $type_format = 2; |
|
258 | - } |
|
259 | - $value = number_format($value, $type_format); |
|
260 | - break; |
|
261 | - |
|
262 | - case "currency": |
|
263 | - if($align == "") { |
|
264 | - $align = "right"; |
|
265 | - } |
|
266 | - if(!$type_format) { |
|
267 | - $type_format = 2; |
|
268 | - } |
|
269 | - $value = "$" . number_format($value, $type_format); |
|
270 | - break; |
|
271 | - |
|
272 | - case "date": |
|
273 | - if($align == "") { |
|
274 | - $align = "right"; |
|
275 | - } |
|
276 | - if(!is_numeric($value)) { |
|
277 | - $value = strtotime($value); |
|
278 | - } |
|
279 | - if(!$type_format) { |
|
280 | - $type_format = "%A %d, %B %Y"; |
|
281 | - } |
|
282 | - $value = strftime($type_format, $value); |
|
283 | - break; |
|
284 | - |
|
285 | - case "boolean": |
|
286 | - if($align == '') { |
|
287 | - $align = "center"; |
|
288 | - } |
|
289 | - $value = number_format($value); |
|
290 | - if($value) { |
|
291 | - $value = '•'; |
|
292 | - } else { |
|
293 | - $value = ' '; |
|
294 | - } |
|
295 | - break; |
|
296 | - |
|
297 | - case "template": |
|
298 | - // replace [+value+] first |
|
299 | - $value = str_replace("[+value+]", $value, $type_format); |
|
300 | - // replace other [+fields+] |
|
301 | - if(strpos($value, "[+") !== false) { |
|
302 | - foreach($row as $k => $v) { |
|
303 | - $value = str_replace("[+$k+]", $v, $value); |
|
304 | - } |
|
305 | - } |
|
306 | - break; |
|
307 | - |
|
308 | - } |
|
309 | - return $value; |
|
310 | - } |
|
241 | + if(strpos($type, ":") !== false) { |
|
242 | + list($type, $type_format) = explode(":", $type, 2); |
|
243 | + } |
|
244 | + switch(strtolower($type)) { |
|
245 | + case "integer": |
|
246 | + if($align == "") { |
|
247 | + $align = "right"; |
|
248 | + } |
|
249 | + $value = number_format($value); |
|
250 | + break; |
|
251 | + |
|
252 | + case "float": |
|
253 | + if($align == "") { |
|
254 | + $align = "right"; |
|
255 | + } |
|
256 | + if(!$type_format) { |
|
257 | + $type_format = 2; |
|
258 | + } |
|
259 | + $value = number_format($value, $type_format); |
|
260 | + break; |
|
261 | + |
|
262 | + case "currency": |
|
263 | + if($align == "") { |
|
264 | + $align = "right"; |
|
265 | + } |
|
266 | + if(!$type_format) { |
|
267 | + $type_format = 2; |
|
268 | + } |
|
269 | + $value = "$" . number_format($value, $type_format); |
|
270 | + break; |
|
271 | + |
|
272 | + case "date": |
|
273 | + if($align == "") { |
|
274 | + $align = "right"; |
|
275 | + } |
|
276 | + if(!is_numeric($value)) { |
|
277 | + $value = strtotime($value); |
|
278 | + } |
|
279 | + if(!$type_format) { |
|
280 | + $type_format = "%A %d, %B %Y"; |
|
281 | + } |
|
282 | + $value = strftime($type_format, $value); |
|
283 | + break; |
|
284 | + |
|
285 | + case "boolean": |
|
286 | + if($align == '') { |
|
287 | + $align = "center"; |
|
288 | + } |
|
289 | + $value = number_format($value); |
|
290 | + if($value) { |
|
291 | + $value = '•'; |
|
292 | + } else { |
|
293 | + $value = ' '; |
|
294 | + } |
|
295 | + break; |
|
296 | + |
|
297 | + case "template": |
|
298 | + // replace [+value+] first |
|
299 | + $value = str_replace("[+value+]", $value, $type_format); |
|
300 | + // replace other [+fields+] |
|
301 | + if(strpos($value, "[+") !== false) { |
|
302 | + foreach($row as $k => $v) { |
|
303 | + $value = str_replace("[+$k+]", $v, $value); |
|
304 | + } |
|
305 | + } |
|
306 | + break; |
|
307 | + |
|
308 | + } |
|
309 | + return $value; |
|
310 | + } |
|
311 | 311 | } |
@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | |
16 | 16 | public $ds; // datasource |
17 | 17 | public $id; |
18 | - public $pageSize; // pager settings |
|
18 | + public $pageSize; // pager settings |
|
19 | 19 | public $pageNumber; |
20 | 20 | public $pager; |
21 | - public $pagerLocation; // top-right, top-left, bottom-left, bottom-right, both-left, both-right |
|
21 | + public $pagerLocation; // top-right, top-left, bottom-left, bottom-right, both-left, both-right |
|
22 | 22 | |
23 | 23 | public $cssStyle; |
24 | 24 | public $cssClass; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public $colAligns; |
37 | 37 | public $colWraps; |
38 | 38 | public $colColors; |
39 | - public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m |
|
39 | + public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m |
|
40 | 40 | // data type: integer,float,currency,date |
41 | 41 | |
42 | 42 | public $header; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public $cellPadding; |
45 | 45 | public $cellSpacing; |
46 | 46 | |
47 | - public $rowAlign; // vertical alignment: top, middle, bottom |
|
47 | + public $rowAlign; // vertical alignment: top, middle, bottom |
|
48 | 48 | public $rowIdField; |
49 | 49 | |
50 | 50 | public $pagerStyle; |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | |
76 | 76 | public static $dataGridCnt; |
77 | 77 | |
78 | - public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
|
78 | + public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1){ |
|
79 | 79 | // set id |
80 | 80 | self::$dataGridCnt++; |
81 | - $this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt; |
|
81 | + $this->id = $this->id ? empty($id) : "dg".self::$dataGridCnt; |
|
82 | 82 | |
83 | 83 | // set datasource |
84 | 84 | $this->ds = $ds; |
@@ -89,50 +89,50 @@ discard block |
||
89 | 89 | $this->pagerLocation = 'top-right'; |
90 | 90 | } |
91 | 91 | |
92 | - public function setDataSource($ds) { |
|
92 | + public function setDataSource($ds){ |
|
93 | 93 | $this->ds = $ds; |
94 | 94 | } |
95 | 95 | |
96 | - public function render() { |
|
96 | + public function render(){ |
|
97 | 97 | $modx = evolutionCMS(); |
98 | - $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
|
99 | - $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
|
100 | - $cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : ''; |
|
101 | - $cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : ''; |
|
98 | + $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='".$this->columnHeaderStyle."'" : ''; |
|
99 | + $columnHeaderClass = ($this->columnHeaderClass) ? "class='".$this->columnHeaderClass."'" : ""; |
|
100 | + $cssStyle = ($this->cssStyle) ? "style='".$this->cssStyle."'" : ''; |
|
101 | + $cssClass = ($this->cssClass) ? "class='".$this->cssClass."'" : ''; |
|
102 | 102 | |
103 | - $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : ''; |
|
104 | - $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'"; |
|
103 | + $pagerClass = ($this->pagerClass) ? "class='".$this->pagerClass."'" : ''; |
|
104 | + $pagerStyle = ($this->pagerStyle) ? "style='".$this->pagerStyle."'" : "style='background-color:#ffffff;'"; |
|
105 | 105 | |
106 | - $this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : ''; |
|
107 | - $this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : ''; |
|
108 | - $this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : ''; |
|
109 | - $this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : ''; |
|
106 | + $this->_itemStyle = ($this->itemStyle) ? "style='".$this->itemStyle."'" : ''; |
|
107 | + $this->_itemClass = ($this->itemClass) ? "class='".$this->itemClass."'" : ''; |
|
108 | + $this->_altItemStyle = ($this->altItemStyle) ? "style='".$this->altItemStyle."'" : ''; |
|
109 | + $this->_altItemClass = ($this->altItemClass) ? "class='".$this->altItemClass."'" : ''; |
|
110 | 110 | |
111 | 111 | $this->_alt = 0; |
112 | 112 | $this->_total = 0; |
113 | 113 | |
114 | 114 | $this->_isDataset = $modx->getDatabase()->isResult($this->ds); // if not dataset then treat as array |
115 | 115 | |
116 | - if(!$cssStyle && !$cssClass) { |
|
116 | + if (!$cssStyle && !$cssClass) { |
|
117 | 117 | $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'"; |
118 | 118 | } |
119 | - if(!$columnHeaderStyle && !$columnHeaderClass) { |
|
119 | + if (!$columnHeaderStyle && !$columnHeaderClass) { |
|
120 | 120 | $columnHeaderStyle = "style='color:black;background-color:silver'"; |
121 | 121 | } |
122 | - if(!$this->_itemStyle && !$this->_itemClass) { |
|
122 | + if (!$this->_itemStyle && !$this->_itemClass) { |
|
123 | 123 | $this->_itemStyle = "style='color:black;'"; |
124 | 124 | } |
125 | - if(!$this->_altItemStyle && !$this->_altItemClass) { |
|
125 | + if (!$this->_altItemStyle && !$this->_altItemClass) { |
|
126 | 126 | $this->_altItemStyle = "style='color:black;background-color:#eeeeee'"; |
127 | 127 | } |
128 | 128 | |
129 | - if($this->_isDataset && !$this->columns) { |
|
129 | + if ($this->_isDataset && !$this->columns) { |
|
130 | 130 | $cols = $modx->getDatabase()->numFields($this->ds); |
131 | - for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
131 | + for ($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "").$modx->getDatabase()->fieldName($this->ds, $i); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // start grid |
135 | - $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>"; |
|
135 | + $tblStart = "<table $cssClass $cssStyle cellpadding='".(isset($this->cellPadding) ? (int) $this->cellPadding : 1)."' cellspacing='".(isset($this->cellSpacing) ? (int) $this->cellSpacing : 1)."'>"; |
|
136 | 136 | $tblEnd = "</table>"; |
137 | 137 | |
138 | 138 | // build column header |
@@ -143,32 +143,32 @@ discard block |
||
143 | 143 | $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors); |
144 | 144 | $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes); |
145 | 145 | $this->_colcount = count($this->_colnames); |
146 | - if(!$this->_isDataset) { |
|
146 | + if (!$this->_isDataset) { |
|
147 | 147 | $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds); |
148 | 148 | $this->ds = array_chunk($this->ds, $this->_colcount); |
149 | 149 | } |
150 | 150 | $tblColHdr = "<thead><tr>"; |
151 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
151 | + for ($c = 0; $c < $this->_colcount; $c++) { |
|
152 | 152 | $name = $this->_colnames[$c]; |
153 | 153 | $width = $this->_colwidths[$c]; |
154 | - $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>"; |
|
154 | + $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass".($width ? " width='$width'" : "").">$name</td>"; |
|
155 | 155 | } |
156 | 156 | $tblColHdr .= "</tr></thead>\n"; |
157 | 157 | |
158 | 158 | // build rows |
159 | 159 | $rowcount = $this->_isDataset ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds); |
160 | 160 | $this->_fieldnames = explode(",", $this->fields); |
161 | - if($rowcount == 0) { |
|
162 | - $tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n"; |
|
161 | + if ($rowcount == 0) { |
|
162 | + $tblRows .= "<tr><td ".$this->_itemStyle." ".$this->_itemClass." colspan='".$this->_colcount."'>".$this->noRecordMsg."</td></tr>\n"; |
|
163 | 163 | } else { |
164 | 164 | // render grid items |
165 | - if($this->pageSize <= 0) { |
|
166 | - for($r = 0; $r < $rowcount; $r++) { |
|
165 | + if ($this->pageSize <= 0) { |
|
166 | + for ($r = 0; $r < $rowcount; $r++) { |
|
167 | 167 | $row = $this->_isDataset ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$r]; |
168 | 168 | $tblRows .= $this->RenderRowFnc($r + 1, $row); |
169 | 169 | } |
170 | 170 | } else { |
171 | - if(!$this->pager) { |
|
171 | + if (!$this->pager) { |
|
172 | 172 | $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber); |
173 | 173 | $this->pager->setRenderRowFnc($this); // pass this object |
174 | 174 | $this->pager->cssStyle = $pagerStyle; |
@@ -188,18 +188,18 @@ discard block |
||
188 | 188 | $o = $tblStart; |
189 | 189 | $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both"); |
190 | 190 | $pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both"); |
191 | - if($this->header) { |
|
192 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>"; |
|
191 | + if ($this->header) { |
|
192 | + $o .= "<tr><td bgcolor='#ffffff' colspan='".$this->_colcount."'>".$this->header."</td></tr>"; |
|
193 | 193 | } |
194 | - if($tblPager && $ptop) { |
|
195 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
194 | + if ($tblPager && $ptop) { |
|
195 | + $o .= "<tr><td align='".(substr($this->pagerLocation, -4) == "left" ? "left" : "right")."' $pagerClass $pagerStyle colspan='".$this->_colcount."'>".$tblPager." </td></tr>"; |
|
196 | 196 | } |
197 | - $o .= $tblColHdr . $tblRows; |
|
198 | - if($tblPager && $pbot) { |
|
199 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
197 | + $o .= $tblColHdr.$tblRows; |
|
198 | + if ($tblPager && $pbot) { |
|
199 | + $o .= "<tr><td align='".(substr($this->pagerLocation, -4) == "left" ? "left" : "right")."' $pagerClass $pagerStyle colspan='".$this->_colcount."'>".$tblPager." </td></tr>"; |
|
200 | 200 | } |
201 | - if($this->footer) { |
|
202 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>"; |
|
201 | + if ($this->footer) { |
|
202 | + $o .= "<tr><td bgcolor='#ffffff' colspan='".$this->_colcount."'>".$this->footer."</td></tr>"; |
|
203 | 203 | } |
204 | 204 | $o .= $tblEnd; |
205 | 205 | return $o; |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | |
208 | 208 | // format column values |
209 | 209 | |
210 | - public function RenderRowFnc($n, $row) { |
|
211 | - if($this->_alt == 0) { |
|
210 | + public function RenderRowFnc($n, $row){ |
|
211 | + if ($this->_alt == 0) { |
|
212 | 212 | $Style = $this->_itemStyle; |
213 | 213 | $Class = $this->_itemClass; |
214 | 214 | $this->_alt = 1; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $this->_alt = 0; |
219 | 219 | } |
220 | 220 | $o = "<tr>"; |
221 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
221 | + for ($c = 0; $c < $this->_colcount; $c++) { |
|
222 | 222 | $colStyle = $Style; |
223 | 223 | $fld = trim($this->_fieldnames[$c]); |
224 | 224 | $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null; |
@@ -227,67 +227,67 @@ discard block |
||
227 | 227 | $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null; |
228 | 228 | $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null; |
229 | 229 | $value = $row[($this->_isDataset && $fld ? $fld : $c)]; |
230 | - if($color && $Style) { |
|
231 | - $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'"; |
|
230 | + if ($color && $Style) { |
|
231 | + $colStyle = substr($colStyle, 0, -1).";background-color:$color;'"; |
|
232 | 232 | } |
233 | 233 | $value = $this->formatColumnValue($row, $value, $type, $align); |
234 | - $o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>"; |
|
234 | + $o .= "<td $colStyle $Class".($align ? " align='$align'" : "").($color ? " bgcolor='$color'" : "").($nowrap ? " nowrap='$nowrap'" : "").($width ? " width='$width'" : "").">$value</td>"; |
|
235 | 235 | } |
236 | 236 | $o .= "</tr>\n"; |
237 | 237 | return $o; |
238 | 238 | } |
239 | 239 | |
240 | - public function formatColumnValue($row, $value, $type, &$align) { |
|
241 | - if(strpos($type, ":") !== false) { |
|
240 | + public function formatColumnValue($row, $value, $type, &$align){ |
|
241 | + if (strpos($type, ":") !== false) { |
|
242 | 242 | list($type, $type_format) = explode(":", $type, 2); |
243 | 243 | } |
244 | - switch(strtolower($type)) { |
|
244 | + switch (strtolower($type)) { |
|
245 | 245 | case "integer": |
246 | - if($align == "") { |
|
246 | + if ($align == "") { |
|
247 | 247 | $align = "right"; |
248 | 248 | } |
249 | 249 | $value = number_format($value); |
250 | 250 | break; |
251 | 251 | |
252 | 252 | case "float": |
253 | - if($align == "") { |
|
253 | + if ($align == "") { |
|
254 | 254 | $align = "right"; |
255 | 255 | } |
256 | - if(!$type_format) { |
|
256 | + if (!$type_format) { |
|
257 | 257 | $type_format = 2; |
258 | 258 | } |
259 | 259 | $value = number_format($value, $type_format); |
260 | 260 | break; |
261 | 261 | |
262 | 262 | case "currency": |
263 | - if($align == "") { |
|
263 | + if ($align == "") { |
|
264 | 264 | $align = "right"; |
265 | 265 | } |
266 | - if(!$type_format) { |
|
266 | + if (!$type_format) { |
|
267 | 267 | $type_format = 2; |
268 | 268 | } |
269 | - $value = "$" . number_format($value, $type_format); |
|
269 | + $value = "$".number_format($value, $type_format); |
|
270 | 270 | break; |
271 | 271 | |
272 | 272 | case "date": |
273 | - if($align == "") { |
|
273 | + if ($align == "") { |
|
274 | 274 | $align = "right"; |
275 | 275 | } |
276 | - if(!is_numeric($value)) { |
|
276 | + if (!is_numeric($value)) { |
|
277 | 277 | $value = strtotime($value); |
278 | 278 | } |
279 | - if(!$type_format) { |
|
279 | + if (!$type_format) { |
|
280 | 280 | $type_format = "%A %d, %B %Y"; |
281 | 281 | } |
282 | 282 | $value = strftime($type_format, $value); |
283 | 283 | break; |
284 | 284 | |
285 | 285 | case "boolean": |
286 | - if($align == '') { |
|
286 | + if ($align == '') { |
|
287 | 287 | $align = "center"; |
288 | 288 | } |
289 | 289 | $value = number_format($value); |
290 | - if($value) { |
|
290 | + if ($value) { |
|
291 | 291 | $value = '•'; |
292 | 292 | } else { |
293 | 293 | $value = ' '; |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | // replace [+value+] first |
299 | 299 | $value = str_replace("[+value+]", $value, $type_format); |
300 | 300 | // replace other [+fields+] |
301 | - if(strpos($value, "[+") !== false) { |
|
302 | - foreach($row as $k => $v) { |
|
301 | + if (strpos($value, "[+") !== false) { |
|
302 | + foreach ($row as $k => $v) { |
|
303 | 303 | $value = str_replace("[+$k+]", $v, $value); |
304 | 304 | } |
305 | 305 | } |
@@ -11,7 +11,8 @@ discard block |
||
11 | 11 | # ----------------------------------------- |
12 | 12 | # |
13 | 13 | |
14 | -class DataGrid implements DataGridInterface{ |
|
14 | +class DataGrid implements DataGridInterface |
|
15 | +{ |
|
15 | 16 | |
16 | 17 | public $ds; // datasource |
17 | 18 | public $id; |
@@ -75,7 +76,8 @@ discard block |
||
75 | 76 | |
76 | 77 | public static $dataGridCnt; |
77 | 78 | |
78 | - public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
|
79 | + public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) |
|
80 | + { |
|
79 | 81 | // set id |
80 | 82 | self::$dataGridCnt++; |
81 | 83 | $this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt; |
@@ -89,11 +91,13 @@ discard block |
||
89 | 91 | $this->pagerLocation = 'top-right'; |
90 | 92 | } |
91 | 93 | |
92 | - public function setDataSource($ds) { |
|
94 | + public function setDataSource($ds) |
|
95 | + { |
|
93 | 96 | $this->ds = $ds; |
94 | 97 | } |
95 | 98 | |
96 | - public function render() { |
|
99 | + public function render() |
|
100 | + { |
|
97 | 101 | $modx = evolutionCMS(); |
98 | 102 | $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
99 | 103 | $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
@@ -128,7 +132,9 @@ discard block |
||
128 | 132 | |
129 | 133 | if($this->_isDataset && !$this->columns) { |
130 | 134 | $cols = $modx->getDatabase()->numFields($this->ds); |
131 | - for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
135 | + for($i = 0; $i < $cols; $i++) { |
|
136 | + $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
137 | + } |
|
132 | 138 | } |
133 | 139 | |
134 | 140 | // start grid |
@@ -207,7 +213,8 @@ discard block |
||
207 | 213 | |
208 | 214 | // format column values |
209 | 215 | |
210 | - public function RenderRowFnc($n, $row) { |
|
216 | + public function RenderRowFnc($n, $row) |
|
217 | + { |
|
211 | 218 | if($this->_alt == 0) { |
212 | 219 | $Style = $this->_itemStyle; |
213 | 220 | $Class = $this->_itemClass; |
@@ -237,7 +244,8 @@ discard block |
||
237 | 244 | return $o; |
238 | 245 | } |
239 | 246 | |
240 | - public function formatColumnValue($row, $value, $type, &$align) { |
|
247 | + public function formatColumnValue($row, $value, $type, &$align) |
|
248 | + { |
|
241 | 249 | if(strpos($type, ":") !== false) { |
242 | 250 | list($type, $type_format) = explode(":", $type, 2); |
243 | 251 | } |
@@ -75,6 +75,10 @@ discard block |
||
75 | 75 | |
76 | 76 | public static $dataGridCnt; |
77 | 77 | |
78 | + /** |
|
79 | + * @param null|string $id |
|
80 | + * @param string $ds |
|
81 | + */ |
|
78 | 82 | public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
79 | 83 | // set id |
80 | 84 | self::$dataGridCnt++; |
@@ -207,6 +211,9 @@ discard block |
||
207 | 211 | |
208 | 212 | // format column values |
209 | 213 | |
214 | + /** |
|
215 | + * @param integer $n |
|
216 | + */ |
|
210 | 217 | public function RenderRowFnc($n, $row) { |
211 | 218 | if($this->_alt == 0) { |
212 | 219 | $Style = $this->_itemStyle; |