13
13
namespace SemanticHTML5 \Backend ;
14
14
15
15
use Contao \Database \Result ;
16
+ use Contao \Database ;
16
17
17
18
/**
18
- * Generall Helper Class for handling start and end tags
19
+ * General Helper Class for handling start and end tags
19
20
*/
20
21
class TagUtils
21
22
{
@@ -126,7 +127,7 @@ public function deleteCorrespondingTag(Result $item)
126
127
*/
127
128
public function getTag ($ id ) {
128
129
129
- $ item = \ Database::getInstance ()
130
+ $ item = Database::getInstance ()
130
131
->prepare ('SELECT * FROM ' . $ this ->table . ' WHERE (type ="sHtml5Start" OR type = "sHtml5End") AND id = ? ' )
131
132
->execute ($ id );
132
133
@@ -141,7 +142,7 @@ public function getTag($id) {
141
142
public function getcorrespondingTag (Result $ item )
142
143
{
143
144
$ type = $ this ->matchingTags [$ item ->type ];
144
- $ result = \ Database::getInstance ()
145
+ $ result = Database::getInstance ()
145
146
->prepare ('SELECT * FROM ' . $ this ->table . ' WHERE pid = ? AND sh5_pid = ? AND type = ? ' )
146
147
->execute ($ item ->pid , $ item ->sh5_pid , $ type );
147
148
@@ -168,11 +169,11 @@ public function createTag($data)
168
169
unset($ data ['id ' ]);
169
170
170
171
//remove fields which are not present in the db table (See #22)
171
- $ tableFields = array_flip (\ Database::getInstance ()->getFieldNames ($ this ->table ));
172
+ $ tableFields = array_flip (Database::getInstance ()->getFieldNames ($ this ->table ));
172
173
$ data = array_intersect_key ($ data , $ tableFields );
173
174
174
175
// Insert the tag
175
- $ result = \ Database::getInstance ()
176
+ $ result = Database::getInstance ()
176
177
->prepare ("INSERT INTO " . $ this ->table . " %s " )
177
178
->set ($ data )
178
179
->execute ();
@@ -194,7 +195,7 @@ public function createTag($data)
194
195
public function deleteTag ($ id )
195
196
{
196
197
//ToDo: add the UnDo functionality from contao
197
- \ Database::getInstance ()
198
+ Database::getInstance ()
198
199
->prepare ('DELETE FROM ' . $ this ->table . ' WHERE id = ? '
199
200
. 'AND (type = "sHtml5Start" OR type = "sHtml5End") ' )
200
201
->execute ($ id );
@@ -210,17 +211,28 @@ public function deleteTag($id)
210
211
public function updateTag ($ id , $ data )
211
212
{
212
213
//update the database
213
- \ Database::getInstance ()
214
+ Database::getInstance ()
214
215
->prepare ('UPDATE ' . $ this ->table . ' %s WHERE id = ? ' )
215
216
->set ($ data )
216
217
->execute ($ id );
217
218
218
219
//return the updated element
219
- return \Database::getInstance ()
220
- ->prepare ('SELECT * FROM ' . $ this ->table . ' WHERE id = ? ' )
221
- ->execute ($ id );
220
+ return $ this ->getCurrentRecord ($ id );
222
221
}
223
222
223
+ /**
224
+ * Returns the current record with the given id as Result
225
+ *
226
+ * @param int $id The id of the element
227
+ * @return Result The current element as a mysql result
228
+ */
229
+ public function getCurrentRecord ($ id ): Result {
230
+ return Database::getInstance ()
231
+ ->prepare ('SELECT * FROM ' . $ this ->table . ' WHERE id = ? ' )
232
+ ->execute ($ id );
233
+ }
234
+
235
+
224
236
/**
225
237
* Collects all fields which should have the same values foro start and end
226
238
* tag, e.g. the show to guest only flag. See #30
0 commit comments