Completed
Pull Request — master (#263)
by
unknown
02:10
created
assets/lib/MODxAPI/modResource.php 3 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         $tpl = $this->get('template');
190 190
         $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
191 191
         foreach ($tvTPL as $item) {
192
-            if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
192
+            if (isset($this->tvid[$item]) && ! array_key_exists($this->tvid[$item], $out)) {
193 193
                 $out[$this->tvid[$item]] = $this->get($this->tvid[$item]);
194 194
             }
195 195
         }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     {
228 228
         $out = null;
229 229
         $id = (int)$this->getID();
230
-        if (!empty($id)) {
230
+        if ( ! empty($id)) {
231 231
             $out = $this->modx->makeUrl($id);
232 232
         }
233 233
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
      */
322 322
     public function set($key, $value)
323 323
     {
324
-        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
324
+        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && ! empty($key)) {
325 325
             switch ($key) {
326 326
                 case 'parent':
327 327
                     $value = (int)$value;
@@ -394,12 +394,12 @@  discard block
 block discarded – undo
394 394
     {
395 395
         $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0);
396 396
         $value = (int)$value;
397
-        if (!empty($value)) {
397
+        if ( ! empty($value)) {
398 398
             $by = $this->findUserBy($value);
399
-            $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
399
+            $exists = $this->managerUsers->exists(function($key, Helpers\Collection $val) use ($by, $value) {
400 400
                 return ($val->containsKey($by) && $val->get($by) === (string)$value);
401 401
             });
402
-            if (!$exists) {
402
+            if ( ! $exists) {
403 403
                 $value = 0;
404 404
             }
405 405
         }
@@ -440,11 +440,11 @@  discard block
 block discarded – undo
440 440
     protected function getTime($value)
441 441
     {
442 442
         $value = trim($value);
443
-        if (!empty($value)) {
444
-            if (!is_numeric($value)) {
443
+        if ( ! empty($value)) {
444
+            if ( ! is_numeric($value)) {
445 445
                 $value = (int)strtotime($value);
446 446
             }
447
-            if (!empty($value)) {
447
+            if ( ! empty($value)) {
448 448
                 $value += $this->modxConfig('server_offset_time');
449 449
             }
450 450
         }
@@ -524,8 +524,8 @@  discard block
 block discarded – undo
524 524
 
525 525
         if (
526 526
             $this->field['parent'] == 0 &&
527
-            !$this->modxConfig('udperms_allowroot') &&
528
-            !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1)
527
+            ! $this->modxConfig('udperms_allowroot') &&
528
+            ! ($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1)
529 529
         ) {
530 530
             $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off';
531 531
 
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
         $fld = $this->encodeFields()->toArray(null, null, null, false);
545 545
         foreach ($this->default_field as $key => $value) {
546 546
             $tmp = $this->get($key);
547
-            if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
547
+            if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) {
548 548
                 if ($tmp == $value) {
549 549
                     switch ($key) {
550 550
                         case 'cacheable':
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
                     $this->field[$key] = $parent;
577 577
                     $this->Uset($key);
578 578
                     break;
579
-                case ($key == 'alias_visible' && !$this->checkVersion('1.0.10', true)):
579
+                case ($key == 'alias_visible' && ! $this->checkVersion('1.0.10', true)):
580 580
                     $this->eraseField('alias_visible');
581 581
                     break;
582 582
                 default:
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
             unset($fld[$key]);
586 586
         }
587 587
 
588
-        if (!empty($this->set)) {
588
+        if ( ! empty($this->set)) {
589 589
             if ($this->newDoc) {
590 590
                 $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set);
591 591
             } else {
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 
606 606
         $_deleteTVs = $_updateTVs = $_insertTVs = array();
607 607
         foreach ($fld as $key => $value) {
608
-            if (empty($this->tv[$key]) || !$this->isChanged($key)) {
608
+            if (empty($this->tv[$key]) || ! $this->isChanged($key)) {
609 609
                 continue;
610 610
             } elseif ($value === '') {
611 611
                 $_deleteTVs[] = $this->tv[$key];
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
             }
615 615
         }
616 616
 
617
-        if (!$this->newDoc && !empty($_insertTVs)) {
617
+        if ( ! $this->newDoc && ! empty($_insertTVs)) {
618 618
             $ids = implode(',', array_keys($_insertTVs));
619 619
             $result = $this->query("SELECT `tmplvarid` FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid`={$this->id} AND `tmplvarid` IN ({$ids})");
620 620
             $existedTVs = $this->modx->db->getColumn('tmplvarid', $result);
@@ -624,13 +624,13 @@  discard block
 block discarded – undo
624 624
             }
625 625
         }
626 626
 
627
-        if (!empty($_updateTVs)) {
627
+        if ( ! empty($_updateTVs)) {
628 628
             foreach ($_updateTVs as $id => $value) {
629 629
                 $this->query("UPDATE {$this->makeTable('site_tmplvar_contentvalues')} SET `value` = '{$value}' WHERE `contentid` = {$this->id} AND `tmplvarid` = {$id}");
630 630
             }
631 631
         }
632 632
 
633
-        if (!empty($_insertTVs)) {
633
+        if ( ! empty($_insertTVs)) {
634 634
             $values = array();
635 635
             foreach ($_insertTVs as $id => $value) {
636 636
                 $values[] = "({$this->id}, {$id}, '{$value}')";
@@ -639,12 +639,12 @@  discard block
 block discarded – undo
639 639
             $this->query("INSERT into {$this->makeTable('site_tmplvar_contentvalues')} (`contentid`,`tmplvarid`,`value`) VALUES {$values}");
640 640
         }
641 641
 
642
-        if (!empty($_deleteTVs)) {
642
+        if ( ! empty($_deleteTVs)) {
643 643
             $ids = implode(',', $_deleteTVs);
644 644
             $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})");
645 645
         }
646 646
 
647
-        if (!isset($this->mode)) {
647
+        if ( ! isset($this->mode)) {
648 648
             $this->mode = $this->newDoc ? "new" : "upd";
649 649
             $this->newDoc = false;
650 650
         }
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
         $_ids = $this->cleanIDs($ids, ',');
721 721
         if (is_array($_ids) && $_ids != array()) {
722 722
             $id = $this->sanitarIn($_ids);
723
-            if (!empty($id)) {
723
+            if ( ! empty($id)) {
724 724
                 $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})");
725 725
                 $id = $this->modx->db->getColumn('id', $q);
726 726
                 if ($depth > 0 || $depth === true) {
@@ -785,12 +785,12 @@  discard block
 block discarded – undo
785 785
         $alias = strtolower($alias);
786 786
         if ($this->modxConfig('friendly_urls')) {
787 787
             $_alias = $this->escape($alias);
788
-            if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
788
+            if (( ! $this->modxConfig('allow_duplicate_alias') && ! $this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
789 789
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1"));
790 790
             } else {
791 791
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1"));
792 792
             }
793
-            if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
793
+            if (($flag && $this->newDoc) || ( ! $this->newDoc && $flag && $this->id != $flag)) {
794 794
                 $suffix = substr($alias, -2);
795 795
                 if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
796 796
                     $suffix = (int)$tmp[1] + 1;
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
      */
866 866
     protected function loadTVDefault(array $tvId = array())
867 867
     {
868
-        if (is_array($tvId) && !empty($tvId)) {
868
+        if (is_array($tvId) && ! empty($tvId)) {
869 869
             $tbl_site_tmplvars = $this->makeTable('site_tmplvars');
870 870
             $fields = 'id,name,default_text as value,display,display_params,type';
871 871
             $implodeTvId = implode(',', $tvId);
@@ -887,11 +887,11 @@  discard block
 block discarded – undo
887 887
      */
888 888
     public function setTemplate($tpl)
889 889
     {
890
-        if (!is_numeric($tpl) || $tpl != (int)$tpl) {
890
+        if ( ! is_numeric($tpl) || $tpl != (int)$tpl) {
891 891
             if (is_scalar($tpl)) {
892 892
                 $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'";
893 893
                 $rs = $this->query($sql);
894
-                if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
894
+                if ( ! $rs || $this->modx->db->getRecordCount($rs) <= 0) {
895 895
                     throw new Exception("Template {$tpl} is not exists");
896 896
                 }
897 897
                 $tpl = $this->modx->db->getValue($rs);
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
         $template = $this->modxConfig('default_template');
953 953
         switch ($this->modxConfig('auto_template_logic')) {
954 954
             case 'sibling':
955
-                if (!$parent) {
955
+                if ( ! $parent) {
956 956
                     $site_start = $this->modxConfig('site_start');
957 957
                     $where = "sc.isfolder=0 AND sc.id!={$site_start}";
958 958
                     $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1);
Please login to merge, or discard this patch.
Braces   +183 added lines, -181 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
      */
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
      * @param DocumentParser $modx
159 159
      * @param bool $debug
160 160
      */
161
-    public function __construct($modx, $debug = false)
162
-    {
161
+    public function __construct($modx, $debug = false)
162
+    {
163 163
         parent::__construct($modx, $debug);
164 164
         $this->get_TV();
165 165
         $uTable = $this->makeTable("manager_users");
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
     /**
173 173
      * @return array
174 174
      */
175
-    public function toArrayMain()
176
-    {
175
+    public function toArrayMain()
176
+    {
177 177
         $out = array_intersect_key(parent::toArray(), $this->default_field);
178 178
 
179 179
         return $out;
@@ -183,18 +183,18 @@  discard block
 block discarded – undo
183 183
      * @param bool $render
184 184
      * @return array
185 185
      */
186
-    public function toArrayTV($render = false)
187
-    {
186
+    public function toArrayTV($render = false)
187
+    {
188 188
         $out = array_diff_key(parent::toArray(), $this->default_field);
189 189
         $tpl = $this->get('template');
190 190
         $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
191
-        foreach ($tvTPL as $item) {
192
-            if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
191
+        foreach ($tvTPL as $item) {
192
+            if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
193 193
                 $out[$this->tvid[$item]] = $this->get($this->tvid[$item]);
194 194
             }
195 195
         }
196
-        if ($render) {
197
-            foreach ($out as $key => $val) {
196
+        if ($render) {
197
+            foreach ($out as $key => $val) {
198 198
                 $out[$key] = $this->renderTV($key);
199 199
             }
200 200
         }
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
      * @param bool $render
210 210
      * @return array
211 211
      */
212
-    public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true)
213
-    {
212
+    public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true)
213
+    {
214 214
         $out = array_merge(
215 215
             $this->toArrayMain(),
216 216
             $this->toArrayTV($render),
@@ -223,11 +223,11 @@  discard block
 block discarded – undo
223 223
     /**
224 224
      * @return null|string
225 225
      */
226
-    public function getUrl()
227
-    {
226
+    public function getUrl()
227
+    {
228 228
         $out = null;
229 229
         $id = (int)$this->getID();
230
-        if (!empty($id)) {
230
+        if (!empty($id)) {
231 231
             $out = $this->modx->makeUrl($id);
232 232
         }
233 233
 
@@ -239,10 +239,10 @@  discard block
 block discarded – undo
239 239
      * @param string $second
240 240
      * @return mixed
241 241
      */
242
-    public function getTitle($main = 'menutitle', $second = 'pagetitle')
243
-    {
242
+    public function getTitle($main = 'menutitle', $second = 'pagetitle')
243
+    {
244 244
         $title = $this->get($main);
245
-        if (empty($title) && $title !== '0') {
245
+        if (empty($title) && $title !== '0') {
246 246
             $title = $this->get($second);
247 247
         }
248 248
 
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
     /**
253 253
      * @return bool
254 254
      */
255
-    public function isWebShow()
256
-    {
255
+    public function isWebShow()
256
+    {
257 257
         $pub = ($this->get('publishedon') < time() && $this->get('published'));
258 258
         $unpub = ($this->get('unpub_date') == 0 || $this->get('unpub_date') > time());
259 259
         $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time()));
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
     /**
265 265
      * @return $this
266 266
      */
267
-    public function touch()
268
-    {
267
+    public function touch()
268
+    {
269 269
         $this->set('editedon', time());
270 270
 
271 271
         return $this;
@@ -275,14 +275,14 @@  discard block
 block discarded – undo
275 275
      * @param $tvname
276 276
      * @return null|string
277 277
      */
278
-    public function renderTV($tvname)
279
-    {
278
+    public function renderTV($tvname)
279
+    {
280 280
         $out = null;
281
-        if ($this->getID() > 0) {
281
+        if ($this->getID() > 0) {
282 282
             include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php";
283 283
             include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php";
284 284
             $tvval = $this->get($tvname);
285
-            if ($this->isTVarrayField($tvname) && is_array($tvval)) {
285
+            if ($this->isTVarrayField($tvname) && is_array($tvval)) {
286 286
                 $tvval = implode('||', $tvval);
287 287
             }
288 288
             $param = APIHelpers::getkey($this->tvd, $tvname, array());
@@ -299,14 +299,14 @@  discard block
 block discarded – undo
299 299
      * @param $key
300 300
      * @return mixed
301 301
      */
302
-    public function get($key)
303
-    {
302
+    public function get($key)
303
+    {
304 304
         $out = parent::get($key);
305
-        if (isset($this->tv[$key])) {
305
+        if (isset($this->tv[$key])) {
306 306
             $tpl = $this->get('template');
307 307
             $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
308 308
             $tvID = APIHelpers::getkey($this->tv, $key, 0);
309
-            if (in_array($tvID, $tvTPL) && is_null($out)) {
309
+            if (in_array($tvID, $tvTPL) && is_null($out)) {
310 310
                 $out = APIHelpers::getkey($this->tvd[$key], 'value', null);
311 311
             }
312 312
         }
@@ -319,10 +319,10 @@  discard block
 block discarded – undo
319 319
      * @param $value
320 320
      * @return $this
321 321
      */
322
-    public function set($key, $value)
323
-    {
324
-        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
325
-            switch ($key) {
322
+    public function set($key, $value)
323
+    {
324
+        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
325
+            switch ($key) {
326 326
                 case 'parent':
327 327
                     $value = (int)$value;
328 328
                     break;
@@ -332,38 +332,38 @@  discard block
 block discarded – undo
332 332
                     break;
333 333
                 case 'published':
334 334
                     $value = (int)((bool)$value);
335
-                    if ($value) {
335
+                    if ($value) {
336 336
                         $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time');
337 337
                     }
338 338
                     break;
339 339
                 case 'pub_date':
340 340
                     $value = $this->getTime($value);
341
-                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
341
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
342 342
                         $this->field['published'] = 1;
343 343
                         $this->field['publishedon'] = $value;
344 344
                     }
345 345
                     break;
346 346
                 case 'unpub_date':
347 347
                     $value = $this->getTime($value);
348
-                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
348
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
349 349
                         $this->field['published'] = 0;
350 350
                         $this->field['publishedon'] = 0;
351 351
                     }
352 352
                     break;
353 353
                 case 'deleted':
354 354
                     $value = (int)((bool)$value);
355
-                    if ($value) {
355
+                    if ($value) {
356 356
                         $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time');
357
-                    } else {
357
+                    } else {
358 358
                         $this->field['deletedon'] = 0;
359 359
                     }
360 360
                     break;
361 361
                 case 'deletedon':
362 362
                     $value = $this->getTime($value);
363
-                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) {
363
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) {
364 364
                         $value = 0;
365 365
                     }
366
-                    if ($value) {
366
+                    if ($value) {
367 367
                         $this->field['deleted'] = 1;
368 368
                     }
369 369
                     break;
@@ -390,20 +390,20 @@  discard block
 block discarded – undo
390 390
      * @param int $default
391 391
      * @return int|mixed
392 392
      */
393
-    protected function getUser($value, $default = 0)
394
-    {
393
+    protected function getUser($value, $default = 0)
394
+    {
395 395
         $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0);
396 396
         $value = (int)$value;
397
-        if (!empty($value)) {
397
+        if (!empty($value)) {
398 398
             $by = $this->findUserBy($value);
399
-            $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
399
+            $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
400 400
                 return ($val->containsKey($by) && $val->get($by) === (string)$value);
401 401
             });
402
-            if (!$exists) {
402
+            if (!$exists) {
403 403
                 $value = 0;
404 404
             }
405 405
         }
406
-        if (empty($value)) {
406
+        if (empty($value)) {
407 407
             $value = empty($currentAdmin) ? $default : $currentAdmin;
408 408
         }
409 409
 
@@ -414,9 +414,9 @@  discard block
 block discarded – undo
414 414
      * @param $data
415 415
      * @return bool|string
416 416
      */
417
-    protected function findUserBy($data)
418
-    {
419
-        switch (true) {
417
+    protected function findUserBy($data)
418
+    {
419
+        switch (true) {
420 420
             case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)):
421 421
                 $find = 'id';
422 422
                 break;
@@ -437,14 +437,14 @@  discard block
 block discarded – undo
437 437
      * @param $value
438 438
      * @return int|mixed|string
439 439
      */
440
-    protected function getTime($value)
441
-    {
440
+    protected function getTime($value)
441
+    {
442 442
         $value = trim($value);
443
-        if (!empty($value)) {
444
-            if (!is_numeric($value)) {
443
+        if (!empty($value)) {
444
+            if (!is_numeric($value)) {
445 445
                 $value = (int)strtotime($value);
446 446
             }
447
-            if (!empty($value)) {
447
+            if (!empty($value)) {
448 448
                 $value += $this->modxConfig('server_offset_time');
449 449
             }
450 450
         }
@@ -456,11 +456,11 @@  discard block
 block discarded – undo
456 456
      * @param array $data
457 457
      * @return $this
458 458
      */
459
-    public function create($data = array())
460
-    {
459
+    public function create($data = array())
460
+    {
461 461
         $this->close();
462 462
         $fld = array();
463
-        foreach ($this->tvd as $name => $tv) {
463
+        foreach ($this->tvd as $name => $tv) {
464 464
             $fld[$name] = $tv['value'];
465 465
         };
466 466
         $this->store($fld);
@@ -478,10 +478,10 @@  discard block
 block discarded – undo
478 478
      * @param $id
479 479
      * @return $this
480 480
      */
481
-    public function edit($id)
482
-    {
481
+    public function edit($id)
482
+    {
483 483
         $id = is_scalar($id) ? trim($id) : '';
484
-        if ($this->getID() != $id) {
484
+        if ($this->getID() != $id) {
485 485
             $this->close();
486 486
             $this->markAllEncode();
487 487
             $this->newDoc = false;
@@ -489,12 +489,12 @@  discard block
 block discarded – undo
489 489
             $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id);
490 490
             $this->fromArray($this->modx->db->getRow($result));
491 491
             $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id);
492
-            while ($row = $this->modx->db->getRow($result)) {
492
+            while ($row = $this->modx->db->getRow($result)) {
493 493
                 $this->field[$this->tvid[$row['tmplvarid']]] = $row['value'];
494 494
             }
495
-            if (empty($this->field['id'])) {
495
+            if (empty($this->field['id'])) {
496 496
                 $this->id = null;
497
-            } else {
497
+            } else {
498 498
                 $this->id = $this->field['id'];
499 499
                 $this->set('editedby', null)->touch();
500 500
                 $this->decodeFields();
@@ -511,10 +511,10 @@  discard block
 block discarded – undo
511 511
      * @param bool $clearCache
512 512
      * @return bool|null|void
513 513
      */
514
-    public function save($fire_events = false, $clearCache = false)
515
-    {
514
+    public function save($fire_events = false, $clearCache = false)
515
+    {
516 516
         $parent = null;
517
-        if ($this->field['pagetitle'] == '') {
517
+        if ($this->field['pagetitle'] == '') {
518 518
             $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>';
519 519
 
520 520
             return false;
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
             $this->field['parent'] == 0 &&
527 527
             !$this->modxConfig('udperms_allowroot') &&
528 528
             !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1)
529
-        ) {
529
+        ) {
530 530
             $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off';
531 531
 
532 532
             return false;
@@ -542,11 +542,11 @@  discard block
 block discarded – undo
542 542
         ), $fire_events);
543 543
 
544 544
         $fld = $this->encodeFields()->toArray(null, null, null, false);
545
-        foreach ($this->default_field as $key => $value) {
545
+        foreach ($this->default_field as $key => $value) {
546 546
             $tmp = $this->get($key);
547
-            if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
548
-                if ($tmp == $value) {
549
-                    switch ($key) {
547
+            if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
548
+                if ($tmp == $value) {
549
+                    switch ($key) {
550 550
                         case 'cacheable':
551 551
                             $value = $this->modxConfig('cache_default');
552 552
                             break;
@@ -566,11 +566,11 @@  discard block
 block discarded – undo
566 566
                 }
567 567
                 $this->field[$key] = $value;
568 568
             }
569
-            switch (true) {
569
+            switch (true) {
570 570
                 case $key == 'parent':
571 571
                     $parent = (int)$this->get($key);
572 572
                     $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'");
573
-                    if ($this->modx->db->getValue($q) != 1) {
573
+                    if ($this->modx->db->getValue($q) != 1) {
574 574
                         $parent = 0;
575 575
                     }
576 576
                     $this->field[$key] = $parent;
@@ -585,66 +585,66 @@  discard block
 block discarded – undo
585 585
             unset($fld[$key]);
586 586
         }
587 587
 
588
-        if (!empty($this->set)) {
589
-            if ($this->newDoc) {
588
+        if (!empty($this->set)) {
589
+            if ($this->newDoc) {
590 590
                 $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set);
591
-            } else {
591
+            } else {
592 592
                 $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ',
593 593
                         $this->set) . " WHERE `id` = " . $this->id;
594 594
             }
595 595
             $this->query($SQL);
596 596
 
597
-            if ($this->newDoc) {
597
+            if ($this->newDoc) {
598 598
                 $this->id = $this->modx->db->getInsertId();
599 599
             }
600 600
 
601
-            if ($parent > 0) {
601
+            if ($parent > 0) {
602 602
                 $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'");
603 603
             }
604 604
         }
605 605
 
606 606
         $_deleteTVs = $_updateTVs = $_insertTVs = array();
607
-        foreach ($fld as $key => $value) {
608
-            if (empty($this->tv[$key]) || !$this->isChanged($key)) {
607
+        foreach ($fld as $key => $value) {
608
+            if (empty($this->tv[$key]) || !$this->isChanged($key)) {
609 609
                 continue;
610
-            } elseif ($value === '') {
610
+            } elseif ($value === '') {
611 611
                 $_deleteTVs[] = $this->tv[$key];
612
-            } else {
612
+            } else {
613 613
                 $_insertTVs[$this->tv[$key]] = $this->escape($value);
614 614
             }
615 615
         }
616 616
 
617
-        if (!$this->newDoc && !empty($_insertTVs)) {
617
+        if (!$this->newDoc && !empty($_insertTVs)) {
618 618
             $ids = implode(',', array_keys($_insertTVs));
619 619
             $result = $this->query("SELECT `tmplvarid` FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid`={$this->id} AND `tmplvarid` IN ({$ids})");
620 620
             $existedTVs = $this->modx->db->getColumn('tmplvarid', $result);
621
-            foreach ($existedTVs as $id) {
621
+            foreach ($existedTVs as $id) {
622 622
                 $_updateTVs[$id] = $_insertTVs[$id];
623 623
                 unset($_insertTVs[$id]);
624 624
             }
625 625
         }
626 626
 
627
-        if (!empty($_updateTVs)) {
628
-            foreach ($_updateTVs as $id => $value) {
627
+        if (!empty($_updateTVs)) {
628
+            foreach ($_updateTVs as $id => $value) {
629 629
                 $this->query("UPDATE {$this->makeTable('site_tmplvar_contentvalues')} SET `value` = '{$value}' WHERE `contentid` = {$this->id} AND `tmplvarid` = {$id}");
630 630
             }
631 631
         }
632 632
 
633
-        if (!empty($_insertTVs)) {
633
+        if (!empty($_insertTVs)) {
634 634
             $values = array();
635
-            foreach ($_insertTVs as $id => $value) {
635
+            foreach ($_insertTVs as $id => $value) {
636 636
                 $values[] = "({$this->id}, {$id}, '{$value}')";
637 637
             }
638 638
             $values = implode(',', $values);
639 639
             $this->query("INSERT into {$this->makeTable('site_tmplvar_contentvalues')} (`contentid`,`tmplvarid`,`value`) VALUES {$values}");
640 640
         }
641 641
 
642
-        if (!empty($_deleteTVs)) {
642
+        if (!empty($_deleteTVs)) {
643 643
             $ids = implode(',', $_deleteTVs);
644 644
             $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})");
645 645
         }
646 646
 
647
-        if (!isset($this->mode)) {
647
+        if (!isset($this->mode)) {
648 648
             $this->mode = $this->newDoc ? "new" : "upd";
649 649
             $this->newDoc = false;
650 650
         }
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
             'docObj' => $this
656 656
         ), $fire_events);
657 657
 
658
-        if ($clearCache) {
658
+        if ($clearCache) {
659 659
             $this->clearCache($fire_events);
660 660
         }
661 661
         $this->decodeFields();
@@ -668,16 +668,16 @@  discard block
 block discarded – undo
668 668
      * @return $this
669 669
      * @throws Exception
670 670
      */
671
-    public function toTrash($ids)
672
-    {
671
+    public function toTrash($ids)
672
+    {
673 673
         $ignore = $this->systemID();
674 674
         $_ids = $this->cleanIDs($ids, ',', $ignore);
675
-        if (is_array($_ids) && $_ids != array()) {
675
+        if (is_array($_ids) && $_ids != array()) {
676 676
             $id = $this->sanitarIn($_ids);
677 677
             $uid = (int)$this->modx->getLoginUserId();
678 678
             $deletedon = time() + $this->modxConfig('server_offset_time');
679 679
             $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})");
680
-        } else {
680
+        } else {
681 681
             throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids,
682 682
                     1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
683 683
         }
@@ -689,11 +689,11 @@  discard block
 block discarded – undo
689 689
      * @param bool $fire_events
690 690
      * @return $this
691 691
      */
692
-    public function clearTrash($fire_events = false)
693
-    {
692
+    public function clearTrash($fire_events = false)
693
+    {
694 694
         $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'");
695 695
         $_ids = $this->modx->db->getColumn('id', $q);
696
-        if (is_array($_ids) && $_ids != array()) {
696
+        if (is_array($_ids) && $_ids != array()) {
697 697
             $this->invokeEvent('OnBeforeEmptyTrash', array(
698 698
                 "ids" => $_ids
699 699
             ), $fire_events);
@@ -715,15 +715,15 @@  discard block
 block discarded – undo
715 715
      * @param int|bool $depth
716 716
      * @return array
717 717
      */
718
-    public function children($ids, $depth)
719
-    {
718
+    public function children($ids, $depth)
719
+    {
720 720
         $_ids = $this->cleanIDs($ids, ',');
721
-        if (is_array($_ids) && $_ids != array()) {
721
+        if (is_array($_ids) && $_ids != array()) {
722 722
             $id = $this->sanitarIn($_ids);
723
-            if (!empty($id)) {
723
+            if (!empty($id)) {
724 724
                 $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})");
725 725
                 $id = $this->modx->db->getColumn('id', $q);
726
-                if ($depth > 0 || $depth === true) {
726
+                if ($depth > 0 || $depth === true) {
727 727
                     $id = $this->children($id, is_bool($depth) ? $depth : ($depth - 1));
728 728
                 }
729 729
                 $_ids = array_merge($_ids, $id);
@@ -739,8 +739,8 @@  discard block
 block discarded – undo
739 739
      * @return $this
740 740
      * @throws Exception
741 741
      */
742
-    public function delete($ids, $fire_events = false)
743
-    {
742
+    public function delete($ids, $fire_events = false)
743
+    {
744 744
         $ids = $this->children($ids, true);
745 745
         $_ids = $this->cleanIDs($ids, ',', $this->systemID());
746 746
         $this->invokeEvent('OnBeforeDocFormDelete', array(
@@ -757,8 +757,8 @@  discard block
 block discarded – undo
757 757
     /**
758 758
      * @return array
759 759
      */
760
-    private function systemID()
761
-    {
760
+    private function systemID()
761
+    {
762 762
         $ignore = array(
763 763
             0, //empty document
764 764
             (int)$this->modxConfig('site_start'),
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
         );
769 769
         $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''");
770 770
         $data = $this->modx->db->makeArray($data);
771
-        foreach ($data as $item) {
771
+        foreach ($data as $item) {
772 772
             $ignore[] = (int)$item['setting_value'];
773 773
         }
774 774
 
@@ -780,22 +780,22 @@  discard block
 block discarded – undo
780 780
      * @param $alias
781 781
      * @return string
782 782
      */
783
-    protected function checkAlias($alias)
784
-    {
783
+    protected function checkAlias($alias)
784
+    {
785 785
         $alias = strtolower($alias);
786
-        if ($this->modxConfig('friendly_urls')) {
786
+        if ($this->modxConfig('friendly_urls')) {
787 787
             $_alias = $this->escape($alias);
788
-            if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
788
+            if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
789 789
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1"));
790
-            } else {
790
+            } else {
791 791
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1"));
792 792
             }
793
-            if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
793
+            if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
794 794
                 $suffix = substr($alias, -2);
795
-                if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
795
+                if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
796 796
                     $suffix = (int)$tmp[1] + 1;
797 797
                     $alias = substr($alias, 0, -2) . '-' . $suffix;
798
-                } else {
798
+                } else {
799 799
                     $alias .= '-2';
800 800
                 }
801 801
                 $alias = $this->checkAlias($alias);
@@ -809,8 +809,8 @@  discard block
 block discarded – undo
809 809
      * @param $key
810 810
      * @return bool
811 811
      */
812
-    public function issetField($key)
813
-    {
812
+    public function issetField($key)
813
+    {
814 814
         return (array_key_exists($key, $this->default_field) || array_key_exists($key, $this->tv));
815 815
     }
816 816
 
@@ -818,11 +818,11 @@  discard block
 block discarded – undo
818 818
      * @param bool $reload
819 819
      * @return $this
820 820
      */
821
-    protected function get_TV($reload = false)
822
-    {
823
-        if (empty($this->modx->_TVnames) || $reload) {
821
+    protected function get_TV($reload = false)
822
+    {
823
+        if (empty($this->modx->_TVnames) || $reload) {
824 824
             $result = $this->query('SELECT `id`,`name`,`type` FROM ' . $this->makeTable('site_tmplvars'));
825
-            while ($row = $this->modx->db->GetRow($result)) {
825
+            while ($row = $this->modx->db->GetRow($result)) {
826 826
                 $this->modx->_TVnames[$row['name']] = array(
827 827
                     "id"   => $row['id'],
828 828
                     "type" => $row['type']
@@ -831,14 +831,16 @@  discard block
 block discarded – undo
831 831
         }
832 832
         $arrayTypes = array('checkbox', 'listbox-multiple');
833 833
         $arrayTVs = array();
834
-        foreach ($this->modx->_TVnames as $name => $data) {
834
+        foreach ($this->modx->_TVnames as $name => $data) {
835 835
             $this->tvid[$data['id']] = $name;
836 836
             $this->tv[$name] = $data['id'];
837
-            if (in_array($data['type'], $arrayTypes)) {
837
+            if (in_array($data['type'], $arrayTypes)) {
838 838
                 $arrayTVs[] = $name;
839 839
             }
840 840
         }
841
-        if (empty($this->tvaFields)) $this->tvaFields = $arrayTVs;
841
+        if (empty($this->tvaFields)) {
842
+            $this->tvaFields = $arrayTVs;
843
+        }
842 844
         $this->loadTVTemplate()->loadTVDefault(array_values($this->tv));
843 845
 
844 846
         return $this;
@@ -847,12 +849,12 @@  discard block
 block discarded – undo
847 849
     /**
848 850
      * @return $this
849 851
      */
850
-    protected function loadTVTemplate()
851
-    {
852
+    protected function loadTVTemplate()
853
+    {
852 854
         $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates'));
853 855
         $q = $this->modx->db->makeArray($q);
854 856
         $this->tvTpl = array();
855
-        foreach ($q as $item) {
857
+        foreach ($q as $item) {
856 858
             $this->tvTpl[$item['templateid']][] = $item['tmplvarid'];
857 859
         }
858 860
 
@@ -863,16 +865,16 @@  discard block
 block discarded – undo
863 865
      * @param array $tvId
864 866
      * @return $this
865 867
      */
866
-    protected function loadTVDefault(array $tvId = array())
867
-    {
868
-        if (is_array($tvId) && !empty($tvId)) {
868
+    protected function loadTVDefault(array $tvId = array())
869
+    {
870
+        if (is_array($tvId) && !empty($tvId)) {
869 871
             $tbl_site_tmplvars = $this->makeTable('site_tmplvars');
870 872
             $fields = 'id,name,default_text as value,display,display_params,type';
871 873
             $implodeTvId = implode(',', $tvId);
872 874
             $rs = $this->query("SELECT {$fields} FROM {$tbl_site_tmplvars} WHERE id IN({$implodeTvId})");
873 875
             $rows = $this->modx->db->makeArray($rs);
874 876
             $this->tvd = array();
875
-            foreach ($rows as $item) {
877
+            foreach ($rows as $item) {
876 878
                 $this->tvd[$item['name']] = $item;
877 879
             }
878 880
         }
@@ -885,17 +887,17 @@  discard block
 block discarded – undo
885 887
      * @return int
886 888
      * @throws Exception
887 889
      */
888
-    public function setTemplate($tpl)
889
-    {
890
-        if (!is_numeric($tpl) || $tpl != (int)$tpl) {
891
-            if (is_scalar($tpl)) {
890
+    public function setTemplate($tpl)
891
+    {
892
+        if (!is_numeric($tpl) || $tpl != (int)$tpl) {
893
+            if (is_scalar($tpl)) {
892 894
                 $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'";
893 895
                 $rs = $this->query($sql);
894
-                if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
896
+                if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
895 897
                     throw new Exception("Template {$tpl} is not exists");
896 898
                 }
897 899
                 $tpl = $this->modx->db->getValue($rs);
898
-            } else {
900
+            } else {
899 901
                 throw new Exception("Invalid template name: " . print_r($tpl, 1));
900 902
             }
901 903
         }
@@ -906,14 +908,14 @@  discard block
 block discarded – undo
906 908
     /**
907 909
      * @return string
908 910
      */
909
-    protected function getAlias()
910
-    {
911
-        if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') {
911
+    protected function getAlias()
912
+    {
913
+        if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') {
912 914
             $alias = strtr($this->get('pagetitle'), $this->table);
913
-        } else {
914
-            if ($this->get('alias') != '') {
915
+        } else {
916
+            if ($this->get('alias') != '') {
915 917
                 $alias = $this->get('alias');
916
-            } else {
918
+            } else {
917 919
                 $alias = '';
918 920
             }
919 921
         }
@@ -930,10 +932,10 @@  discard block
 block discarded – undo
930 932
      *
931 933
      * Пересчет menuindex по полю таблицы site_content
932 934
      */
933
-    public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc')
934
-    {
935
+    public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc')
936
+    {
935 937
         $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc';
936
-        if (is_integer($parent) && $criteria !== '') {
938
+        if (is_integer($parent) && $criteria !== '') {
937 939
             $this->query("SET @index := 0");
938 940
             $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}");
939 941
         }
@@ -946,37 +948,37 @@  discard block
 block discarded – undo
946 948
      *
947 949
      * @return $this
948 950
      */
949
-    public function setDefaultTemplate()
950
-    {
951
+    public function setDefaultTemplate()
952
+    {
951 953
         $parent = $this->get('parent');
952 954
         $template = $this->modxConfig('default_template');
953
-        switch ($this->modxConfig('auto_template_logic')) {
955
+        switch ($this->modxConfig('auto_template_logic')) {
954 956
             case 'sibling':
955
-                if (!$parent) {
957
+                if (!$parent) {
956 958
                     $site_start = $this->modxConfig('site_start');
957 959
                     $where = "sc.isfolder=0 AND sc.id!={$site_start}";
958 960
                     $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1);
959
-                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
961
+                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
960 962
                         $template = $sibl[0]['template'];
961 963
                     }
962
-                } else {
964
+                } else {
963 965
                     $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', 'isfolder=0', 'menuindex',
964 966
                         'ASC', 1);
965
-                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
967
+                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
966 968
                         $template = $sibl[0]['template'];
967
-                    } else {
969
+                    } else {
968 970
                         $sibl = $this->modx->getDocumentChildren($parent, 0, 0, 'template', 'isfolder=0', 'menuindex',
969 971
                             'ASC', 1);
970
-                        if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
972
+                        if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
971 973
                             $template = $sibl[0]['template'];
972 974
                         }
973 975
                     }
974 976
                 }
975 977
                 break;
976 978
             case 'parent':
977
-                if ($parent) {
979
+                if ($parent) {
978 980
                     $_parent = $this->modx->getPageInfo($parent, 0, 'template');
979
-                    if (isset($_parent['template'])) {
981
+                    if (isset($_parent['template'])) {
980 982
                         $template = $_parent['template'];
981 983
                     }
982 984
                 }
@@ -993,18 +995,18 @@  discard block
 block discarded – undo
993 995
      * @param  bool $store обновить распакованное поле
994 996
      * @return array ассоциативный массив с данными из json строки
995 997
      */
996
-    public function decodeField($field, $store = false)
997
-    {
998
+    public function decodeField($field, $store = false)
999
+    {
998 1000
         $out = array();
999
-        if ($this->isDecodableField($field)) {
1001
+        if ($this->isDecodableField($field)) {
1000 1002
             $data = $this->get($field);
1001
-            if ($this->isTVarrayField($field)) {
1003
+            if ($this->isTVarrayField($field)) {
1002 1004
                 $out = explode('||', $data);
1003
-            } else {
1005
+            } else {
1004 1006
                 $out = jsonHelper::jsonDecode($data, array('assoc' => true), true);
1005 1007
             }
1006 1008
         }
1007
-        if ($store) {
1009
+        if ($store) {
1008 1010
             $this->field[$field] = $out;
1009 1011
             $this->markAsDecode($field);
1010 1012
         }
@@ -1018,18 +1020,18 @@  discard block
 block discarded – undo
1018 1020
      * @param  bool $store обновить запакованное поле
1019 1021
      * @return string|null json строка
1020 1022
      */
1021
-    public function encodeField($field, $store = false)
1022
-    {
1023
+    public function encodeField($field, $store = false)
1024
+    {
1023 1025
         $out = null;
1024
-        if ($this->isEncodableField($field)) {
1026
+        if ($this->isEncodableField($field)) {
1025 1027
             $data = $this->get($field);
1026
-            if ($this->isTVarrayField($field)) {
1028
+            if ($this->isTVarrayField($field)) {
1027 1029
                 $out = is_array($data) ? implode('||', $data) : $data;
1028
-            } else {
1030
+            } else {
1029 1031
                 $out = json_encode($data);
1030 1032
             }
1031 1033
         }
1032
-        if ($store) {
1034
+        if ($store) {
1033 1035
             $this->field[$field] = $out;
1034 1036
             $this->markAsEncode($field);
1035 1037
         }
@@ -1042,8 +1044,8 @@  discard block
 block discarded – undo
1042 1044
      * @param  string $field имя поля
1043 1045
      * @return boolean
1044 1046
      */
1045
-    public function isTVarrayField($field)
1046
-    {
1047
+    public function isTVarrayField($field)
1048
+    {
1047 1049
         return (is_scalar($field) && in_array($field, $this->tvaFields));
1048 1050
     }
1049 1051
 
@@ -1051,10 +1053,10 @@  discard block
 block discarded – undo
1051 1053
      * Пометить все поля как запакованные
1052 1054
      * @return $this
1053 1055
      */
1054
-    public function markAllEncode()
1055
-    {
1056
+    public function markAllEncode()
1057
+    {
1056 1058
         parent::markAllEncode();
1057
-        foreach ($this->tvaFields as $field) {
1059
+        foreach ($this->tvaFields as $field) {
1058 1060
             $this->markAsEncode($field);
1059 1061
         }
1060 1062
 
@@ -1065,10 +1067,10 @@  discard block
 block discarded – undo
1065 1067
      * Пометить все поля как распакованные
1066 1068
      * @return $this
1067 1069
      */
1068
-    public function markAllDecode()
1069
-    {
1070
+    public function markAllDecode()
1071
+    {
1070 1072
         parent::markAllDecode();
1071
-        foreach ($this->tvaFields as $field) {
1073
+        foreach ($this->tvaFields as $field) {
1072 1074
             $this->markAsDecode($field);
1073 1075
         }
1074 1076
 
Please login to merge, or discard this patch.
Upper-Lower-Casing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
             if ($this->newDoc) {
590 590
                 $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set);
591 591
             } else {
592
-                $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ',
592
+                $SQL = "update {$this->makeTable('site_content')} SET " . implode(', ',
593 593
                         $this->set) . " WHERE `id` = " . $this->id;
594 594
             }
595 595
             $this->query($SQL);
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
             }
600 600
 
601 601
             if ($parent > 0) {
602
-                $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'");
602
+                $this->query("update {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'");
603 603
             }
604 604
         }
605 605
 
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 
627 627
         if (!empty($_updateTVs)) {
628 628
             foreach ($_updateTVs as $id => $value) {
629
-                $this->query("UPDATE {$this->makeTable('site_tmplvar_contentvalues')} SET `value` = '{$value}' WHERE `contentid` = {$this->id} AND `tmplvarid` = {$id}");
629
+                $this->query("update {$this->makeTable('site_tmplvar_contentvalues')} SET `value` = '{$value}' WHERE `contentid` = {$this->id} AND `tmplvarid` = {$id}");
630 630
             }
631 631
         }
632 632
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
             $id = $this->sanitarIn($_ids);
677 677
             $uid = (int)$this->modx->getLoginUserId();
678 678
             $deletedon = time() + $this->modxConfig('server_offset_time');
679
-            $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})");
679
+            $this->query("update {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})");
680 680
         } else {
681 681
             throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids,
682 682
                     1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
             $tbl_site_tmplvars = $this->makeTable('site_tmplvars');
870 870
             $fields = 'id,name,default_text as value,display,display_params,type';
871 871
             $implodeTvId = implode(',', $tvId);
872
-            $rs = $this->query("SELECT {$fields} FROM {$tbl_site_tmplvars} WHERE id IN({$implodeTvId})");
872
+            $rs = $this->query("select {$fields} FROM {$tbl_site_tmplvars} WHERE id IN({$implodeTvId})");
873 873
             $rows = $this->modx->db->makeArray($rs);
874 874
             $this->tvd = array();
875 875
             foreach ($rows as $item) {
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
                 $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'";
893 893
                 $rs = $this->query($sql);
894 894
                 if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
895
-                    throw new Exception("Template {$tpl} is not exists");
895
+                    throw new Exception("template {$tpl} is not exists");
896 896
                 }
897 897
                 $tpl = $this->modx->db->getValue($rs);
898 898
             } else {
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
         $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc';
936 936
         if (is_integer($parent) && $criteria !== '') {
937 937
             $this->query("SET @index := 0");
938
-            $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}");
938
+            $this->query("update {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}");
939 939
         }
940 940
 
941 941
         return $this;
Please login to merge, or discard this patch.