Completed
Push — master ( a8cf44...b01fba )
by
unknown
02:08
created
assets/lib/MODxAPI/modResource.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         $tpl = $this->get('template');
191 191
         $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
192 192
         foreach ($tvTPL as $item) {
193
-            if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
193
+            if (isset($this->tvid[$item]) && ! array_key_exists($this->tvid[$item], $out)) {
194 194
                 $out[$this->tvid[$item]] = $this->get($this->tvid[$item]);
195 195
             }
196 196
         }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
     {
229 229
         $out = null;
230 230
         $id = (int)$this->getID();
231
-        if (!empty($id)) {
231
+        if ( ! empty($id)) {
232 232
             $out = $this->modx->makeUrl($id);
233 233
         }
234 234
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
      */
323 323
     public function set($key, $value)
324 324
     {
325
-        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
325
+        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && ! empty($key)) {
326 326
             switch ($key) {
327 327
                 case 'parent':
328 328
                     $value = (int)$value;
@@ -395,12 +395,12 @@  discard block
 block discarded – undo
395 395
     {
396 396
         $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0);
397 397
         $value = (int)$value;
398
-        if (!empty($value)) {
398
+        if ( ! empty($value)) {
399 399
             $by = $this->findUserBy($value);
400
-            $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
400
+            $exists = $this->managerUsers->exists(function($key, Helpers\Collection $val) use ($by, $value) {
401 401
                 return ($val->containsKey($by) && $val->get($by) === (string)$value);
402 402
             });
403
-            if (!$exists) {
403
+            if ( ! $exists) {
404 404
                 $value = 0;
405 405
             }
406 406
         }
@@ -441,11 +441,11 @@  discard block
 block discarded – undo
441 441
     protected function getTime($value)
442 442
     {
443 443
         $value = trim($value);
444
-        if (!empty($value)) {
445
-            if (!is_numeric($value)) {
444
+        if ( ! empty($value)) {
445
+            if ( ! is_numeric($value)) {
446 446
                 $value = (int)strtotime($value);
447 447
             }
448
-            if (!empty($value)) {
448
+            if ( ! empty($value)) {
449 449
                 $value += $this->modxConfig('server_offset_time');
450 450
             }
451 451
         }
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
 
526 526
         if (
527 527
             $this->field['parent'] == 0 &&
528
-            !$this->modxConfig('udperms_allowroot') &&
529
-            !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1)
528
+            ! $this->modxConfig('udperms_allowroot') &&
529
+            ! ($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1)
530 530
         ) {
531 531
             $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off';
532 532
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
         $fld = $this->encodeFields()->toArray(null, null, null, false);
546 546
         foreach ($this->default_field as $key => $value) {
547 547
             $tmp = $this->get($key);
548
-            if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
548
+            if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) {
549 549
                 if ($tmp == $value) {
550 550
                     switch ($key) {
551 551
                         case 'cacheable':
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
                     $this->field[$key] = $parent;
578 578
                     $this->Uset($key);
579 579
                     break;
580
-                case ($key == 'alias_visible' && !$this->checkVersion('1.0.10', true)):
580
+                case ($key == 'alias_visible' && ! $this->checkVersion('1.0.10', true)):
581 581
                     $this->eraseField('alias_visible');
582 582
                     break;
583 583
                 default:
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
             unset($fld[$key]);
587 587
         }
588 588
 
589
-        if (!empty($this->set)) {
589
+        if ( ! empty($this->set)) {
590 590
             if ($this->newDoc) {
591 591
                 $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set);
592 592
             } else {
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 
607 607
         $_deleteTVs = $_updateTVs = $_insertTVs = array();
608 608
         foreach ($fld as $key => $value) {
609
-            if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) {
609
+            if (empty($this->tv[$key]) || ! $this->isChanged($key) || ! $this->belongsToTemplate($this->tv[$key])) {
610 610
                 continue;
611 611
             } elseif ($value === '') {
612 612
                 $_deleteTVs[] = $this->tv[$key];
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
             }
616 616
         }
617 617
 
618
-        if (!$this->newDoc && !empty($_insertTVs)) {
618
+        if ( ! $this->newDoc && ! empty($_insertTVs)) {
619 619
             $ids = implode(',', array_keys($_insertTVs));
620 620
             $result = $this->query("SELECT `tmplvarid` FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid`={$this->id} AND `tmplvarid` IN ({$ids})");
621 621
             $existedTVs = $this->modx->db->getColumn('tmplvarid', $result);
@@ -625,13 +625,13 @@  discard block
 block discarded – undo
625 625
             }
626 626
         }
627 627
 
628
-        if (!empty($_updateTVs)) {
628
+        if ( ! empty($_updateTVs)) {
629 629
             foreach ($_updateTVs as $id => $value) {
630 630
                 $this->query("UPDATE {$this->makeTable('site_tmplvar_contentvalues')} SET `value` = '{$value}' WHERE `contentid` = {$this->id} AND `tmplvarid` = {$id}");
631 631
             }
632 632
         }
633 633
 
634
-        if (!empty($_insertTVs)) {
634
+        if ( ! empty($_insertTVs)) {
635 635
             $values = array();
636 636
             foreach ($_insertTVs as $id => $value) {
637 637
                 $values[] = "({$this->id}, {$id}, '{$value}')";
@@ -640,12 +640,12 @@  discard block
 block discarded – undo
640 640
             $this->query("INSERT into {$this->makeTable('site_tmplvar_contentvalues')} (`contentid`,`tmplvarid`,`value`) VALUES {$values}");
641 641
         }
642 642
 
643
-        if (!empty($_deleteTVs)) {
643
+        if ( ! empty($_deleteTVs)) {
644 644
             $ids = implode(',', $_deleteTVs);
645 645
             $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})");
646 646
         }
647 647
 
648
-        if (!isset($this->mode)) {
648
+        if ( ! isset($this->mode)) {
649 649
             $this->mode = $this->newDoc ? "new" : "upd";
650 650
             $this->newDoc = false;
651 651
         }
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
         $_ids = $this->cleanIDs($ids, ',');
733 733
         if (is_array($_ids) && $_ids != array()) {
734 734
             $id = $this->sanitarIn($_ids);
735
-            if (!empty($id)) {
735
+            if ( ! empty($id)) {
736 736
                 $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})");
737 737
                 $id = $this->modx->db->getColumn('id', $q);
738 738
                 if ($depth > 0 || $depth === true) {
@@ -797,12 +797,12 @@  discard block
 block discarded – undo
797 797
         $alias = strtolower($alias);
798 798
         if ($this->modxConfig('friendly_urls')) {
799 799
             $_alias = $this->escape($alias);
800
-            if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
800
+            if (( ! $this->modxConfig('allow_duplicate_alias') && ! $this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
801 801
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1"));
802 802
             } else {
803 803
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1"));
804 804
             }
805
-            if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
805
+            if (($flag && $this->newDoc) || ( ! $this->newDoc && $flag && $this->id != $flag)) {
806 806
                 $suffix = substr($alias, -2);
807 807
                 if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
808 808
                     $suffix = (int)$tmp[1] + 1;
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
      */
878 878
     protected function loadTVDefault(array $tvId = array())
879 879
     {
880
-        if (is_array($tvId) && !empty($tvId)) {
880
+        if (is_array($tvId) && ! empty($tvId)) {
881 881
             $tbl_site_tmplvars = $this->makeTable('site_tmplvars');
882 882
             $fields = 'id,name,default_text as value,display,display_params,type';
883 883
             $implodeTvId = implode(',', $tvId);
@@ -899,11 +899,11 @@  discard block
 block discarded – undo
899 899
      */
900 900
     public function setTemplate($tpl)
901 901
     {
902
-        if (!is_numeric($tpl) || $tpl != (int)$tpl) {
902
+        if ( ! is_numeric($tpl) || $tpl != (int)$tpl) {
903 903
             if (is_scalar($tpl)) {
904 904
                 $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'";
905 905
                 $rs = $this->query($sql);
906
-                if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
906
+                if ( ! $rs || $this->modx->db->getRecordCount($rs) <= 0) {
907 907
                     throw new Exception("Template {$tpl} is not exists");
908 908
                 }
909 909
                 $tpl = $this->modx->db->getValue($rs);
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
         $template = $this->modxConfig('default_template');
965 965
         switch ($this->modxConfig('auto_template_logic')) {
966 966
             case 'sibling':
967
-                if (!$parent) {
967
+                if ( ! $parent) {
968 968
                     $site_start = $this->modxConfig('site_start');
969 969
                     $where = "sc.isfolder=0 AND sc.id!={$site_start}";
970 970
                     $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1);
@@ -1116,7 +1116,7 @@  discard block
 block discarded – undo
1116 1116
      */
1117 1117
     public function setDocumentGroups($docId = 0, $groupIds = array())
1118 1118
     {
1119
-        if (!is_array($groupIds)) return $this;
1119
+        if ( ! is_array($groupIds)) return $this;
1120 1120
         if ($this->newDoc && $docId == 0) {
1121 1121
             $this->groupIds = $groupIds;
1122 1122
         } else {
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
                 foreach ($groupIds as $gid) {
1126 1126
                     $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')");
1127 1127
                 }
1128
-                if (!$this->newDoc) {
1128
+                if ( ! $this->newDoc) {
1129 1129
                     $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds);
1130 1130
                     $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})");
1131 1131
                 }
Please login to merge, or discard this patch.
Braces   +202 added lines, -194 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@  discard block
 block discarded – undo
4 4
 /**
5 5
  * Class modResource
6 6
  */
7
-class modResource extends MODxAPI
8
-{
7
+class modResource extends MODxAPI
8
+{
9 9
     /**
10 10
      * @var string
11 11
      */
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
      * @param DocumentParser $modx
160 160
      * @param bool $debug
161 161
      */
162
-    public function __construct($modx, $debug = false)
163
-    {
162
+    public function __construct($modx, $debug = false)
163
+    {
164 164
         parent::__construct($modx, $debug);
165 165
         $this->get_TV();
166 166
         $uTable = $this->makeTable("manager_users");
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
     /**
174 174
      * @return array
175 175
      */
176
-    public function toArrayMain()
177
-    {
176
+    public function toArrayMain()
177
+    {
178 178
         $out = array_intersect_key(parent::toArray(), $this->default_field);
179 179
 
180 180
         return $out;
@@ -184,18 +184,18 @@  discard block
 block discarded – undo
184 184
      * @param bool $render
185 185
      * @return array
186 186
      */
187
-    public function toArrayTV($render = false)
188
-    {
187
+    public function toArrayTV($render = false)
188
+    {
189 189
         $out = array_diff_key(parent::toArray(), $this->default_field);
190 190
         $tpl = $this->get('template');
191 191
         $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
192
-        foreach ($tvTPL as $item) {
193
-            if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
192
+        foreach ($tvTPL as $item) {
193
+            if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
194 194
                 $out[$this->tvid[$item]] = $this->get($this->tvid[$item]);
195 195
             }
196 196
         }
197
-        if ($render) {
198
-            foreach ($out as $key => $val) {
197
+        if ($render) {
198
+            foreach ($out as $key => $val) {
199 199
                 $out[$key] = $this->renderTV($key);
200 200
             }
201 201
         }
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
      * @param bool $render
211 211
      * @return array
212 212
      */
213
-    public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true)
214
-    {
213
+    public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true)
214
+    {
215 215
         $out = array_merge(
216 216
             $this->toArrayMain(),
217 217
             $this->toArrayTV($render),
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
     /**
225 225
      * @return null|string
226 226
      */
227
-    public function getUrl()
228
-    {
227
+    public function getUrl()
228
+    {
229 229
         $out = null;
230 230
         $id = (int)$this->getID();
231
-        if (!empty($id)) {
231
+        if (!empty($id)) {
232 232
             $out = $this->modx->makeUrl($id);
233 233
         }
234 234
 
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
      * @param string $second
241 241
      * @return mixed
242 242
      */
243
-    public function getTitle($main = 'menutitle', $second = 'pagetitle')
244
-    {
243
+    public function getTitle($main = 'menutitle', $second = 'pagetitle')
244
+    {
245 245
         $title = $this->get($main);
246
-        if (empty($title) && $title !== '0') {
246
+        if (empty($title) && $title !== '0') {
247 247
             $title = $this->get($second);
248 248
         }
249 249
 
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
     /**
254 254
      * @return bool
255 255
      */
256
-    public function isWebShow()
257
-    {
256
+    public function isWebShow()
257
+    {
258 258
         $pub = ($this->get('publishedon') < time() && $this->get('published'));
259 259
         $unpub = ($this->get('unpub_date') == 0 || $this->get('unpub_date') > time());
260 260
         $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time()));
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
     /**
266 266
      * @return $this
267 267
      */
268
-    public function touch()
269
-    {
268
+    public function touch()
269
+    {
270 270
         $this->set('editedon', time());
271 271
 
272 272
         return $this;
@@ -276,14 +276,14 @@  discard block
 block discarded – undo
276 276
      * @param $tvname
277 277
      * @return null|string
278 278
      */
279
-    public function renderTV($tvname)
280
-    {
279
+    public function renderTV($tvname)
280
+    {
281 281
         $out = null;
282
-        if ($this->getID() > 0) {
282
+        if ($this->getID() > 0) {
283 283
             include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php";
284 284
             include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php";
285 285
             $tvval = $this->get($tvname);
286
-            if ($this->isTVarrayField($tvname) && is_array($tvval)) {
286
+            if ($this->isTVarrayField($tvname) && is_array($tvval)) {
287 287
                 $tvval = implode('||', $tvval);
288 288
             }
289 289
             $param = APIHelpers::getkey($this->tvd, $tvname, array());
@@ -300,14 +300,14 @@  discard block
 block discarded – undo
300 300
      * @param $key
301 301
      * @return mixed
302 302
      */
303
-    public function get($key)
304
-    {
303
+    public function get($key)
304
+    {
305 305
         $out = parent::get($key);
306
-        if (isset($this->tv[$key])) {
306
+        if (isset($this->tv[$key])) {
307 307
             $tpl = $this->get('template');
308 308
             $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
309 309
             $tvID = APIHelpers::getkey($this->tv, $key, 0);
310
-            if (in_array($tvID, $tvTPL) && is_null($out)) {
310
+            if (in_array($tvID, $tvTPL) && is_null($out)) {
311 311
                 $out = APIHelpers::getkey($this->tvd[$key], 'value', null);
312 312
             }
313 313
         }
@@ -320,10 +320,10 @@  discard block
 block discarded – undo
320 320
      * @param $value
321 321
      * @return $this
322 322
      */
323
-    public function set($key, $value)
324
-    {
325
-        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
326
-            switch ($key) {
323
+    public function set($key, $value)
324
+    {
325
+        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
326
+            switch ($key) {
327 327
                 case 'parent':
328 328
                     $value = (int)$value;
329 329
                     break;
@@ -333,38 +333,38 @@  discard block
 block discarded – undo
333 333
                     break;
334 334
                 case 'published':
335 335
                     $value = (int)((bool)$value);
336
-                    if ($value) {
336
+                    if ($value) {
337 337
                         $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time');
338 338
                     }
339 339
                     break;
340 340
                 case 'pub_date':
341 341
                     $value = $this->getTime($value);
342
-                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
342
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
343 343
                         $this->field['published'] = 1;
344 344
                         $this->field['publishedon'] = $value;
345 345
                     }
346 346
                     break;
347 347
                 case 'unpub_date':
348 348
                     $value = $this->getTime($value);
349
-                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
349
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
350 350
                         $this->field['published'] = 0;
351 351
                         $this->field['publishedon'] = 0;
352 352
                     }
353 353
                     break;
354 354
                 case 'deleted':
355 355
                     $value = (int)((bool)$value);
356
-                    if ($value) {
356
+                    if ($value) {
357 357
                         $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time');
358
-                    } else {
358
+                    } else {
359 359
                         $this->field['deletedon'] = 0;
360 360
                     }
361 361
                     break;
362 362
                 case 'deletedon':
363 363
                     $value = $this->getTime($value);
364
-                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) {
364
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) {
365 365
                         $value = 0;
366 366
                     }
367
-                    if ($value) {
367
+                    if ($value) {
368 368
                         $this->field['deleted'] = 1;
369 369
                     }
370 370
                     break;
@@ -391,20 +391,20 @@  discard block
 block discarded – undo
391 391
      * @param int $default
392 392
      * @return int|mixed
393 393
      */
394
-    protected function getUser($value, $default = 0)
395
-    {
394
+    protected function getUser($value, $default = 0)
395
+    {
396 396
         $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0);
397 397
         $value = (int)$value;
398
-        if (!empty($value)) {
398
+        if (!empty($value)) {
399 399
             $by = $this->findUserBy($value);
400
-            $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
400
+            $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
401 401
                 return ($val->containsKey($by) && $val->get($by) === (string)$value);
402 402
             });
403
-            if (!$exists) {
403
+            if (!$exists) {
404 404
                 $value = 0;
405 405
             }
406 406
         }
407
-        if (empty($value)) {
407
+        if (empty($value)) {
408 408
             $value = empty($currentAdmin) ? $default : $currentAdmin;
409 409
         }
410 410
 
@@ -415,9 +415,9 @@  discard block
 block discarded – undo
415 415
      * @param $data
416 416
      * @return bool|string
417 417
      */
418
-    protected function findUserBy($data)
419
-    {
420
-        switch (true) {
418
+    protected function findUserBy($data)
419
+    {
420
+        switch (true) {
421 421
             case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)):
422 422
                 $find = 'id';
423 423
                 break;
@@ -438,14 +438,14 @@  discard block
 block discarded – undo
438 438
      * @param $value
439 439
      * @return int|mixed|string
440 440
      */
441
-    protected function getTime($value)
442
-    {
441
+    protected function getTime($value)
442
+    {
443 443
         $value = trim($value);
444
-        if (!empty($value)) {
445
-            if (!is_numeric($value)) {
444
+        if (!empty($value)) {
445
+            if (!is_numeric($value)) {
446 446
                 $value = (int)strtotime($value);
447 447
             }
448
-            if (!empty($value)) {
448
+            if (!empty($value)) {
449 449
                 $value += $this->modxConfig('server_offset_time');
450 450
             }
451 451
         }
@@ -457,11 +457,11 @@  discard block
 block discarded – undo
457 457
      * @param array $data
458 458
      * @return $this
459 459
      */
460
-    public function create($data = array())
461
-    {
460
+    public function create($data = array())
461
+    {
462 462
         $this->close();
463 463
         $fld = array();
464
-        foreach ($this->tvd as $name => $tv) {
464
+        foreach ($this->tvd as $name => $tv) {
465 465
             $fld[$name] = $tv['value'];
466 466
         };
467 467
         $this->store($fld);
@@ -479,10 +479,10 @@  discard block
 block discarded – undo
479 479
      * @param $id
480 480
      * @return $this
481 481
      */
482
-    public function edit($id)
483
-    {
482
+    public function edit($id)
483
+    {
484 484
         $id = is_scalar($id) ? trim($id) : '';
485
-        if ($this->getID() != $id) {
485
+        if ($this->getID() != $id) {
486 486
             $this->close();
487 487
             $this->markAllEncode();
488 488
             $this->newDoc = false;
@@ -490,12 +490,12 @@  discard block
 block discarded – undo
490 490
             $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id);
491 491
             $this->fromArray($this->modx->db->getRow($result));
492 492
             $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id);
493
-            while ($row = $this->modx->db->getRow($result)) {
493
+            while ($row = $this->modx->db->getRow($result)) {
494 494
                 $this->field[$this->tvid[$row['tmplvarid']]] = $row['value'];
495 495
             }
496
-            if (empty($this->field['id'])) {
496
+            if (empty($this->field['id'])) {
497 497
                 $this->id = null;
498
-            } else {
498
+            } else {
499 499
                 $this->id = $this->field['id'];
500 500
                 $this->set('editedby', null)->touch();
501 501
                 $this->decodeFields();
@@ -512,10 +512,10 @@  discard block
 block discarded – undo
512 512
      * @param bool $clearCache
513 513
      * @return bool|null
514 514
      */
515
-    public function save($fire_events = false, $clearCache = false)
516
-    {
515
+    public function save($fire_events = false, $clearCache = false)
516
+    {
517 517
         $parent = null;
518
-        if ($this->field['pagetitle'] == '') {
518
+        if ($this->field['pagetitle'] == '') {
519 519
             $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>';
520 520
 
521 521
             return false;
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
             $this->field['parent'] == 0 &&
528 528
             !$this->modxConfig('udperms_allowroot') &&
529 529
             !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1)
530
-        ) {
530
+        ) {
531 531
             $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off';
532 532
 
533 533
             return false;
@@ -543,11 +543,11 @@  discard block
 block discarded – undo
543 543
         ), $fire_events);
544 544
 
545 545
         $fld = $this->encodeFields()->toArray(null, null, null, false);
546
-        foreach ($this->default_field as $key => $value) {
546
+        foreach ($this->default_field as $key => $value) {
547 547
             $tmp = $this->get($key);
548
-            if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
549
-                if ($tmp == $value) {
550
-                    switch ($key) {
548
+            if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
549
+                if ($tmp == $value) {
550
+                    switch ($key) {
551 551
                         case 'cacheable':
552 552
                             $value = $this->modxConfig('cache_default');
553 553
                             break;
@@ -567,11 +567,11 @@  discard block
 block discarded – undo
567 567
                 }
568 568
                 $this->field[$key] = $value;
569 569
             }
570
-            switch (true) {
570
+            switch (true) {
571 571
                 case $key == 'parent':
572 572
                     $parent = (int)$this->get($key);
573 573
                     $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'");
574
-                    if ($this->modx->db->getValue($q) != 1) {
574
+                    if ($this->modx->db->getValue($q) != 1) {
575 575
                         $parent = 0;
576 576
                     }
577 577
                     $this->field[$key] = $parent;
@@ -586,71 +586,73 @@  discard block
 block discarded – undo
586 586
             unset($fld[$key]);
587 587
         }
588 588
 
589
-        if (!empty($this->set)) {
590
-            if ($this->newDoc) {
589
+        if (!empty($this->set)) {
590
+            if ($this->newDoc) {
591 591
                 $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set);
592
-            } else {
592
+            } else {
593 593
                 $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ',
594 594
                         $this->set) . " WHERE `id` = " . $this->id;
595 595
             }
596 596
             $this->query($SQL);
597 597
 
598
-            if ($this->newDoc) {
598
+            if ($this->newDoc) {
599 599
                 $this->id = $this->modx->db->getInsertId();
600 600
             }
601 601
 
602
-            if ($parent > 0) {
602
+            if ($parent > 0) {
603 603
                 $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'");
604 604
             }
605 605
         }
606 606
 
607 607
         $_deleteTVs = $_updateTVs = $_insertTVs = array();
608
-        foreach ($fld as $key => $value) {
609
-            if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) {
608
+        foreach ($fld as $key => $value) {
609
+            if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) {
610 610
                 continue;
611
-            } elseif ($value === '') {
611
+            } elseif ($value === '') {
612 612
                 $_deleteTVs[] = $this->tv[$key];
613
-            } else {
613
+            } else {
614 614
                 $_insertTVs[$this->tv[$key]] = $this->escape($value);
615 615
             }
616 616
         }
617 617
 
618
-        if (!$this->newDoc && !empty($_insertTVs)) {
618
+        if (!$this->newDoc && !empty($_insertTVs)) {
619 619
             $ids = implode(',', array_keys($_insertTVs));
620 620
             $result = $this->query("SELECT `tmplvarid` FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid`={$this->id} AND `tmplvarid` IN ({$ids})");
621 621
             $existedTVs = $this->modx->db->getColumn('tmplvarid', $result);
622
-            foreach ($existedTVs as $id) {
622
+            foreach ($existedTVs as $id) {
623 623
                 $_updateTVs[$id] = $_insertTVs[$id];
624 624
                 unset($_insertTVs[$id]);
625 625
             }
626 626
         }
627 627
 
628
-        if (!empty($_updateTVs)) {
629
-            foreach ($_updateTVs as $id => $value) {
628
+        if (!empty($_updateTVs)) {
629
+            foreach ($_updateTVs as $id => $value) {
630 630
                 $this->query("UPDATE {$this->makeTable('site_tmplvar_contentvalues')} SET `value` = '{$value}' WHERE `contentid` = {$this->id} AND `tmplvarid` = {$id}");
631 631
             }
632 632
         }
633 633
 
634
-        if (!empty($_insertTVs)) {
634
+        if (!empty($_insertTVs)) {
635 635
             $values = array();
636
-            foreach ($_insertTVs as $id => $value) {
636
+            foreach ($_insertTVs as $id => $value) {
637 637
                 $values[] = "({$this->id}, {$id}, '{$value}')";
638 638
             }
639 639
             $values = implode(',', $values);
640 640
             $this->query("INSERT into {$this->makeTable('site_tmplvar_contentvalues')} (`contentid`,`tmplvarid`,`value`) VALUES {$values}");
641 641
         }
642 642
 
643
-        if (!empty($_deleteTVs)) {
643
+        if (!empty($_deleteTVs)) {
644 644
             $ids = implode(',', $_deleteTVs);
645 645
             $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})");
646 646
         }
647 647
 
648
-        if (!isset($this->mode)) {
648
+        if (!isset($this->mode)) {
649 649
             $this->mode = $this->newDoc ? "new" : "upd";
650 650
             $this->newDoc = false;
651 651
         }
652 652
 
653
-        if ($this->groupIds) $this->setDocumentGroups($this->id, $this->groupIds);
653
+        if ($this->groupIds) {
654
+            $this->setDocumentGroups($this->id, $this->groupIds);
655
+        }
654 656
         $this->invokeEvent('OnDocFormSave', array(
655 657
             'mode'   => $this->mode,
656 658
             'id'     => $this->id,
@@ -658,7 +660,7 @@  discard block
 block discarded – undo
658 660
             'docObj' => $this
659 661
         ), $fire_events);
660 662
 
661
-        if ($clearCache) {
663
+        if ($clearCache) {
662 664
             $this->clearCache($fire_events);
663 665
         }
664 666
         $this->decodeFields();
@@ -670,7 +672,8 @@  discard block
 block discarded – undo
670 672
      * @param $tvId
671 673
      * @return bool
672 674
      */
673
-    protected function belongsToTemplate($tvId) {
675
+    protected function belongsToTemplate($tvId)
676
+    {
674 677
         $template = $this->get('template');
675 678
         return in_array($tvId, $this->tvTpl[$template]);
676 679
     }
@@ -680,16 +683,16 @@  discard block
 block discarded – undo
680 683
      * @return $this
681 684
      * @throws Exception
682 685
      */
683
-    public function toTrash($ids)
684
-    {
686
+    public function toTrash($ids)
687
+    {
685 688
         $ignore = $this->systemID();
686 689
         $_ids = $this->cleanIDs($ids, ',', $ignore);
687
-        if (is_array($_ids) && $_ids != array()) {
690
+        if (is_array($_ids) && $_ids != array()) {
688 691
             $id = $this->sanitarIn($_ids);
689 692
             $uid = (int)$this->modx->getLoginUserId();
690 693
             $deletedon = time() + $this->modxConfig('server_offset_time');
691 694
             $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})");
692
-        } else {
695
+        } else {
693 696
             throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids,
694 697
                     1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
695 698
         }
@@ -701,11 +704,11 @@  discard block
 block discarded – undo
701 704
      * @param bool $fire_events
702 705
      * @return $this
703 706
      */
704
-    public function clearTrash($fire_events = false)
705
-    {
707
+    public function clearTrash($fire_events = false)
708
+    {
706 709
         $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'");
707 710
         $_ids = $this->modx->db->getColumn('id', $q);
708
-        if (is_array($_ids) && $_ids != array()) {
711
+        if (is_array($_ids) && $_ids != array()) {
709 712
             $this->invokeEvent('OnBeforeEmptyTrash', array(
710 713
                 "ids" => $_ids
711 714
             ), $fire_events);
@@ -727,15 +730,15 @@  discard block
 block discarded – undo
727 730
      * @param int|bool $depth
728 731
      * @return array
729 732
      */
730
-    public function children($ids, $depth)
731
-    {
733
+    public function children($ids, $depth)
734
+    {
732 735
         $_ids = $this->cleanIDs($ids, ',');
733
-        if (is_array($_ids) && $_ids != array()) {
736
+        if (is_array($_ids) && $_ids != array()) {
734 737
             $id = $this->sanitarIn($_ids);
735
-            if (!empty($id)) {
738
+            if (!empty($id)) {
736 739
                 $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})");
737 740
                 $id = $this->modx->db->getColumn('id', $q);
738
-                if ($depth > 0 || $depth === true) {
741
+                if ($depth > 0 || $depth === true) {
739 742
                     $id = $this->children($id, is_bool($depth) ? $depth : ($depth - 1));
740 743
                 }
741 744
                 $_ids = array_merge($_ids, $id);
@@ -751,8 +754,8 @@  discard block
 block discarded – undo
751 754
      * @return $this
752 755
      * @throws Exception
753 756
      */
754
-    public function delete($ids, $fire_events = false)
755
-    {
757
+    public function delete($ids, $fire_events = false)
758
+    {
756 759
         $ids = $this->children($ids, true);
757 760
         $_ids = $this->cleanIDs($ids, ',', $this->systemID());
758 761
         $this->invokeEvent('OnBeforeDocFormDelete', array(
@@ -769,8 +772,8 @@  discard block
 block discarded – undo
769 772
     /**
770 773
      * @return array
771 774
      */
772
-    private function systemID()
773
-    {
775
+    private function systemID()
776
+    {
774 777
         $ignore = array(
775 778
             0, //empty document
776 779
             (int)$this->modxConfig('site_start'),
@@ -780,7 +783,7 @@  discard block
 block discarded – undo
780 783
         );
781 784
         $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''");
782 785
         $data = $this->modx->db->makeArray($data);
783
-        foreach ($data as $item) {
786
+        foreach ($data as $item) {
784 787
             $ignore[] = (int)$item['setting_value'];
785 788
         }
786 789
 
@@ -792,22 +795,22 @@  discard block
 block discarded – undo
792 795
      * @param $alias
793 796
      * @return string
794 797
      */
795
-    protected function checkAlias($alias)
796
-    {
798
+    protected function checkAlias($alias)
799
+    {
797 800
         $alias = strtolower($alias);
798
-        if ($this->modxConfig('friendly_urls')) {
801
+        if ($this->modxConfig('friendly_urls')) {
799 802
             $_alias = $this->escape($alias);
800
-            if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
803
+            if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
801 804
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1"));
802
-            } else {
805
+            } else {
803 806
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1"));
804 807
             }
805
-            if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
808
+            if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
806 809
                 $suffix = substr($alias, -2);
807
-                if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
810
+                if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
808 811
                     $suffix = (int)$tmp[1] + 1;
809 812
                     $alias = substr($alias, 0, -2) . '-' . $suffix;
810
-                } else {
813
+                } else {
811 814
                     $alias .= '-2';
812 815
                 }
813 816
                 $alias = $this->checkAlias($alias);
@@ -821,8 +824,8 @@  discard block
 block discarded – undo
821 824
      * @param $key
822 825
      * @return bool
823 826
      */
824
-    public function issetField($key)
825
-    {
827
+    public function issetField($key)
828
+    {
826 829
         return (array_key_exists($key, $this->default_field) || array_key_exists($key, $this->tv));
827 830
     }
828 831
 
@@ -830,11 +833,11 @@  discard block
 block discarded – undo
830 833
      * @param bool $reload
831 834
      * @return $this
832 835
      */
833
-    protected function get_TV($reload = false)
834
-    {
835
-        if (empty($this->modx->_TVnames) || $reload) {
836
+    protected function get_TV($reload = false)
837
+    {
838
+        if (empty($this->modx->_TVnames) || $reload) {
836 839
             $result = $this->query('SELECT `id`,`name`,`type` FROM ' . $this->makeTable('site_tmplvars'));
837
-            while ($row = $this->modx->db->GetRow($result)) {
840
+            while ($row = $this->modx->db->GetRow($result)) {
838 841
                 $this->modx->_TVnames[$row['name']] = array(
839 842
                     "id"   => $row['id'],
840 843
                     "type" => $row['type']
@@ -843,14 +846,16 @@  discard block
 block discarded – undo
843 846
         }
844 847
         $arrayTypes = array('checkbox', 'listbox-multiple');
845 848
         $arrayTVs = array();
846
-        foreach ($this->modx->_TVnames as $name => $data) {
849
+        foreach ($this->modx->_TVnames as $name => $data) {
847 850
             $this->tvid[$data['id']] = $name;
848 851
             $this->tv[$name] = $data['id'];
849
-            if (in_array($data['type'], $arrayTypes)) {
852
+            if (in_array($data['type'], $arrayTypes)) {
850 853
                 $arrayTVs[] = $name;
851 854
             }
852 855
         }
853
-        if (empty($this->tvaFields)) $this->tvaFields = $arrayTVs;
856
+        if (empty($this->tvaFields)) {
857
+            $this->tvaFields = $arrayTVs;
858
+        }
854 859
         $this->loadTVTemplate()->loadTVDefault(array_values($this->tv));
855 860
 
856 861
         return $this;
@@ -859,12 +864,12 @@  discard block
 block discarded – undo
859 864
     /**
860 865
      * @return $this
861 866
      */
862
-    protected function loadTVTemplate()
863
-    {
867
+    protected function loadTVTemplate()
868
+    {
864 869
         $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates'));
865 870
         $q = $this->modx->db->makeArray($q);
866 871
         $this->tvTpl = array();
867
-        foreach ($q as $item) {
872
+        foreach ($q as $item) {
868 873
             $this->tvTpl[$item['templateid']][] = $item['tmplvarid'];
869 874
         }
870 875
 
@@ -875,16 +880,16 @@  discard block
 block discarded – undo
875 880
      * @param array $tvId
876 881
      * @return $this
877 882
      */
878
-    protected function loadTVDefault(array $tvId = array())
879
-    {
880
-        if (is_array($tvId) && !empty($tvId)) {
883
+    protected function loadTVDefault(array $tvId = array())
884
+    {
885
+        if (is_array($tvId) && !empty($tvId)) {
881 886
             $tbl_site_tmplvars = $this->makeTable('site_tmplvars');
882 887
             $fields = 'id,name,default_text as value,display,display_params,type';
883 888
             $implodeTvId = implode(',', $tvId);
884 889
             $rs = $this->query("SELECT {$fields} FROM {$tbl_site_tmplvars} WHERE id IN({$implodeTvId})");
885 890
             $rows = $this->modx->db->makeArray($rs);
886 891
             $this->tvd = array();
887
-            foreach ($rows as $item) {
892
+            foreach ($rows as $item) {
888 893
                 $this->tvd[$item['name']] = $item;
889 894
             }
890 895
         }
@@ -897,17 +902,17 @@  discard block
 block discarded – undo
897 902
      * @return int
898 903
      * @throws Exception
899 904
      */
900
-    public function setTemplate($tpl)
901
-    {
902
-        if (!is_numeric($tpl) || $tpl != (int)$tpl) {
903
-            if (is_scalar($tpl)) {
905
+    public function setTemplate($tpl)
906
+    {
907
+        if (!is_numeric($tpl) || $tpl != (int)$tpl) {
908
+            if (is_scalar($tpl)) {
904 909
                 $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'";
905 910
                 $rs = $this->query($sql);
906
-                if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
911
+                if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
907 912
                     throw new Exception("Template {$tpl} is not exists");
908 913
                 }
909 914
                 $tpl = $this->modx->db->getValue($rs);
910
-            } else {
915
+            } else {
911 916
                 throw new Exception("Invalid template name: " . print_r($tpl, 1));
912 917
             }
913 918
         }
@@ -918,14 +923,14 @@  discard block
 block discarded – undo
918 923
     /**
919 924
      * @return string
920 925
      */
921
-    protected function getAlias()
922
-    {
923
-        if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') {
926
+    protected function getAlias()
927
+    {
928
+        if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') {
924 929
             $alias = strtr($this->get('pagetitle'), $this->table);
925
-        } else {
926
-            if ($this->get('alias') != '') {
930
+        } else {
931
+            if ($this->get('alias') != '') {
927 932
                 $alias = $this->get('alias');
928
-            } else {
933
+            } else {
929 934
                 $alias = '';
930 935
             }
931 936
         }
@@ -942,10 +947,10 @@  discard block
 block discarded – undo
942 947
      *
943 948
      * Пересчет menuindex по полю таблицы site_content
944 949
      */
945
-    public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc')
946
-    {
950
+    public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc')
951
+    {
947 952
         $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc';
948
-        if (is_integer($parent) && $criteria !== '') {
953
+        if (is_integer($parent) && $criteria !== '') {
949 954
             $this->query("SET @index := 0");
950 955
             $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}");
951 956
         }
@@ -958,37 +963,37 @@  discard block
 block discarded – undo
958 963
      *
959 964
      * @return $this
960 965
      */
961
-    public function setDefaultTemplate()
962
-    {
966
+    public function setDefaultTemplate()
967
+    {
963 968
         $parent = $this->get('parent');
964 969
         $template = $this->modxConfig('default_template');
965
-        switch ($this->modxConfig('auto_template_logic')) {
970
+        switch ($this->modxConfig('auto_template_logic')) {
966 971
             case 'sibling':
967
-                if (!$parent) {
972
+                if (!$parent) {
968 973
                     $site_start = $this->modxConfig('site_start');
969 974
                     $where = "sc.isfolder=0 AND sc.id!={$site_start}";
970 975
                     $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1);
971
-                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
976
+                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
972 977
                         $template = $sibl[0]['template'];
973 978
                     }
974
-                } else {
979
+                } else {
975 980
                     $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', 'isfolder=0', 'menuindex',
976 981
                         'ASC', 1);
977
-                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
982
+                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
978 983
                         $template = $sibl[0]['template'];
979
-                    } else {
984
+                    } else {
980 985
                         $sibl = $this->modx->getDocumentChildren($parent, 0, 0, 'template', 'isfolder=0', 'menuindex',
981 986
                             'ASC', 1);
982
-                        if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
987
+                        if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
983 988
                             $template = $sibl[0]['template'];
984 989
                         }
985 990
                     }
986 991
                 }
987 992
                 break;
988 993
             case 'parent':
989
-                if ($parent) {
994
+                if ($parent) {
990 995
                     $_parent = $this->modx->getPageInfo($parent, 0, 'template');
991
-                    if (isset($_parent['template'])) {
996
+                    if (isset($_parent['template'])) {
992 997
                         $template = $_parent['template'];
993 998
                     }
994 999
                 }
@@ -1005,18 +1010,18 @@  discard block
 block discarded – undo
1005 1010
      * @param  bool $store обновить распакованное поле
1006 1011
      * @return array ассоциативный массив с данными из json строки
1007 1012
      */
1008
-    public function decodeField($field, $store = false)
1009
-    {
1013
+    public function decodeField($field, $store = false)
1014
+    {
1010 1015
         $out = array();
1011
-        if ($this->isDecodableField($field)) {
1016
+        if ($this->isDecodableField($field)) {
1012 1017
             $data = $this->get($field);
1013
-            if ($this->isTVarrayField($field)) {
1018
+            if ($this->isTVarrayField($field)) {
1014 1019
                 $out = explode('||', $data);
1015
-            } else {
1020
+            } else {
1016 1021
                 $out = jsonHelper::jsonDecode($data, array('assoc' => true), true);
1017 1022
             }
1018 1023
         }
1019
-        if ($store) {
1024
+        if ($store) {
1020 1025
             $this->field[$field] = $out;
1021 1026
             $this->markAsDecode($field);
1022 1027
         }
@@ -1030,18 +1035,18 @@  discard block
 block discarded – undo
1030 1035
      * @param  bool $store обновить запакованное поле
1031 1036
      * @return string|null json строка
1032 1037
      */
1033
-    public function encodeField($field, $store = false)
1034
-    {
1038
+    public function encodeField($field, $store = false)
1039
+    {
1035 1040
         $out = null;
1036
-        if ($this->isEncodableField($field)) {
1041
+        if ($this->isEncodableField($field)) {
1037 1042
             $data = $this->get($field);
1038
-            if ($this->isTVarrayField($field)) {
1043
+            if ($this->isTVarrayField($field)) {
1039 1044
                 $out = is_array($data) ? implode('||', $data) : $data;
1040
-            } else {
1045
+            } else {
1041 1046
                 $out = json_encode($data);
1042 1047
             }
1043 1048
         }
1044
-        if ($store) {
1049
+        if ($store) {
1045 1050
             $this->field[$field] = $out;
1046 1051
             $this->markAsEncode($field);
1047 1052
         }
@@ -1054,8 +1059,8 @@  discard block
 block discarded – undo
1054 1059
      * @param  string $field имя поля
1055 1060
      * @return boolean
1056 1061
      */
1057
-    public function isTVarrayField($field)
1058
-    {
1062
+    public function isTVarrayField($field)
1063
+    {
1059 1064
         return (is_scalar($field) && in_array($field, $this->tvaFields));
1060 1065
     }
1061 1066
 
@@ -1063,10 +1068,10 @@  discard block
 block discarded – undo
1063 1068
      * Пометить все поля как запакованные
1064 1069
      * @return $this
1065 1070
      */
1066
-    public function markAllEncode()
1067
-    {
1071
+    public function markAllEncode()
1072
+    {
1068 1073
         parent::markAllEncode();
1069
-        foreach ($this->tvaFields as $field) {
1074
+        foreach ($this->tvaFields as $field) {
1070 1075
             $this->markAsEncode($field);
1071 1076
         }
1072 1077
 
@@ -1077,10 +1082,10 @@  discard block
 block discarded – undo
1077 1082
      * Пометить все поля как распакованные
1078 1083
      * @return $this
1079 1084
      */
1080
-    public function markAllDecode()
1081
-    {
1085
+    public function markAllDecode()
1086
+    {
1082 1087
         parent::markAllDecode();
1083
-        foreach ($this->tvaFields as $field) {
1088
+        foreach ($this->tvaFields as $field) {
1084 1089
             $this->markAsDecode($field);
1085 1090
         }
1086 1091
 
@@ -1090,16 +1095,17 @@  discard block
 block discarded – undo
1090 1095
     /**
1091 1096
      * @param int $docId
1092 1097
      */
1093
-    public function getDocumentGroups($docId = 0) {
1098
+    public function getDocumentGroups($docId = 0)
1099
+    {
1094 1100
         $out = array();
1095 1101
         $doc = $this->switchObject($docId);
1096
-        if (null !== $doc->getID()) {
1102
+        if (null !== $doc->getID()) {
1097 1103
             $doc_groups = $this->makeTable('document_groups');
1098 1104
             $docgroup_names = $this->makeTable('documentgroup_names');
1099 1105
 
1100 1106
             $rs = $this->query("SELECT `dg`.`document_group`, `dgn`.`name` FROM {$doc_groups} as `dg` INNER JOIN {$docgroup_names} as `dgn` ON `dgn`.`id`=`dg`.`document_group`
1101 1107
                 WHERE `dg`.`document` = " . $doc->getID());
1102
-            while ($row = $this->modx->db->getRow($rs)) {
1108
+            while ($row = $this->modx->db->getRow($rs)) {
1103 1109
                 $out[$row['document_group']] = $row['name'];
1104 1110
             }
1105 1111
 
@@ -1114,18 +1120,20 @@  discard block
 block discarded – undo
1114 1120
      * @param array $groupIds
1115 1121
      * @return $this
1116 1122
      */
1117
-    public function setDocumentGroups($docId = 0, $groupIds = array())
1118
-    {
1119
-        if (!is_array($groupIds)) return $this;
1120
-        if ($this->newDoc && $docId == 0) {
1123
+    public function setDocumentGroups($docId = 0, $groupIds = array())
1124
+    {
1125
+        if (!is_array($groupIds)) {
1126
+            return $this;
1127
+        }
1128
+        if ($this->newDoc && $docId == 0) {
1121 1129
             $this->groupIds = $groupIds;
1122
-        } else {
1130
+        } else {
1123 1131
             $doc = $this->switchObject($docId);
1124
-            if ($id = $doc->getID()) {
1125
-                foreach ($groupIds as $gid) {
1132
+            if ($id = $doc->getID()) {
1133
+                foreach ($groupIds as $gid) {
1126 1134
                     $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')");
1127 1135
                 }
1128
-                if (!$this->newDoc) {
1136
+                if (!$this->newDoc) {
1129 1137
                     $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds);
1130 1138
                     $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})");
1131 1139
                 }
Please login to merge, or discard this patch.