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 / employee / area / manager.php
vikappointments / site / helpers / libraries / employee / area Last commit date
controller.php 6 days ago fieldcontrol.php 6 days ago index.html 6 days ago manager.php 6 days ago toolbar.php 6 days ago
manager.php
118 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 * Class used to manage the employees area.
16 *
17 * @since 1.7
18 */
19 class VAPEmployeeAreaManager
20 {
21 /**
22 * Checks if a user can register a new account.
23 *
24 * @return boolean True if allowed, false otherwise.
25 */
26 public static function canRegister()
27 {
28 $setting = VAPFactory::getConfig()->getBool('empsignup');
29
30 // allow plugins to override this setting
31 return (bool) static::override('config.register', $setting);
32 }
33
34 /**
35 * Returns the default status of an employee after its registration.
36 *
37 * @return string The default status.
38 */
39 public static function getSignUpStatus()
40 {
41 $setting = VAPFactory::getConfig()->getString('empsignstatus');
42
43 // allow plugins to override this setting
44 return (string) static::override('config.signup.status', $setting);
45 }
46
47 /**
48 * Returns the default user group assigned to the employee.
49 *
50 * @return string The default user group.
51 */
52 public static function getSignUpUserGroup()
53 {
54 $setting = VAPFactory::getConfig()->getString('empsignrule');
55
56 // allow plugins to override this setting
57 return (string) static::override('config.signup.group', $setting);
58 }
59
60 /**
61 * Returns the list of all the services to auto-assign to the employee.
62 *
63 * @return array The default assigned services.
64 */
65 public static function getServicesToAssign()
66 {
67 $setting = VAPFactory::getConfig()->getString('empassignser');
68 $setting = array_filter(array_map('intval', explode(',', $setting)));
69
70 // allow plugins to override this setting
71 return (array) static::override('config.services', $setting);
72 }
73
74 /**
75 * Returns the toolbar instance.
76 *
77 * @return VAPEmployeeAreaToolbar
78 */
79 public static function getToolbar()
80 {
81 VAPLoader::import('libraries.employee.area.toolbar');
82 return VAPEmployeeAreaToolbar::getInstance();
83 }
84
85 /**
86 * Helper method used to extend the roles that an employee can perform.
87 *
88 * @param string $role The role to check.
89 * @param mixed $setting The default setting value.
90 * @param mixed $handler The employee wrapper instance or null.
91 *
92 * @return mixed The value to return.
93 */
94 public static function override($role, $setting, $handler = null)
95 {
96 /**
97 * Trigger event to allow external plugins to override a specific setting
98 * of the employees area.
99 *
100 * @param string $role The role to check.
101 * @param mixed $setting The default setting value.
102 * @param mixed $handler The employee wrapper instance or null.
103 *
104 * @return mixed The value to return.
105 *
106 * @since 1.7
107 */
108 $result = VAPFactory::getEventDispatcher()->triggerOnce('onOverrideEmployeesAreaSetting', array($role, $setting, $handler));
109
110 if (!is_null($result))
111 {
112 return $result;
113 }
114
115 return $setting;
116 }
117 }
118