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 / employees.php
vikappointments / site / helpers / libraries / wizard / classes Last commit date
employees.php 5 days ago index.html 5 days ago locations.php 5 days ago locwdays.php 5 days ago options.php 5 days ago packages.php 5 days ago payments.php 5 days ago services.php 5 days ago subscriptions.php 5 days ago syspack.php 5 days ago syssubscr.php 5 days ago system.php 5 days ago taxes.php 5 days ago
employees.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 * employees and the working days.
17 *
18 * @since 1.7.1
19 */
20 class VAPWizardStepEmployees 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('VAPMENUEMPLOYEES');
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_EMPLOYEES_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-user-tie"></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 employees
74 $employees = $this->getEmployees();
75
76 if ($employees)
77 {
78 // employee created, increase progress
79 $progress = 50;
80
81 // search for an employee with assigned working times
82 $employees = array_filter($employees, function($e)
83 {
84 return $e->id_worktime;
85 });
86
87 if ($employees)
88 {
89 // working times created, 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 employees list
116 $employees = $this->getEmployees();
117
118 $count = count($employees);
119
120 if ($count == 1)
121 {
122 // point to the controller for editing an existing employee
123 return '<a href="index.php?option=com_vikappointments&task=employee.edit&cid[]=' . $employees[0]->id . '" class="btn btn-success">' . JText::translate('VAPEDIT') . '</a>';
124 }
125
126 if ($count > 1)
127 {
128 // reach the employees list to start pick a record to edit
129 return '<a href="index.php?option=com_vikappointments&view=employees" class="btn btn-success">' . JText::translate('VAPEDIT') . '</a>';
130 }
131
132 // point to the controller for creating a new employee
133 return '<a href="index.php?option=com_vikappointments&task=employee.add" class="btn btn-success">' . JText::translate('VAPNEW') . '</a>';
134 }
135
136 /**
137 * Returns a list of created employees.
138 *
139 * @return array A list of employees.
140 */
141 public function getEmployees()
142 {
143 static $employees = null;
144
145 // get employees only once
146 if (is_null($employees))
147 {
148 $dbo = JFactory::getDbo();
149
150 $q = $dbo->getQuery(true)
151 ->select($dbo->qn(array('e.id', 'e.nickname')))
152 ->select($dbo->qn('w.id', 'id_worktime'))
153 ->from($dbo->qn('#__vikappointments_employee', 'e'))
154 ->leftjoin($dbo->qn('#__vikappointments_emp_worktime', 'w') . ' ON ' . $dbo->qn('w.id_employee') . ' = ' . $dbo->qn('e.id'))
155 ->group($dbo->qn('e.id'))
156 ->order($dbo->qn('e.id') . ' ASC');
157
158 $dbo->setQuery($q);
159 $employees = $dbo->loadObjectList();
160 }
161
162 return $employees;
163 }
164 }
165