Completed
Push — master ( 0bc767...49baef )
by
unknown
02:07
created
assets/lib/MODxAPI/autoTable.abstract.php 1 patch
Braces   +32 added lines, -33 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@  discard block
 block discarded – undo
4 4
 /**
5 5
  * Class autoTable
6 6
  */
7
-abstract class autoTable extends MODxAPI
8
-{
7
+abstract class autoTable extends MODxAPI
8
+{
9 9
     /**
10 10
      * @var null
11 11
      */
@@ -18,8 +18,8 @@  discard block
 block discarded – undo
18 18
     /**
19 19
      * @return null
20 20
      */
21
-    public function tableName()
22
-    {
21
+    public function tableName()
22
+    {
23 23
         return $this->table;
24 24
     }
25 25
 
@@ -28,16 +28,16 @@  discard block
 block discarded – undo
28 28
      * @param DocumentParser $modx
29 29
      * @param bool $debug
30 30
      */
31
-    public function __construct($modx, $debug = false)
32
-    {
31
+    public function __construct($modx, $debug = false)
32
+    {
33 33
         parent::__construct($modx, $debug);
34
-        if (empty($this->default_field)) {
34
+        if (empty($this->default_field)) {
35 35
             $data = $this->modx->db->getTableMetaData($this->makeTable($this->table));
36
-            foreach ($data as $item) {
37
-                if (empty($this->pkName) && $item['Key'] == 'PRI') {
36
+            foreach ($data as $item) {
37
+                if (empty($this->pkName) && $item['Key'] == 'PRI') {
38 38
                     $this->pkName = $item['Field'];
39 39
                 }
40
-                if ($this->pkName != $item['Field']) {
40
+                if ($this->pkName != $item['Field']) {
41 41
                     $this->default_field[$item['Field']] = $item['Default'];
42 42
                 }
43 43
             }
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
      * @param $id
50 50
      * @return $this
51 51
      */
52
-    public function edit($id)
53
-    {
52
+    public function edit($id)
53
+    {
54 54
         $id = is_scalar($id) ? trim($id) : '';
55
-        if ($this->getID() != $id) {
55
+        if ($this->getID() != $id) {
56 56
             $this->close();
57 57
             $this->markAllEncode();
58 58
             $this->newDoc = false;
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
             $this->fromArray($this->modx->db->getRow($result));
61 61
             $this->store($this->toArray());
62 62
             $this->id = $this->eraseField($this->pkName);
63
-            if (is_bool($this->id) && $this->id === false) {
63
+            if (is_bool($this->id) && $this->id === false) {
64 64
                 $this->id = null;
65
-            } else {
65
+            } else {
66 66
                 $this->decodeFields();
67 67
             }
68 68
         }
@@ -75,40 +75,39 @@  discard block
 block discarded – undo
75 75
      * @param bool $clearCache
76 76
      * @return bool|null|void
77 77
      */
78
-    public function save($fire_events = null, $clearCache = false)
79
-    {
80
-        foreach ($this->jsonFields as $field) {
78
+    public function save($fire_events = null, $clearCache = false)
79
+    {
80
+        foreach ($this->jsonFields as $field) {
81 81
             if ($this->get($field) === null 
82 82
                 && isset($this->default_field[$field]) 
83
-                && is_array($this->default_field[$field])) 
84
-            {
83
+                && is_array($this->default_field[$field])) {
85 84
                 $this->set($field, $this->default_field[$field]);
86 85
             }
87 86
         }
88 87
         $fld = $this->encodeFields()->toArray();
89
-        foreach ($this->default_field as $key => $value) {
90
-            if ($this->newDoc && $this->get($key) === null && $this->get($key) !== $value) {
88
+        foreach ($this->default_field as $key => $value) {
89
+            if ($this->newDoc && $this->get($key) === null && $this->get($key) !== $value) {
91 90
                 $this->set($key, $value);
92 91
             }
93
-            if ((!$this->generateField || isset($fld[$key])) && $this->get($key) !== null) {
92
+            if ((!$this->generateField || isset($fld[$key])) && $this->get($key) !== null) {
94 93
                 $this->Uset($key);
95 94
             }
96 95
             unset($fld[$key]);
97 96
         }
98
-        if (!empty($this->set)) {
99
-            if ($this->newDoc) {
97
+        if (!empty($this->set)) {
98
+            if ($this->newDoc) {
100 99
                 $SQL = "INSERT {$this->ignoreError} INTO {$this->makeTable($this->table)} SET " . implode(', ',
101 100
                         $this->set);
102
-            } else {
101
+            } else {
103 102
                 $SQL = ($this->getID() === null) ? null : "UPDATE {$this->ignoreError} {$this->makeTable($this->table)} SET " . implode(', ',
104 103
                         $this->set) . " WHERE `" . $this->pkName . "` = " . $this->getID();
105 104
             }
106 105
             $this->query($SQL);
107
-            if ($this->newDoc) {
106
+            if ($this->newDoc) {
108 107
                 $this->id = $this->modx->db->getInsertId();
109 108
             }
110 109
         }
111
-        if ($clearCache) {
110
+        if ($clearCache) {
112 111
             $this->clearCache($fire_events);
113 112
         }
114 113
         $this->decodeFields();
@@ -122,16 +121,16 @@  discard block
 block discarded – undo
122 121
      * @return $this
123 122
      * @throws Exception
124 123
      */
125
-    public function delete($ids, $fire_events = null)
126
-    {
124
+    public function delete($ids, $fire_events = null)
125
+    {
127 126
         $_ids = $this->cleanIDs($ids, ',');
128
-        if (is_array($_ids) && $_ids != array()) {
127
+        if (is_array($_ids) && $_ids != array()) {
129 128
             $id = $this->sanitarIn($_ids);
130
-            if (!empty($id)) {
129
+            if (!empty($id)) {
131 130
                 $this->query("DELETE from {$this->makeTable($this->table)} where `" . $this->pkName . "` IN ({$id})");
132 131
             }
133 132
             $this->clearCache($fire_events);
134
-        } else {
133
+        } else {
135 134
             throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre>');
136 135
         }
137 136
 
Please login to merge, or discard this patch.