| @@ -1,106 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\Classes; | |
| 4 | - | |
| 5 | -use AcyMailing\Core\AcymClass; | |
| 6 | - | |
| 7 | -class TagClass extends AcymClass | |
| 8 | -{ | |
| 9 | - const TYPE_MAIL = 'mail'; | |
| 10 | - const TYPE_LIST = 'list'; | |
| 11 | - | |
| 12 | - public function __construct() | |
| 13 | - { | |
| 14 | - parent::__construct(); | |
| 15 | - | |
| 16 | - $this->table = 'tag'; | |
| 17 | - $this->pkey = 'id'; | |
| 18 | - } | |
| 19 | - | |
| 20 | - public function setTags(string $type, int $elementId, array $newTags): void | |
| 21 | - { | |
| 22 | - acym_query('DELETE FROM #__acym_tag WHERE `type` = '.acym_escapeDB($type).' AND `id_element` = '.intval($elementId)); | |
| 23 | - | |
| 24 | - $tagsToInsertQuery = []; | |
| 25 | - | |
| 26 | - foreach ($newTags as $oneTag) { | |
| 27 | - if (empty($oneTag)) { | |
| 28 | - continue; | |
| 29 | - } | |
| 30 | - | |
| 31 | - $newTag = new \stdClass(); | |
| 32 | - $newTag->type = $type; | |
| 33 | - | |
| 34 | - if (strpos($oneTag, 'acy_new_tag_') !== false) { | |
| 35 | - $tagName = substr($oneTag, 12); | |
| 36 | - if (empty($tagName)) { | |
| 37 | - continue; | |
| 38 | - } | |
| 39 | - | |
| 40 | - $newTag->name = $tagName; | |
| 41 | - } else { | |
| 42 | - $newTag->name = $oneTag; | |
| 43 | - } | |
| 44 | - $tagsToInsertQuery[] = '('.acym_escapeDB($newTag->name).','.acym_escapeDB($newTag->type).', '.intval($elementId).')'; | |
| 45 | - } | |
| 46 | - | |
| 47 | - if (!empty($tagsToInsertQuery)) { | |
| 48 | - acym_query('INSERT INTO #__acym_tag (`name`, `type`, `id_element`) VALUES '.implode(',', $tagsToInsertQuery)); | |
| 49 | - } | |
| 50 | - } | |
| 51 | - | |
| 52 | - public function getAllTagsByType(string $type): array | |
| 53 | - { | |
| 54 | - return acym_loadObjectList( | |
| 55 | - 'SELECT `name` AS `value`, `name` | |
| 56 | - FROM #__acym_tag | |
| 57 | - WHERE `type` = '.acym_escapeDB($type).' | |
| 58 | - GROUP BY `name`' | |
| 59 | - ); | |
| 60 | - } | |
| 61 | - | |
| 62 | - public function getAllTagsByElementId(string $type, int $id): array | |
| 63 | - { | |
| 64 | - if (empty($id)) { | |
| 65 | - return []; | |
| 66 | - } | |
| 67 | - | |
| 68 | - $tags = acym_loadResultArray( | |
| 69 | - 'SELECT * | |
| 70 | - FROM #__acym_tag | |
| 71 | - WHERE `type` = '.acym_escapeDB($type).' | |
| 72 | - AND `id_element` = '.intval($id) | |
| 73 | - ); | |
| 74 | - | |
| 75 | - return empty($tags) ? [] : $tags; | |
| 76 | - } | |
| 77 | - | |
| 78 | - public function getAllTagsByTypeAndElementIds(string $type, array $ids): array | |
| 79 | - { | |
| 80 | - acym_arrayToInteger($ids); | |
| 81 | - if (empty($ids)) { | |
| 82 | - return []; | |
| 83 | - } | |
| 84 | - | |
| 85 | - return acym_loadObjectList( | |
| 86 | - 'SELECT * | |
| 87 | - FROM #__acym_tag | |
| 88 | - WHERE `type` = '.acym_escapeDB($type).' | |
| 89 | - AND `id_element` IN ('.implode(',', $ids).')' | |
| 90 | - ); | |
| 91 | - } | |
| 92 | - | |
| 93 | - public function getAllTagsForSelect(): array | |
| 94 | - { | |
| 95 | - return acym_loadObjectList( | |
| 96 | - 'SELECT DISTINCT `name` | |
| 97 | - FROM #__acym_tag | |
| 98 | - ORDER BY `name` ASC' | |
| 99 | - ); | |
| 100 | - } | |
| 101 | - | |
| 102 | - public function deleteByName(string $name): void | |
| 103 | - { | |
| 104 | - acym_query('DELETE FROM #__acym_tag WHERE `name` = '.acym_escapeDB($name)); | |
| 105 | - } | |
| 106 | -} | |