| @@ -16,15 +16,23 @@ | ||
| 16 | 16 | $this->table = 'tag'; |
| 17 | 17 | $this->pkey = 'id'; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + /** | |
| 21 | + * Attaches the tags passed in parameter to the specified element | |
| 22 | + */ | |
| 20 | 23 | public function setTags(string $type, int $elementId, array $newTags): void |
| 21 | 24 | { |
| 25 | + // Remove the old tags from the element | |
| 22 | 26 | acym_query('DELETE FROM #__acym_tag WHERE `type` = '.acym_escapeDB($type).' AND `id_element` = '.intval($elementId)); |
| 23 | 27 | |
| 24 | 28 | $tagsToInsertQuery = []; |
| 25 | 29 | |
| 26 | 30 | foreach ($newTags as $oneTag) { |
| 31 | + if (empty($oneTag)) { | |
| 32 | + continue; | |
| 33 | + } | |
| 34 | + | |
| 27 | 35 | $newTag = new \stdClass(); |
| 28 | 36 | $newTag->type = $type; |
| 29 | 37 | |
| 30 | 38 | if (strpos($oneTag, 'acy_new_tag_') !== false) { |