Override Setting
publc function onOverrideEmployeesAreaSetting(string $role, mixed $setting, mixed $handler) : mixed
Fires while fetching a setting for the employees area.
Description
Trigger hook to allow external plugins to override a specific setting of the employees area.
Here's the full list of settings (roles) that can be overwritten at runtime:
config.register
config.signup.status
config.signup.group
config.services
profile.manage
service.create
service.manage
service.override
service.assign
service.remove
service.max
payment.manage
coupon.manage
field.manage
worktime.manage
location.manage
reservation.create
reservation.manage
reservation.confirm
reservation.remove
reservation.notify
Parameters
- $role
-
(string) The identifier of the role to override.
- $setting
-
(mixed) The default setting value.
- $handler
-
(VAPEmployeeAuth|null) The employee wrapper instance or null.
Return Value
Mixed. The value to return. Return NULL to use the default value.
Example
The example below explains how to have dynamic settings, which may vary depending on the purchased subscription plan. In this case, we are going to increase the maximum number of services that can be created, depending on the latest purchased subscription. In example:
- Basic (ID #1) - 5 services
- Advanced (ID #2) - 10 services
- Premium (ID #3) - 15 services
/**
* Trigger event to allow external plugins to override a specific setting
* of the employees area.
*
* @param string $role The role to check.
* @param mixed $setting The default setting value.
* @param mixed $handler The employee wrapper instance or null.
*
* @return mixed The value to return, NULL to use the default one.
*/
public function onOverrideEmployeesAreaSetting($role, $setting, $handler)
{
$value = null;
if ($role !== 'service.max')
{
return $value;
}
$dbo = JFactory::getDbo();
// fetch the latest purchased subscription
$q = $dbo->getQuery(true)
->select($dbo->qn('id_subscr'))
->from($dbo->qn('#__vikappointments_subscr_order'))
->where($dbo->qn('id_employee') . ' = ' . (int) $handler->id)
->where($dbo->qn('status') . ' IN (\'P\', \'C\')')
->order($dbo->qn('id') . ' DESC');
$dbo->setQuery($q, 0, 1);
$dbo->execute();
if ($dbo->getNumRows())
{
switch ((int) $dbo->loadResult())
{
// basic
case 1:
$value = 5;
break;
// advanced
case 2:
$value = 10;
break;
// premium
case 3:
$value = 15;
break;
}
}
return $value;
}
Changelog
Version | Description |
---|---|
1.7 | Introduced. |
Last Update: 2021-10-08 09:41
Helpful?