Completed
Push — master ( ee5358...671ffe )
by
unknown
02:12
created
assets/snippets/DocLister/core/controller/site_content.php 1 patch
Braces   +107 added lines, -109 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
  * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
8 8
  * @author Agel_Nash <[email protected]>, kabachello <[email protected]>
9 9
  */
10
-class site_contentDocLister extends DocLister
11
-{
10
+class site_contentDocLister extends DocLister
11
+{
12 12
     /**
13 13
      * Экземпляр экстендера TV
14 14
      *
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
      * @param array $cfg
29 29
      * @param null $startTime
30 30
      */
31
-    public function __construct($modx, $cfg = array(), $startTime = null)
32
-    {
31
+    public function __construct($modx, $cfg = array(), $startTime = null)
32
+    {
33 33
         parent::__construct($modx, $cfg, $startTime);
34 34
         $this->extTV = $this->getExtender('tv', true, true);
35 35
     }
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
     /**
38 38
      * @absctract
39 39
      */
40
-    public function getDocs($tvlist = '')
41
-    {
42
-        if ($tvlist == '') {
40
+    public function getDocs($tvlist = '')
41
+    {
42
+        if ($tvlist == '') {
43 43
             $tvlist = $this->getCFGDef('tvList', '');
44 44
         }
45 45
         
@@ -50,29 +50,29 @@  discard block
 block discarded – undo
50 50
          */
51 51
         $extJotCount = $this->getCFGdef('jotcount', 0) ? $this->getExtender('jotcount', true) : null;
52 52
 
53
-        if ($extJotCount) {
53
+        if ($extJotCount) {
54 54
             $extJotCount->init($this);
55 55
         }
56 56
 
57
-        if ($this->extPaginate = $this->getExtender('paginate')) {
57
+        if ($this->extPaginate = $this->getExtender('paginate')) {
58 58
             $this->extPaginate->init($this);
59 59
         }
60 60
         $type = $this->getCFGDef('idType', 'parents');
61 61
         $this->_docs = ($type == 'parents') ? $this->getChildrenList() : $this->getDocList();
62
-        if ($tvlist != '' && count($this->_docs) > 0) {
62
+        if ($tvlist != '' && count($this->_docs) > 0) {
63 63
             $tv = $this->extTV->getTVList(array_keys($this->_docs), $tvlist);
64
-            if (!is_array($tv)) {
64
+            if (!is_array($tv)) {
65 65
                 $tv = array();
66 66
             }
67
-            foreach ($tv as $docID => $TVitem) {
68
-                if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) {
67
+            foreach ($tv as $docID => $TVitem) {
68
+                if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) {
69 69
                     $this->_docs[$docID] = array_merge($this->_docs[$docID], $TVitem);
70
-                } else {
70
+                } else {
71 71
                     unset($this->_docs[$docID]);
72 72
                 }
73 73
             }
74 74
         }
75
-        if (1 == $this->getCFGDef('tree', '0')) {
75
+        if (1 == $this->getCFGDef('tree', '0')) {
76 76
             $this->treeBuild('id', 'parent');
77 77
         }
78 78
 
@@ -83,23 +83,23 @@  discard block
 block discarded – undo
83 83
      * @param string $tpl
84 84
      * @return string
85 85
      */
86
-    public function _render($tpl = '')
87
-    {
86
+    public function _render($tpl = '')
87
+    {
88 88
         $out = '';
89 89
         $separator = $this->getCFGDef('outputSeparator', '');
90
-        if ($tpl == '') {
90
+        if ($tpl == '') {
91 91
             $tpl = $this->getCFGDef('tpl', '@CODE:<a href="[+url+]">[+pagetitle+]</a><br />');
92 92
         }
93
-        if ($tpl != '') {
93
+        if ($tpl != '') {
94 94
             $this->toPlaceholders(count($this->_docs), 1, "display"); // [+display+] - сколько показано на странице.
95 95
 
96 96
             $i = 1;
97 97
             $sysPlh = $this->renameKeyArr($this->_plh, $this->getCFGDef("sysKey", "dl"));
98
-            if (count($this->_docs) > 0) {
98
+            if (count($this->_docs) > 0) {
99 99
                 /**
100 100
                  * @var $extUser user_DL_Extender
101 101
                  */
102
-                if ($extUser = $this->getExtender('user')) {
102
+                if ($extUser = $this->getExtender('user')) {
103 103
                     $extUser->init($this, array('fields' => $this->getCFGDef("userFields", "")));
104 104
                 }
105 105
 
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
                 $extPrepare = $this->getExtender('prepare');
115 115
 
116 116
                 $this->skippedDocs = 0;
117
-                foreach ($this->_docs as $item) {
117
+                foreach ($this->_docs as $item) {
118 118
                     $this->renderTPL = $tpl;
119
-                    if ($extUser) {
119
+                    if ($extUser) {
120 120
                         $item = $extUser->setUserData($item); //[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+]....
121 121
                     }
122 122
 
@@ -128,24 +128,24 @@  discard block
 block discarded – undo
128 128
 
129 129
                     $item['title'] = ($item['menutitle'] == '' ? $item['pagetitle'] : $item['menutitle']);
130 130
 
131
-                    if ($this->getCFGDef('makeUrl', 1)) {
132
-                        if ($item['type'] == 'reference') {
131
+                    if ($this->getCFGDef('makeUrl', 1)) {
132
+                        if ($item['type'] == 'reference') {
133 133
                             $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '',
134 134
                                 $this->getCFGDef('urlScheme', '')) : $item['content'];
135
-                        } else {
135
+                        } else {
136 136
                             $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', ''));
137 137
                         }
138 138
                     }
139 139
                     $date = $this->getCFGDef('dateSource', 'pub_date');
140
-                    if (isset($item[$date])) {
141
-                        if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) {
140
+                    if (isset($item[$date])) {
141
+                        if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) {
142 142
                             $date = 'createdon';
143 143
                         }
144 144
                         $_date = is_numeric($item[$date]) && $item[$date] == (int)$item[$date] ? $item[$date] : strtotime($item[$date]);
145
-                        if ($_date !== false) {
145
+                        if ($_date !== false) {
146 146
                             $_date = $_date + $this->modx->config['server_offset_time'];
147 147
                             $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M');
148
-                            if ($dateFormat) {
148
+                            if ($dateFormat) {
149 149
                                 $item['date'] = strftime($dateFormat, $_date);
150 150
                             }
151 151
                         }
@@ -154,33 +154,33 @@  discard block
 block discarded – undo
154 154
                     $findTpl = $this->renderTPL;
155 155
                     $tmp = $this->uniformPrepare($item, $i);
156 156
                     extract($tmp, EXTR_SKIP);
157
-                    if ($this->renderTPL == '') {
157
+                    if ($this->renderTPL == '') {
158 158
                         $this->renderTPL = $findTpl;
159 159
                     }
160 160
 
161
-                    if ($extPrepare) {
161
+                    if ($extPrepare) {
162 162
                         $item = $extPrepare->init($this, array(
163 163
                             'data'      => $item,
164 164
                             'nameParam' => 'prepare'
165 165
                         ));
166
-                        if (is_bool($item) && $item === false) {
166
+                        if (is_bool($item) && $item === false) {
167 167
                             $this->skippedDocs++;
168 168
                             continue;
169 169
                         }
170 170
                     }
171 171
                     $tmp = $this->parseChunk($this->renderTPL, $item);
172 172
 
173
-                    if ($this->getCFGDef('contentPlaceholder', 0) !== 0) {
173
+                    if ($this->getCFGDef('contentPlaceholder', 0) !== 0) {
174 174
                         $this->toPlaceholders($tmp, 1,
175 175
                             "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page
176 176
                     }
177 177
                     $out .= $tmp;
178
-                    if (next($this->_docs) !== false) {
178
+                    if (next($this->_docs) !== false) {
179 179
                         $out .= $separator;
180 180
                     }
181 181
                     $i++;
182 182
                 }
183
-            } else {
183
+            } else {
184 184
                 $noneTPL = $this->getCFGDef('noneTPL', '');
185 185
                 $out = ($noneTPL != '') ? $this->parseChunk($noneTPL, $sysPlh) : '';
186 186
             }
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
      * @param array $array
197 197
      * @return string
198 198
      */
199
-    public function getJSON($data, $fields, $array = array())
200
-    {
199
+    public function getJSON($data, $fields, $array = array())
200
+    {
201 201
         $out = array();
202 202
         $fields = is_array($fields) ? $fields : explode(",", $fields);
203 203
         $date = $this->getCFGDef('dateSource', 'pub_date');
@@ -216,50 +216,50 @@  discard block
 block discarded – undo
216 216
          */
217 217
         $extE = $this->getExtender('e', true, true);
218 218
 
219
-        foreach ($data as $num => $row) {
220
-            if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) {
219
+        foreach ($data as $num => $row) {
220
+            if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) {
221 221
                 $row['summary'] = $this->getSummary($row, $extSummary, 'introtext', 'content');
222 222
             }
223 223
 
224
-            if (array('1') == $fields || in_array('date', $fields)) {
225
-                if (isset($row[$date])) {
226
-                    if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) {
224
+            if (array('1') == $fields || in_array('date', $fields)) {
225
+                if (isset($row[$date])) {
226
+                    if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) {
227 227
                         $date = 'createdon';
228 228
                     }   
229 229
                     $_date = is_numeric($row[$date]) && $row[$date] == (int)$row[$date] ? $row[$date] : strtotime($row[$date]);
230
-                    if ($_date !== false) {
230
+                    if ($_date !== false) {
231 231
                         $_date = $_date + $this->modx->config['server_offset_time'];
232 232
                         $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M');
233
-                        if ($dateFormat) {
233
+                        if ($dateFormat) {
234 234
                             $row['date'] = strftime($dateFormat, $_date);
235 235
                         }
236 236
                     }
237 237
                 }
238 238
             }
239 239
 
240
-            if (array('1') == $fields || in_array('title', $fields)) {
241
-                if (isset($row['pagetitle'])) {
240
+            if (array('1') == $fields || in_array('title', $fields)) {
241
+                if (isset($row['pagetitle'])) {
242 242
                     $row['title'] = empty($row['menutitle']) ? $row['pagetitle'] : $row['menutitle'];
243 243
                 }
244 244
             }
245 245
             if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url',$fields))
246
-            ) {
247
-                if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) {
246
+            ) {
247
+                if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) {
248 248
                     $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '',
249 249
                         $this->getCFGDef('urlScheme', '')) : $row['content'];
250
-                } elseif (isset($row['id'])) {
250
+                } elseif (isset($row['id'])) {
251 251
                     $row['url'] = $this->modx->makeUrl($row['id'], '', '', $this->getCFGDef('urlScheme', ''));
252 252
                 }
253 253
             }
254
-            if ($extE && $tmp = $extE->init($this, array('data' => $row))) {
255
-                if (is_array($tmp)) {
254
+            if ($extE && $tmp = $extE->init($this, array('data' => $row))) {
255
+                if (is_array($tmp)) {
256 256
                     $row = $tmp;
257 257
                 }
258 258
             }
259 259
 
260
-            if ($extPrepare) {
260
+            if ($extPrepare) {
261 261
                 $row = $extPrepare->init($this, array('data' => $row));
262
-                if (is_bool($row) && $row === false) {
262
+                if (is_bool($row) && $row === false) {
263 263
                     continue;
264 264
                 }
265 265
             }
@@ -272,36 +272,35 @@  discard block
 block discarded – undo
272 272
     /**
273 273
      * @abstract
274 274
      */
275
-    public function getChildrenCount()
276
-    {
275
+    public function getChildrenCount()
276
+    {
277 277
         $out = 0;
278 278
         $sanitarInIDs = $this->sanitarIn($this->IDs);
279
-        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
279
+        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
280 280
             $q_true = $this->getCFGDef('ignoreEmpty', '0');
281 281
             $q_true = $q_true ? $q_true : $this->getCFGDef('idType', 'parents') == 'parents';
282 282
             $where = $this->getCFGDef('addWhereList', '');
283 283
             $where = sqlHelper::trimLogicalOp($where);
284 284
             $where = ($where ? $where . ' AND ' : '') . $this->_filters['where'];
285
-            if ($where != '' && $this->_filters['where'] != '') {
285
+            if ($where != '' && $this->_filters['where'] != '') {
286 286
                 $where .= " AND ";
287 287
             }
288 288
             $where = sqlHelper::trimLogicalOp($where);
289 289
 
290 290
             $where = "WHERE {$where}";
291 291
             $whereArr = array();
292
-            if (!$this->getCFGDef('showNoPublish', 0)) {
292
+            if (!$this->getCFGDef('showNoPublish', 0)) {
293 293
                 $whereArr[] = "c.deleted=0 AND c.published=1";
294
-            }
295
-            else{
294
+            } else {
296 295
                 $q_true = 1;
297 296
             }
298 297
 
299 298
             $tbl_site_content = $this->getTable('site_content', 'c');
300 299
 
301
-            if ($sanitarInIDs != "''") {
302
-                switch ($this->getCFGDef('idType', 'parents')) {
300
+            if ($sanitarInIDs != "''") {
301
+                switch ($this->getCFGDef('idType', 'parents')) {
303 302
                     case 'parents':
304
-                        switch ($this->getCFGDef('showParent', '0')) {
303
+                        switch ($this->getCFGDef('showParent', '0')) {
305 304
                             case '-1':
306 305
                                 $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
307 306
                                 break;
@@ -313,10 +312,10 @@  discard block
 block discarded – undo
313 312
                                 $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))";
314 313
                                 break;
315 314
                         }
316
-                        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
315
+                        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
317 316
                             $addDocs = $this->sanitarIn($this->cleanIDs($addDocs));
318 317
                             $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
319
-                        } else {
318
+                        } else {
320 319
                             $whereArr[] = $tmpWhere;
321 320
                         }
322 321
 
@@ -331,26 +330,25 @@  discard block
 block discarded – undo
331 330
 
332 331
             $q_true = $q_true ? $q_true : trim($where) != 'WHERE';
333 332
 
334
-            if (trim($where) != 'WHERE') {
333
+            if (trim($where) != 'WHERE') {
335 334
                 $where .= " AND ";
336 335
             }
337 336
 
338 337
             $where .= implode(" AND ", $whereArr);
339 338
             $where = sqlHelper::trimLogicalOp($where);
340 339
 
341
-            if (trim($where) == 'WHERE') {
340
+            if (trim($where) == 'WHERE') {
342 341
                 $where = '';
343 342
             }
344 343
             $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id'));
345 344
 
346 345
             $q_true = $q_true ? $q_true : $group != '';
347
-            if ( $q_true ){
346
+            if ( $q_true ) {
348 347
                 $maxDocs = $this->getCFGDef('maxDocs', 0);
349 348
                 $limit = $maxDocs > 0 ? $this->LimitSQL($this->getCFGDef('maxDocs', 0)) : '';
350 349
                 $rs = $this->dbQuery("SELECT count(*) FROM (SELECT count(*) FROM {$from} {$where} {$group} {$limit}) as `tmp`");
351 350
                 $out = $this->modx->db->getValue($rs);
352
-            }
353
-            else {
351
+            } else {
354 352
                 $out = count($this->IDs);
355 353
             }
356 354
         }
@@ -361,11 +359,11 @@  discard block
 block discarded – undo
361 359
     /**
362 360
      * @return array
363 361
      */
364
-    protected function getDocList()
365
-    {
362
+    protected function getDocList()
363
+    {
366 364
         $out = array();
367 365
         $sanitarInIDs = $this->sanitarIn($this->IDs);
368
-        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
366
+        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
369 367
             $where = $this->getCFGDef('addWhereList', '');
370 368
             $where = sqlHelper::trimLogicalOp($where);
371 369
 
@@ -373,21 +371,21 @@  discard block
 block discarded – undo
373 371
             $where = sqlHelper::trimLogicalOp($where);
374 372
 
375 373
             $tbl_site_content = $this->getTable('site_content', 'c');
376
-            if ($sanitarInIDs != "''") {
374
+            if ($sanitarInIDs != "''") {
377 375
                 $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND";
378 376
             }
379 377
             $where = sqlHelper::trimLogicalOp($where);
380 378
 
381
-            if ($this->getCFGDef('showNoPublish', 0)) {
382
-                if ($where != '') {
379
+            if ($this->getCFGDef('showNoPublish', 0)) {
380
+                if ($where != '') {
383 381
                     $where = "WHERE {$where}";
384
-                } else {
382
+                } else {
385 383
                     $where = '';
386 384
                 }
387
-            } else {
388
-                if ($where != '') {
385
+            } else {
386
+                if ($where != '') {
389 387
                     $where = "WHERE {$where} AND ";
390
-                } else {
388
+                } else {
391 389
                     $where = "WHERE {$where} ";
392 390
                 }
393 391
                 $where .= "c.deleted=0 AND c.published=1";
@@ -404,7 +402,7 @@  discard block
 block discarded – undo
404 402
 
405 403
             $rs = $this->dbQuery("SELECT {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}");
406 404
 
407
-            while ($item = $this->modx->db->getRow($rs)) {
405
+            while ($item = $this->modx->db->getRow($rs)) {
408 406
                 $out[$item['id']] = $item;
409 407
             };
410 408
         }
@@ -416,26 +414,26 @@  discard block
 block discarded – undo
416 414
      * @param string $id
417 415
      * @return array
418 416
      */
419
-    public function getChildrenFolder($id)
420
-    {
417
+    public function getChildrenFolder($id)
418
+    {
421 419
         $out = array();
422 420
         $where = $this->getCFGDef('addWhereFolder', '');
423 421
         $where = sqlHelper::trimLogicalOp($where);
424
-        if ($where != '') {
422
+        if ($where != '') {
425 423
             $where .= " AND ";
426 424
         }
427 425
 
428 426
         $tbl_site_content = $this->getTable('site_content', 'c');
429 427
         $sanitarInIDs = $this->sanitarIn($id);
430
-        if ($this->getCFGDef('showNoPublish', 0)) {
428
+        if ($this->getCFGDef('showNoPublish', 0)) {
431 429
             $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1";
432
-        } else {
430
+        } else {
433 431
             $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1";
434 432
         }
435 433
 
436 434
         $rs = $this->dbQuery("SELECT id FROM {$tbl_site_content} {$where}");
437 435
 
438
-        while ($item = $this->modx->db->getRow($rs)) {
436
+        while ($item = $this->modx->db->getRow($rs)) {
439 437
             $out[] = $item['id'];
440 438
         }
441 439
 
@@ -447,10 +445,10 @@  discard block
 block discarded – undo
447 445
      * @param $sort
448 446
      * @return array
449 447
      */
450
-    protected function injectSortByTV($table, $sort)
451
-    {
448
+    protected function injectSortByTV($table, $sort)
449
+    {
452 450
         $out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort);
453
-        if (!is_array($out) || empty($out)) {
451
+        if (!is_array($out) || empty($out)) {
454 452
             $out = array($table, $sort);
455 453
         }
456 454
 
@@ -460,19 +458,19 @@  discard block
 block discarded – undo
460 458
     /**
461 459
      * @return array
462 460
      */
463
-    protected function getChildrenList()
464
-    {
461
+    protected function getChildrenList()
462
+    {
465 463
         $where = array();
466 464
         $out = array();
467 465
 
468 466
         $tmpWhere = $this->getCFGDef('addWhereList', '');
469 467
         $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere);
470
-        if (!empty($tmpWhere)) {
468
+        if (!empty($tmpWhere)) {
471 469
             $where[] = $tmpWhere;
472 470
         }
473 471
 
474 472
         $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']);
475
-        if (!empty($tmpWhere)) {
473
+        if (!empty($tmpWhere)) {
476 474
             $where[] = $tmpWhere;
477 475
         }
478 476
 
@@ -483,8 +481,8 @@  discard block
 block discarded – undo
483 481
         $sanitarInIDs = $this->sanitarIn($this->IDs);
484 482
 
485 483
         $tmpWhere = null;
486
-        if ($sanitarInIDs != "''") {
487
-            switch ($this->getCFGDef('showParent', '0')) {
484
+        if ($sanitarInIDs != "''") {
485
+            switch ($this->getCFGDef('showParent', '0')) {
488 486
                 case '-1':
489 487
                     $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
490 488
                     break;
@@ -497,36 +495,36 @@  discard block
 block discarded – undo
497 495
                     break;
498 496
             }
499 497
         }
500
-        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
498
+        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
501 499
             $addDocs = $this->sanitarIn($this->cleanIDs($addDocs));
502
-            if (empty($tmpWhere)) {
500
+            if (empty($tmpWhere)) {
503 501
                 $tmpWhere = "c.id IN({$addDocs})";
504
-            } else {
502
+            } else {
505 503
                 $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
506 504
             }
507 505
         }
508
-        if (!empty($tmpWhere)) {
506
+        if (!empty($tmpWhere)) {
509 507
             $where[] = $tmpWhere;
510 508
         }
511
-        if (!$this->getCFGDef('showNoPublish', 0)) {
509
+        if (!$this->getCFGDef('showNoPublish', 0)) {
512 510
             $where[] = "c.deleted=0 AND c.published=1";
513 511
         }
514
-        if (!empty($where)) {
512
+        if (!empty($where)) {
515 513
             $where = "WHERE " . implode(" AND ", $where);
516
-        } else {
514
+        } else {
517 515
             $where = '';
518 516
         }
519 517
         $fields = $this->getCFGDef('selectFields', 'c.*');
520 518
         $group = $this->getGroupSQL($this->getCFGDef('groupBy', ''));
521 519
 
522
-        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
520
+        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
523 521
             $rs = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " .
524 522
                 $group . " " .
525 523
                 $sort . " " .
526 524
                 $this->LimitSQL($this->getCFGDef('queryLimit', 0))
527 525
             );
528 526
 
529
-            while ($item = $this->modx->db->getRow($rs)) {
527
+            while ($item = $this->modx->db->getRow($rs)) {
530 528
                 $out[$item['id']] = $item;
531 529
             }
532 530
         }
@@ -539,10 +537,10 @@  discard block
 block discarded – undo
539 537
      * @param string $type
540 538
      * @return string
541 539
      */
542
-    public function changeSortType($field, $type)
543
-    {
540
+    public function changeSortType($field, $type)
541
+    {
544 542
         $type = trim($type);
545
-        switch (strtoupper($type)) {
543
+        switch (strtoupper($type)) {
546 544
             case 'TVDATETIME':
547 545
                 $field = "STR_TO_DATE(" . $field . ",'%d-%m-%Y %H:%i:%s')";
548 546
                 break;
Please login to merge, or discard this patch.
assets/snippets/DocLister/core/controller/onetable.php 1 patch
Braces   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
  * @param contentField =`description` //content
11 11
  * @param table =`` //table name
12 12
  */
13
-class onetableDocLister extends DocLister
14
-{
13
+class onetableDocLister extends DocLister
14
+{
15 15
     /**
16 16
      * @var string
17 17
      */
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
     /**
30 30
      * @absctract
31 31
      */
32
-    public function getDocs($tvlist = '')
33
-    {
34
-        if ($this->checkExtender('paginate')) {
32
+    public function getDocs($tvlist = '')
33
+    {
34
+        if ($this->checkExtender('paginate')) {
35 35
             $this->extender['paginate']->init($this);
36 36
         }
37 37
         $type = $this->getCFGDef('idType', 'parents');
@@ -44,26 +44,26 @@  discard block
 block discarded – undo
44 44
      * @param string $tpl
45 45
      * @return string
46 46
      */
47
-    public function _render($tpl = '')
48
-    {
47
+    public function _render($tpl = '')
48
+    {
49 49
         $out = '';
50 50
         $separator = $this->getCFGDef('outputSeparator', '');
51
-        if ($tpl == '') {
51
+        if ($tpl == '') {
52 52
             $tpl = $this->getCFGDef('tpl', '');
53 53
         }
54
-        if ($tpl != '') {
54
+        if ($tpl != '') {
55 55
             $this->toPlaceholders(count($this->_docs), 1, "display"); // [+display+] - сколько показано на странице.
56 56
 
57 57
             $i = 1;
58 58
             $sysPlh = $this->renameKeyArr($this->_plh, $this->getCFGDef("sysKey", "dl"));
59 59
             $noneTPL = $this->getCFGDef("noneTPL", "");
60
-            if (count($this->_docs) == 0 && $noneTPL != '') {
60
+            if (count($this->_docs) == 0 && $noneTPL != '') {
61 61
                 $out = $this->parseChunk($noneTPL, $sysPlh);
62
-            } else {
62
+            } else {
63 63
                 /**
64 64
                  * @var $extUser user_DL_Extender
65 65
                  */
66
-                if ($extUser = $this->getExtender('user')) {
66
+                if ($extUser = $this->getExtender('user')) {
67 67
                     $extUser->init($this, array('fields' => $this->getCFGDef("userFields", "")));
68 68
                 }
69 69
 
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
                  */
78 78
                 $extPrepare = $this->getExtender('prepare');
79 79
                 $this->skippedDocs = 0;
80
-                foreach ($this->_docs as $item) {
80
+                foreach ($this->_docs as $item) {
81 81
                     $this->renderTPL = $tpl;
82
-                    if ($extUser) {
82
+                    if ($extUser) {
83 83
                         $item = $extUser->setUserData($item); //[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+]....
84 84
                     }
85 85
 
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
                         "dl") . '.iteration'] = $i; //[+iteration+] - Number element. Starting from zero
93 93
 
94 94
                     $date = $this->getCFGDef('dateSource', 'pub_date');
95
-                    if (isset($item[$date])) {
95
+                    if (isset($item[$date])) {
96 96
                         $_date = is_numeric($item[$date]) && $item[$date] == (int)$item[$date] ? $item[$date] : strtotime($item[$date]);
97
-                        if ($_date !== false) {
97
+                        if ($_date !== false) {
98 98
                             $_date = $_date + $this->modx->config['server_offset_time'];
99 99
                             $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M');
100
-                            if ($dateFormat) {
100
+                            if ($dateFormat) {
101 101
                                 $item['date'] = strftime($dateFormat, $_date);
102 102
                             }
103 103
                         }
@@ -106,27 +106,27 @@  discard block
 block discarded – undo
106 106
                     $findTpl = $this->renderTPL;
107 107
                     $tmp = $this->uniformPrepare($item, $i);
108 108
                     extract($tmp, EXTR_SKIP);
109
-                    if ($this->renderTPL == '') {
109
+                    if ($this->renderTPL == '') {
110 110
                         $this->renderTPL = $findTpl;
111 111
                     }
112 112
 
113
-                    if ($extPrepare) {
113
+                    if ($extPrepare) {
114 114
                         $item = $extPrepare->init($this, array(
115 115
                             'data'      => $item,
116 116
                             'nameParam' => 'prepare'
117 117
                         ));
118
-                        if (is_bool($item) && $item === false) {
118
+                        if (is_bool($item) && $item === false) {
119 119
                             $this->skippedDocs++;
120 120
                             continue;
121 121
                         }
122 122
                     }
123 123
                     $tmp = $this->parseChunk($this->renderTPL, $item);
124
-                    if ($this->getCFGDef('contentPlaceholder', 0) !== 0) {
124
+                    if ($this->getCFGDef('contentPlaceholder', 0) !== 0) {
125 125
                         $this->toPlaceholders($tmp, 1,
126 126
                             "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page
127 127
                     }
128 128
                     $out .= $tmp;
129
-                    if (next($this->_docs) !== false) {
129
+                    if (next($this->_docs) !== false) {
130 130
                         $out .= $separator;
131 131
                     }
132 132
                     $i++;
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
      * @param array $array
145 145
      * @return string
146 146
      */
147
-    public function getJSON($data, $fields, $array = array())
148
-    {
147
+    public function getJSON($data, $fields, $array = array())
148
+    {
149 149
         $out = array();
150 150
         $fields = is_array($fields) ? $fields : explode(",", $fields);
151 151
         $date = $this->getCFGDef('dateSource', 'pub_date');
@@ -164,19 +164,19 @@  discard block
 block discarded – undo
164 164
          * @var $extE e_DL_Extender
165 165
          */
166 166
         $extE = $this->getExtender('e', true, true);
167
-        foreach ($data as $num => $row) {
167
+        foreach ($data as $num => $row) {
168 168
 
169
-            switch (true) {
169
+            switch (true) {
170 170
                 case ((array('1') == $fields || in_array('summary', $fields)) && $extSummary):
171 171
                     $row['summary'] = $this->getSummary($row, $extSummary, 'introtext');
172 172
                 //without break
173 173
                 case ((array('1') == $fields || in_array('date', $fields)) && $date != 'date'):
174
-                    if (isset($row[$date])) {
174
+                    if (isset($row[$date])) {
175 175
                         $_date = is_numeric($row[$date]) && $row[$date] == (int)$row[$date] ? $row[$date] : strtotime($row[$date]);
176
-                        if ($_date !== false) {
176
+                        if ($_date !== false) {
177 177
                             $_date = $_date + $this->modx->config['server_offset_time'];
178 178
                             $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M');
179
-                            if ($dateFormat) {
179
+                            if ($dateFormat) {
180 180
                                 $row['date'] = strftime($dateFormat, $_date);
181 181
                             }
182 182
                         }
@@ -184,15 +184,15 @@  discard block
 block discarded – undo
184 184
                 //nobreak    
185 185
             }
186 186
 
187
-            if ($extE && $tmp = $extE->init($this, array('data' => $row))) {
188
-                if (is_array($tmp)) {
187
+            if ($extE && $tmp = $extE->init($this, array('data' => $row))) {
188
+                if (is_array($tmp)) {
189 189
                     $row = $tmp;
190 190
                 }
191 191
             }
192 192
 
193
-            if ($extPrepare) {
193
+            if ($extPrepare) {
194 194
                 $row = $extPrepare->init($this, array('data' => $row));
195
-                if (is_bool($row) && $row === false) {
195
+                if (is_bool($row) && $row === false) {
196 196
                     continue;
197 197
                 }
198 198
             }
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
     /**
206 206
      * @return array
207 207
      */
208
-    protected function getDocList()
209
-    {
208
+    protected function getDocList()
209
+    {
210 210
         $out = array();
211 211
         $sanitarInIDs = $this->sanitarIn($this->IDs);
212
-        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
212
+        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
213 213
             $from = $this->table . " " . $this->_filters['join'];
214 214
             $where = $this->getCFGDef('addWhereList', '');
215 215
             
@@ -219,14 +219,14 @@  discard block
 block discarded – undo
219 219
         	//------- end of block -------
220 220
 
221 221
             
222
-            if ($where != '') {
222
+            if ($where != '') {
223 223
                 $where = array($where);
224 224
             }
225
-            if ($sanitarInIDs != "''") {
225
+            if ($sanitarInIDs != "''") {
226 226
                 $where[] = "{$this->getPK()} IN ({$sanitarInIDs})";
227 227
             }
228 228
 
229
-            if (!empty($where)) {
229
+            if (!empty($where)) {
230 230
                 $where = "WHERE " . implode(" AND ", $where);
231 231
             }
232 232
             $limit = $this->LimitSQL($this->getCFGDef('queryLimit', 0));
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
             $rs = $this->dbQuery("SELECT {$fields} FROM {$from} {$where} {$group} {$sort} {$limit}");
237 237
 
238 238
             $pk = $this->getPK(false);
239
-            while ($item = $this->modx->db->getRow($rs)) {
239
+            while ($item = $this->modx->db->getRow($rs)) {
240 240
                 $out[$item[$pk]] = $item;
241 241
             }
242 242
         }
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
     /**
248 248
      * @return array
249 249
      */
250
-    protected function getChildrenList()
251
-    {
250
+    protected function getChildrenList()
251
+    {
252 252
         $where = array();
253 253
         $out = array();
254 254
         $from = $this->table . " " . $this->_filters['join'];
@@ -261,15 +261,15 @@  discard block
 block discarded – undo
261 261
 	    //------- end of block -------
262 262
         
263 263
         
264
-        if (!empty($tmpWhere)) {
264
+        if (!empty($tmpWhere)) {
265 265
             $where[] = $tmpWhere;
266 266
         }
267 267
         $sanitarInIDs = $this->sanitarIn($this->IDs);
268 268
 
269 269
         $tmpWhere = null;
270
-        if ($sanitarInIDs != "''") {
270
+        if ($sanitarInIDs != "''") {
271 271
             $tmpWhere = "({$this->getParentField()} IN (" . $sanitarInIDs . ")";
272
-            switch ($this->getCFGDef('showParent', '0')) {
272
+            switch ($this->getCFGDef('showParent', '0')) {
273 273
                 case -1:
274 274
                     $tmpWhere .= ")";
275 275
                     break;
@@ -282,32 +282,32 @@  discard block
 block discarded – undo
282 282
                     break;
283 283
             }
284 284
         }
285
-        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
285
+        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
286 286
             $addDocs = $this->sanitarIn($this->cleanIDs($addDocs));
287
-            if (empty($tmpWhere)) {
287
+            if (empty($tmpWhere)) {
288 288
                 $tmpWhere = $this->getPK() . " IN({$addDocs})";
289
-            } else {
289
+            } else {
290 290
                 $tmpWhere = "((" . $tmpWhere . ") OR {$this->getPK()} IN({$addDocs}))";
291 291
             }
292 292
         }
293
-        if (!empty($tmpWhere)) {
293
+        if (!empty($tmpWhere)) {
294 294
             $where[] = $tmpWhere;
295 295
         }
296
-        if (!empty($where)) {
296
+        if (!empty($where)) {
297 297
             $where = "WHERE " . implode(" AND ", $where);
298
-        } else {
298
+        } else {
299 299
             $where = '';
300 300
         }
301 301
         $fields = $this->getCFGDef('selectFields', '*');
302 302
         $group = $this->getGroupSQL($this->getCFGDef('groupBy', ''));
303 303
         $sort = $this->SortOrderSQL($this->getPK());
304 304
         $limit = $this->LimitSQL($this->getCFGDef('queryLimit', 0));
305
-        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
305
+        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
306 306
             $rs = $this->dbQuery("SELECT {$fields} FROM {$from} {$where} {$group} {$sort} {$limit}");
307 307
 
308 308
             $pk = $this->getPK(false);
309 309
 
310
-            while ($item = $this->modx->db->getRow($rs)) {
310
+            while ($item = $this->modx->db->getRow($rs)) {
311 311
                 $out[$item[$pk]] = $item;
312 312
             }
313 313
 
@@ -319,11 +319,11 @@  discard block
 block discarded – undo
319 319
     /**
320 320
      * @absctract
321 321
      */
322
-    public function getChildrenCount()
323
-    {
322
+    public function getChildrenCount()
323
+    {
324 324
         $out = 0;
325 325
         $sanitarInIDs = $this->sanitarIn($this->IDs);
326
-        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
326
+        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
327 327
             $from = $this->table . " " . $this->_filters['join'];
328 328
             $where = $this->getCFGDef('addWhereList', '');
329 329
             
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
             $where = sqlHelper::trimLogicalOp($where);
333 333
 	        //------- end of block -------
334 334
             
335
-            if ($where != '') {
335
+            if ($where != '') {
336 336
                 $where = array($where);
337
-            } else {
337
+            } else {
338 338
                 $where = array();
339 339
             }
340
-            if ($sanitarInIDs != "''") {
341
-                if ($sanitarInIDs != "''") {
342
-                    switch ($this->getCFGDef('idType', 'parents')) {
340
+            if ($sanitarInIDs != "''") {
341
+                if ($sanitarInIDs != "''") {
342
+                    switch ($this->getCFGDef('idType', 'parents')) {
343 343
                         case 'parents':
344
-                            switch ($this->getCFGDef('showParent', '0')) {
344
+                            switch ($this->getCFGDef('showParent', '0')) {
345 345
                                 case '-1':
346 346
                                     $tmpWhere = "{$this->getParentField()} IN ({$sanitarInIDs})";
347 347
                                     break;
@@ -353,10 +353,10 @@  discard block
 block discarded – undo
353 353
                                     $tmpWhere = "({$this->getParentField()} IN ({$sanitarInIDs}) OR {$this->getPK()} IN({$sanitarInIDs}))";
354 354
                                     break;
355 355
                             }
356
-                            if (($addDocs = $this->getCFGDef('documents', '')) != '') {
356
+                            if (($addDocs = $this->getCFGDef('documents', '')) != '') {
357 357
                                 $addDocs = $this->sanitarIn($this->cleanIDs($addDocs));
358 358
                                 $where[] = "((" . $tmpWhere . ") OR {$this->getPK()} IN({$addDocs}))";
359
-                            } else {
359
+                            } else {
360 360
                                 $where[] = $tmpWhere;
361 361
                             }
362 362
                             break;
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
                     }
367 367
                 }
368 368
             }
369
-            if (!empty($where)) {
369
+            if (!empty($where)) {
370 370
                 $where = "WHERE " . implode(" AND ", $where);
371
-            } else {
371
+            } else {
372 372
                 $where = '';
373 373
             }
374 374
 
@@ -386,20 +386,20 @@  discard block
 block discarded – undo
386 386
      * @param string $id
387 387
      * @return array
388 388
      */
389
-    public function getChildrenFolder($id)
390
-    {
389
+    public function getChildrenFolder($id)
390
+    {
391 391
         $out = array();
392 392
         $sanitarInIDs = $this->sanitarIn($id);
393 393
 
394 394
         $tmp = $this->getCFGDef('addWhereFolder', '');
395 395
         $where = "{$this->getParentField()} IN ({$sanitarInIDs})";
396
-        if (!empty($tmp)) {
396
+        if (!empty($tmp)) {
397 397
             $where .= " AND " . $tmp;
398 398
         }
399 399
 
400 400
         $rs = $this->dbQuery("SELECT {$this->getPK()} FROM {$this->table} WHERE {$where}");
401 401
         $pk = $this->getPK(false);
402
-        while ($item = $this->modx->db->getRow($rs)) {
402
+        while ($item = $this->modx->db->getRow($rs)) {
403 403
             $out[] = $item[$pk];
404 404
         }
405 405
 
Please login to merge, or discard this patch.