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 / services.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
services.php
165 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 * services and the relations with the employees.
17 *
18 * @since 1.7.1
19 */
20 class VAPWizardStepServices 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('VAPMENUSERVICES');
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_SERVICES_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-flask"></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 services
74 $services = $this->getServices();
75
76 if ($services)
77 {
78 // service created, increase progress
79 $progress = 50;
80
81 // search for a service with assigned employees
82 $services = array_filter($services, function($s)
83 {
84 return $s->id_employee;
85 });
86
87 if ($services)
88 {
89 // assigned to employees, 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 services list
116 $services = $this->getServices();
117
118 $count = count($services);
119
120 if ($count == 1)
121 {
122 // point to the controller for editing an existing service
123 return '<a href="index.php?option=com_vikappointments&task=service.edit&cid[]=' . $services[0]->id . '" class="btn btn-success">' . JText::translate('VAPEDIT') . '</a>';
124 }
125
126 if ($count > 1)
127 {
128 // reach the services list to start pick a record to edit
129 return '<a href="index.php?option=com_vikappointments&view=services" class="btn btn-success">' . JText::translate('VAPEDIT') . '</a>';
130 }
131
132 // point to the controller for creating a new service
133 return '<a href="index.php?option=com_vikappointments&task=service.add" class="btn btn-success">' . JText::translate('VAPNEW') . '</a>';
134 }
135
136 /**
137 * Returns a list of created services.
138 *
139 * @return array A list of services.
140 */
141 public function getServices()
142 {
143 static $services = null;
144
145 // get services only once
146 if (is_null($services))
147 {
148 $dbo = JFactory::getDbo();
149
150 $q = $dbo->getQuery(true)
151 ->select($dbo->qn(array('s.id', 's.name')))
152 ->select($dbo->qn('a.id_employee'))
153 ->from($dbo->qn('#__vikappointments_service', 's'))
154 ->leftjoin($dbo->qn('#__vikappointments_ser_emp_assoc', 'a') . ' ON ' . $dbo->qn('a.id_service') . ' = ' . $dbo->qn('s.id'))
155 ->group($dbo->qn('s.id'))
156 ->order($dbo->qn('s.id') . ' ASC');
157
158 $dbo->setQuery($q);
159 $services = $dbo->loadObjectList();
160 }
161
162 return $services;
163 }
164 }
165