PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Classes / TagClass.php

TagClass.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.1.4, at back/Classes/TagClass.php

103 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $newTag = new \stdClass();
28 $newTag->type = $type;
29
30 if (strpos($oneTag, 'acy_new_tag_') !== false) {
31 $tagName = substr($oneTag, 12);
32 if (empty($tagName)) {
33 continue;
34 }
35
36 $newTag->name = $tagName;
37 } else {
38 $newTag->name = $oneTag;
39 }
40 $tagsToInsertQuery[] = '('.acym_escapeDB($newTag->name).','.acym_escapeDB($newTag->type).', '.intval($elementId).')';
41 }
42
43 if (!empty($tagsToInsertQuery)) {
44 acym_query('INSERT INTO #__acym_tag (`name`, `type`, `id_element`) VALUES '.implode(',', $tagsToInsertQuery));
45 }
46 }
47
48 public function getAllTagsByType(string $type): array
49 {
50 return acym_loadObjectList(
51 'SELECT `name` AS `value`, `name`
52 FROM #__acym_tag
53 WHERE `type` = '.acym_escapeDB($type).'
54 GROUP BY `name`'
55 );
56 }
57
58 public function getAllTagsByElementId(string $type, int $id): array
59 {
60 if (empty($id)) {
61 return [];
62 }
63
64 $tags = acym_loadResultArray(
65 'SELECT *
66 FROM #__acym_tag
67 WHERE `type` = '.acym_escapeDB($type).'
68 AND `id_element` = '.intval($id)
69 );
70
71 return empty($tags) ? [] : $tags;
72 }
73
74 public function getAllTagsByTypeAndElementIds(string $type, array $ids): array
75 {
76 acym_arrayToInteger($ids);
77 if (empty($ids)) {
78 return [];
79 }
80
81 return acym_loadObjectList(
82 'SELECT *
83 FROM #__acym_tag
84 WHERE `type` = '.acym_escapeDB($type).'
85 AND `id_element` IN ('.implode(',', $ids).')'
86 );
87 }
88
89 public function getAllTagsForSelect(): array
90 {
91 return acym_loadObjectList(
92 'SELECT DISTINCT `name`
93 FROM #__acym_tag
94 ORDER BY `name` ASC'
95 );
96 }
97
98 public function deleteByName(string $name): void
99 {
100 acym_query('DELETE FROM #__acym_tag WHERE `name` = '.acym_escapeDB($name));
101 }
102 }
103