PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / wizard / classes / options.php
vikappointments / site / helpers / libraries / wizard / classes Last commit date
employees.php 3 days ago index.html 3 days ago locations.php 3 days ago locwdays.php 3 days ago options.php 3 days ago packages.php 3 days ago payments.php 3 days ago services.php 3 days ago subscriptions.php 3 days ago syspack.php 3 days ago syssubscr.php 3 days ago system.php 3 days ago taxes.php 3 days ago
options.php
177 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 /**
15 * Implement the wizard step used to configure the
16 * options and the relations with the services.
17 *
18 * @since 1.7.1
19 */
20 class VAPWizardStepOptions extends VAPWizardStep
21 {
22 /**
23 * Returns the step title.
24 * Used as a very-short description.
25 *
26 * @return string The step title.
27 */
28 public function getTitle()
29 {
30 return JText::translate('VAPMENUOPTIONS');
31 }
32
33 /**
34 * Returns the step description.
35 *
36 * @return string The step description.
37 */
38 public function getDescription()
39 {
40 return JText::translate('VAP_WIZARD_STEP_OPTIONS_DESC');
41 }
42
43 /**
44 * Returns an optional step icon.
45 *
46 * @return string The step icon.
47 */
48 public function getIcon()
49 {
50 return '<i class="fas fa-tags"></i>';
51 }
52
53 /**
54 * Return the group to which the step belongs.
55 *
56 * @return string The group name.
57 */
58 public function getGroup()
59 {
60 // belongs to APPOINTMENTS group
61 return JText::translate('VAPMENUTITLEHEADER2');
62 }
63
64 /**
65 * Returns the completion progress in percentage.
66 *
67 * @return integer The percentage progress (always rounded).
68 */
69 public function getProgress()
70 {
71 $progress = 0;
72
73 // get list of created options
74 $options = $this->getExtraOptions();
75
76 if ($options)
77 {
78 // option created, increase progress
79 $progress = 50;
80
81 // search for an option with assigned services
82 $options = array_filter($options, function($s)
83 {
84 return $s->id_service;
85 });
86
87 if ($options)
88 {
89 // assigned to services, increase progress
90 $progress = 100;
91 }
92 }
93
94 return $progress;
95 }
96
97 /**
98 * Checks whether the step has been completed.
99 *
100 * @return boolean True if completed, false otherwise.
101 */
102 public function isCompleted()
103 {
104 // look for 100% completion progress
105 return $this->getProgress() == 100;
106 }
107
108 /**
109 * Returns the button used to process the step.
110 *
111 * @return string The HTML of the button.
112 */
113 public function getExecuteButton()
114 {
115 // get options list
116 if ($this->getOptions())
117 {
118 // load services step from dependencies
119 $step = $this->getDependency('services');
120
121 if (!$services)
122 {
123 return '';
124 }
125
126 // fetch available services
127 $services = $step->getServices();
128
129 // edit the first service of the list and auto-focus the assignments list
130 return '<a href="index.php?option=com_vikappointments&task=service.edit&cid[]=' . $services[0]->id . '#service_assoc" class="btn btn-success">' . JText::translate('VAPEDIT') . '</a>';
131 }
132
133 // point to the controller for creating a new option
134 return '<a href="index.php?option=com_vikappointments&task=option.add" class="btn btn-success">' . JText::translate('VAPNEW') . '</a>';
135 }
136
137 /**
138 * Checks whether the specified step can be skipped.
139 * By default, all the steps are mandatory.
140 *
141 * @return boolean True if skippable, false otherwise.
142 */
143 public function canIgnore()
144 {
145 return true;
146 }
147
148 /**
149 * Returns a list of created options.
150 *
151 * @return array A list of options.
152 */
153 public function getExtraOptions()
154 {
155 static $options = null;
156
157 // get options only once
158 if (is_null($options))
159 {
160 $dbo = JFactory::getDbo();
161
162 $q = $dbo->getQuery(true)
163 ->select($dbo->qn(array('o.id', 'o.name')))
164 ->select($dbo->qn('a.id_service'))
165 ->from($dbo->qn('#__vikappointments_option', 'o'))
166 ->leftjoin($dbo->qn('#__vikappointments_ser_opt_assoc', 'a') . ' ON ' . $dbo->qn('a.id_option') . ' = ' . $dbo->qn('o.id'))
167 ->group($dbo->qn('o.id'))
168 ->order($dbo->qn('o.id') . ' ASC');
169
170 $dbo->setQuery($q);
171 $options = $dbo->loadObjectList();
172 }
173
174 return $options;
175 }
176 }
177