PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.18
VikAppointments Services Booking Calendar v1.2.18
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / models / tag.php
vikappointments / admin / models Last commit date
apiban.php 5 months ago apilog.php 5 months ago apiplugin.php 5 months ago apiuser.php 5 months ago apiuseroptions.php 5 months ago backup.php 5 months ago caldays.php 5 months ago calendar.php 5 months ago city.php 5 months ago closure.php 5 months ago configapp.php 5 months ago configcldays.php 5 months ago configcron.php 5 months ago configemp.php 5 months ago configsmsapi.php 5 months ago configuration.php 5 months ago conversion.php 5 months ago country.php 5 months ago coupon.php 5 months ago couponemployee.php 5 months ago coupongroup.php 5 months ago couponservice.php 5 months ago cronjob.php 5 months ago cronjoblog.php 5 months ago customer.php 5 months ago customf.php 5 months ago customfservice.php 5 months ago customizer.php 5 months ago empgroup.php 5 months ago employee.php 5 months ago empsettings.php 5 months ago file.php 5 months ago findreservation.php 5 months ago group.php 5 months ago import.php 5 months ago index.html 5 months ago invoice.php 5 months ago langcustomf.php 5 months ago langempgroup.php 5 months ago langemployee.php 5 months ago langgroup.php 5 months ago langmedia.php 5 months ago langoption.php 5 months ago langoptiongroup.php 5 months ago langoptionvar.php 5 months ago langpackage.php 5 months ago langpackgroup.php 5 months ago langpayment.php 5 months ago langservice.php 5 months ago langstatuscode.php 5 months ago langsubscr.php 5 months ago langtax.php 5 months ago langtaxrule.php 5 months ago location.php 5 months ago mailtext.php 5 months ago makerecurrence.php 5 months ago media.php 5 months ago multiorder.php 5 months ago option.php 5 months ago optiongroup.php 5 months ago optionvar.php 5 months ago orderstatus.php 5 months ago package.php 5 months ago packageservice.php 5 months ago packgroup.php 5 months ago packorder.php 5 months ago packorderitem.php 5 months ago payment.php 5 months ago rate.php 5 months ago reportsemp.php 5 months ago reportsser.php 5 months ago reservation.php 5 months ago resoptassoc.php 5 months ago restriction.php 5 months ago review.php 5 months ago serempassoc.php 5 months ago seroptassoc.php 5 months ago serrateassoc.php 5 months ago serrestrassoc.php 5 months ago service.php 5 months ago state.php 5 months ago statswidget.php 5 months ago statuscode.php 5 months ago subscription.php 5 months ago subscrorder.php 5 months ago tag.php 5 months ago tax.php 5 months ago taxrule.php 5 months ago updateprogram.php 5 months ago usernote.php 5 months ago waitinglist.php 5 months ago webhook.php 5 months ago worktime.php 5 months ago
tag.php
158 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 VAPLoader::import('libraries.mvc.model');
15
16 /**
17 * VikAppointments tag model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelTag extends JModelVAP
22 {
23 /**
24 * Array used to cache the loaded tags.
25 *
26 * @var array
27 */
28 protected static $tags = array();
29
30 /**
31 * Takes the tag names and creates all the missing records.
32 *
33 * @param mixed $tags Either an array or a string (comma-separated).
34 * @param string $group The group to which the tags belong.
35 * @param boolean $column The name of the column to return (* for all).
36 *
37 * @return array The resulting tags.
38 */
39 public function writeTags($tags, $group = null, $column = 'id')
40 {
41 if (is_string($tags))
42 {
43 // explode tags string
44 $tags = preg_split("/\s*,\s*/", $tags);
45 }
46 else
47 {
48 $tags = (array) $tags;
49 }
50
51 $list = array();
52
53 if (!$tags)
54 {
55 // nothing to commit
56 return $list;
57 }
58
59 foreach ($tags as $tag)
60 {
61 // load tag details
62 $item = $this->getItem(array('name' => $tag));
63
64 if (!$item)
65 {
66 // tag not found, create it
67 if ($this->save(array('name' => $tag, 'group' => $group)))
68 {
69 // get saved data
70 $item = (object) $this->getData();
71 }
72 }
73
74 if ($item)
75 {
76 // tag found/created, register it within the list
77 if ($column == '*')
78 {
79 // return the whole object
80 $list[] = $item;
81 }
82 else if (isset($item->{$column}))
83 {
84 // return the specified property
85 $list[] = $item->{$column};
86 }
87 else
88 {
89 // return the tag ID
90 $list[] = $item->id;
91 }
92 }
93 }
94
95 return $list;
96 }
97
98 /**
99 * Takes the tag IDs and convert them into the related name.
100 *
101 * @param mixed $tags Either an array or a string (comma-separated).
102 * @param boolean $column The name of the column to return (* for all).
103 *
104 * @return array The resulting tags.
105 */
106 public function readTags($tags, $column = 'name')
107 {
108 if (is_string($tags))
109 {
110 // explode tags string
111 $tags = preg_split("/\s*,\s*/", $tags);
112 }
113 else
114 {
115 $tags = (array) $tags;
116 }
117
118 $list = array();
119
120 if (!$tags)
121 {
122 // nothing to read
123 return $list;
124 }
125
126 foreach (array_map('intval', $tags) as $tag)
127 {
128 if (!isset(static::$tags[$tag]))
129 {
130 // load tag details only once
131 static::$tags[$tag] = $this->getItem($tag);
132 }
133
134 if (static::$tags[$tag])
135 {
136 // tag found, register it within the list
137 if ($column == '*')
138 {
139 // return the whole object
140 $list[] = static::$tags[$tag];
141 }
142 else if (isset(static::$tags[$tag]->{$column}))
143 {
144 // return the specified property
145 $list[] = static::$tags[$tag]->{$column};
146 }
147 else
148 {
149 // return the tag name
150 $list[] = static::$tags[$tag]->name;
151 }
152 }
153 }
154
155 return $list;
156 }
157 }
158