2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2016-04-27 09:21:40 +03:00
|
|
|
*
|
2015-07-20 22:41:24 +03:00
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2015-07-20 22:41:24 +03:00
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2013-08-26 14:53:11 +03:00
|
|
|
/**
|
2021-11-06 18:21:27 +03:00
|
|
|
* Secretaries model.
|
2016-04-27 09:21:40 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* Handles all the database operations of the secretary resource.
|
2016-04-27 09:21:40 +03:00
|
|
|
*
|
2015-07-08 01:36:16 +03:00
|
|
|
* @package Models
|
2013-08-26 14:53:11 +03:00
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
class Secretaries_model extends EA_Model
|
|
|
|
{
|
2021-10-29 13:39:14 +03:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-03-13 11:06:18 +03:00
|
|
|
protected array $casts = [
|
2021-10-29 13:39:14 +03:00
|
|
|
'id' => 'integer',
|
2023-12-22 13:35:41 +03:00
|
|
|
'id_roles' => 'integer',
|
2021-10-29 13:39:14 +03:00
|
|
|
];
|
|
|
|
|
2021-11-06 17:02:40 +03:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-03-13 11:06:18 +03:00
|
|
|
protected array $api_resource = [
|
2021-11-06 17:02:40 +03:00
|
|
|
'id' => 'id',
|
|
|
|
'firstName' => 'first_name',
|
|
|
|
'lastName' => 'last_name',
|
|
|
|
'email' => 'email',
|
|
|
|
'mobile' => 'mobile_number',
|
|
|
|
'phone' => 'phone_number',
|
|
|
|
'address' => 'address',
|
|
|
|
'city' => 'city',
|
|
|
|
'state' => 'state',
|
|
|
|
'zip' => 'zip_code',
|
|
|
|
'timezone' => 'timezone',
|
|
|
|
'language' => 'language',
|
|
|
|
'notes' => 'notes',
|
2024-05-14 00:36:54 +03:00
|
|
|
'ldapDn' => 'ldap_dn',
|
2023-12-22 13:35:41 +03:00
|
|
|
'roleId' => 'id_roles',
|
2021-11-06 17:02:40 +03:00
|
|
|
];
|
|
|
|
|
2013-08-26 14:53:11 +03:00
|
|
|
/**
|
2021-10-27 11:04:35 +03:00
|
|
|
* Save (insert or update) a secretary.
|
2016-04-27 09:21:40 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @param array $secretary Associative array with the secretary data.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @return int Returns the secretary ID.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @throws InvalidArgumentException
|
2023-03-13 11:06:18 +03:00
|
|
|
* @throws Exception
|
2013-08-26 14:53:11 +03:00
|
|
|
*/
|
2021-10-27 11:04:35 +03:00
|
|
|
public function save(array $secretary): int
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
$this->validate($secretary);
|
2013-09-03 21:58:56 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($secretary['id'])) {
|
2021-10-27 11:04:35 +03:00
|
|
|
return $this->insert($secretary);
|
2023-11-29 12:24:09 +03:00
|
|
|
} else {
|
2021-10-27 11:04:35 +03:00
|
|
|
return $this->update($secretary);
|
2013-08-26 14:53:11 +03:00
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
/**
|
2021-10-27 11:04:35 +03:00
|
|
|
* Validate the secretary data.
|
2020-04-22 22:48:56 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @param array $secretary Associative array with the secretary data.
|
2020-04-22 22:48:56 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @throws InvalidArgumentException
|
2020-04-22 22:48:56 +03:00
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function validate(array $secretary): void
|
2020-04-22 22:48:56 +03:00
|
|
|
{
|
2021-10-27 11:04:35 +03:00
|
|
|
// If a secretary ID is provided then check whether the record really exists in the database.
|
2024-03-18 14:38:09 +03:00
|
|
|
if (!empty($secretary['id'])) {
|
2021-10-27 11:04:35 +03:00
|
|
|
$count = $this->db->get_where('users', ['id' => $secretary['id']])->num_rows();
|
2020-12-05 12:38:57 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!$count) {
|
|
|
|
throw new InvalidArgumentException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'The provided secretary ID does not exist in the database: ' . $secretary['id'],
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 17:25:45 +03:00
|
|
|
// Make sure all required fields are provided.
|
2021-10-27 11:04:35 +03:00
|
|
|
if (
|
2023-11-29 12:24:09 +03:00
|
|
|
empty($secretary['first_name']) ||
|
|
|
|
empty($secretary['last_name']) ||
|
|
|
|
empty($secretary['email']) ||
|
|
|
|
empty($secretary['phone_number'])
|
|
|
|
) {
|
|
|
|
throw new InvalidArgumentException('Not all required fields are provided: ' . print_r($secretary, true));
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
// Validate the email address.
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!filter_var($secretary['email'], FILTER_VALIDATE_EMAIL)) {
|
2021-10-27 11:04:35 +03:00
|
|
|
throw new InvalidArgumentException('Invalid email address provided: ' . $secretary['email']);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
// Validate secretary providers.
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!empty($secretary['providers'])) {
|
2021-10-27 11:04:35 +03:00
|
|
|
// Make sure the provided provider entries are numeric values.
|
2024-03-18 14:54:08 +03:00
|
|
|
foreach ($secretary['providers'] as $provider_id) {
|
|
|
|
if (!is_numeric($provider_id)) {
|
2023-11-29 12:24:09 +03:00
|
|
|
throw new InvalidArgumentException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'The provided secretary providers are invalid: ' . print_r($secretary, true),
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2021-10-27 11:04:35 +03:00
|
|
|
}
|
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
|
2023-10-19 17:25:45 +03:00
|
|
|
// Make sure the username is unique.
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!empty($secretary['settings']['username'])) {
|
|
|
|
$secretary_id = $secretary['id'] ?? null;
|
2021-10-27 11:04:35 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!$this->validate_username($secretary['settings']['username'], $secretary_id)) {
|
|
|
|
throw new InvalidArgumentException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'The provided username is already in use, please use a different one.',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 17:25:45 +03:00
|
|
|
// Validate the password.
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!empty($secretary['settings']['password'])) {
|
|
|
|
if (strlen($secretary['settings']['password']) < MIN_PASSWORD_LENGTH) {
|
|
|
|
throw new InvalidArgumentException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'The secretary password must be at least ' . MIN_PASSWORD_LENGTH . ' characters long.',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 17:25:45 +03:00
|
|
|
// New users must always have a password value set.
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($secretary['id']) && empty($secretary['settings']['password'])) {
|
2024-11-20 21:28:42 +03:00
|
|
|
throw new InvalidArgumentException('The secretary password cannot be empty when inserting a new record.');
|
2020-12-11 22:18:33 +03:00
|
|
|
}
|
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
// Validate calendar view type value.
|
|
|
|
if (
|
2023-11-29 12:24:09 +03:00
|
|
|
!empty($secretary['settings']['calendar_view']) &&
|
|
|
|
!in_array($secretary['settings']['calendar_view'], [CALENDAR_VIEW_DEFAULT, CALENDAR_VIEW_TABLE])
|
|
|
|
) {
|
|
|
|
throw new InvalidArgumentException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'The provided calendar view is invalid: ' . $secretary['settings']['calendar_view'],
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
// Make sure the email address is unique.
|
2023-11-29 12:24:09 +03:00
|
|
|
$secretary_id = $secretary['id'] ?? null;
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$count = $this->db
|
2021-10-27 11:04:35 +03:00
|
|
|
->select()
|
2020-04-23 21:48:20 +03:00
|
|
|
->from('users')
|
2020-05-02 13:51:06 +03:00
|
|
|
->join('roles', 'roles.id = users.id_roles', 'inner')
|
2020-04-23 21:48:20 +03:00
|
|
|
->where('roles.slug', DB_SLUG_SECRETARY)
|
|
|
|
->where('users.email', $secretary['email'])
|
2020-12-05 12:38:57 +03:00
|
|
|
->where('users.id !=', $secretary_id)
|
2020-04-22 22:48:56 +03:00
|
|
|
->get()
|
|
|
|
->num_rows();
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if ($count > 0) {
|
|
|
|
throw new InvalidArgumentException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'The provided email address is already in use, please use a different one.',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-27 11:04:35 +03:00
|
|
|
* Validate the secretary username.
|
2020-04-22 22:48:56 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @param string $username Secretary username.
|
|
|
|
* @param int|null $secretary_id Secretary ID.
|
2020-04-22 22:48:56 +03:00
|
|
|
*
|
|
|
|
* @return bool Returns the validation result.
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
public function validate_username(string $username, int $secretary_id = null): bool
|
2020-04-22 22:48:56 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!empty($secretary_id)) {
|
2021-10-27 11:04:35 +03:00
|
|
|
$this->db->where('id_users !=', $secretary_id);
|
2020-12-08 12:00:31 +03:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
return $this->db
|
|
|
|
->from('users')
|
|
|
|
->join('user_settings', 'user_settings.id_users = users.id', 'inner')
|
|
|
|
->where(['username' => $username])
|
|
|
|
->get()
|
|
|
|
->num_rows() === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all secretaries that match the provided criteria.
|
|
|
|
*
|
|
|
|
* @param array|string|null $where Where conditions
|
|
|
|
* @param int|null $limit Record limit.
|
|
|
|
* @param int|null $offset Record offset.
|
|
|
|
* @param string|null $order_by Order by.
|
|
|
|
*
|
|
|
|
* @return array Returns an array of secretaries.
|
|
|
|
*/
|
|
|
|
public function get(
|
|
|
|
array|string $where = null,
|
|
|
|
int $limit = null,
|
|
|
|
int $offset = null,
|
2023-12-22 13:35:41 +03:00
|
|
|
string $order_by = null,
|
2023-11-29 12:24:09 +03:00
|
|
|
): array {
|
|
|
|
$role_id = $this->get_secretary_role_id();
|
|
|
|
|
|
|
|
if ($where !== null) {
|
|
|
|
$this->db->where($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($order_by !== null) {
|
|
|
|
$this->db->order_by($order_by);
|
|
|
|
}
|
|
|
|
|
|
|
|
$secretaries = $this->db->get_where('users', ['id_roles' => $role_id], $limit, $offset)->result_array();
|
|
|
|
|
|
|
|
foreach ($secretaries as &$secretary) {
|
2024-05-11 18:03:54 +03:00
|
|
|
$this->cast($secretary);
|
|
|
|
$secretary['settings'] = $this->get_settings($secretary['id']);
|
|
|
|
$secretary['providers'] = $this->get_provider_ids($secretary['id']);
|
2023-11-29 12:24:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $secretaries;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the secretary role ID.
|
|
|
|
*
|
|
|
|
* @return int Returns the role ID.
|
|
|
|
*/
|
|
|
|
public function get_secretary_role_id(): int
|
|
|
|
{
|
|
|
|
$role = $this->db->get_where('roles', ['slug' => DB_SLUG_SECRETARY])->row_array();
|
|
|
|
|
|
|
|
if (empty($role)) {
|
|
|
|
throw new RuntimeException('The secretary role was not found in the database.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $role['id'];
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
|
2013-08-26 14:53:11 +03:00
|
|
|
/**
|
2021-10-27 11:04:35 +03:00
|
|
|
* Insert a new secretary into the database.
|
2016-04-27 09:21:40 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @param array $secretary Associative array with the secretary data.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @return int Returns the secretary ID.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2023-03-13 11:06:18 +03:00
|
|
|
* @throws RuntimeException|Exception
|
2013-08-26 14:53:11 +03:00
|
|
|
*/
|
2021-10-27 11:04:35 +03:00
|
|
|
protected function insert(array $secretary): int
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2022-01-25 01:42:13 +03:00
|
|
|
$secretary['create_datetime'] = date('Y-m-d H:i:s');
|
|
|
|
$secretary['update_datetime'] = date('Y-m-d H:i:s');
|
2022-11-30 13:21:39 +03:00
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
$secretary['id_roles'] = $this->get_secretary_role_id();
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2022-03-25 14:46:49 +03:00
|
|
|
$provider_ids = $secretary['providers'] ?? [];
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
$settings = $secretary['settings'];
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
unset($secretary['providers'], $secretary['settings']);
|
2021-10-27 11:04:35 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!$this->db->insert('users', $secretary)) {
|
2021-10-27 11:04:35 +03:00
|
|
|
throw new RuntimeException('Could not insert secretary.');
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
$secretary['id'] = $this->db->insert_id();
|
|
|
|
$settings['salt'] = generate_salt();
|
|
|
|
$settings['password'] = hash_password($settings['salt'], $settings['password']);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2024-05-11 18:03:54 +03:00
|
|
|
$this->set_settings($secretary['id'], $settings);
|
|
|
|
$this->set_provider_ids($secretary['id'], $provider_ids);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
return $secretary['id'];
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
/**
|
2024-05-11 18:03:54 +03:00
|
|
|
* Set the secretary settings.
|
2023-11-29 12:24:09 +03:00
|
|
|
*
|
|
|
|
* @param int $secretary_id Secretary ID.
|
|
|
|
* @param array $settings Associative array with the settings data.
|
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
2024-05-11 18:03:54 +03:00
|
|
|
public function set_settings(int $secretary_id, array $settings): void
|
2023-11-29 12:24:09 +03:00
|
|
|
{
|
|
|
|
if (empty($settings)) {
|
|
|
|
throw new InvalidArgumentException('The settings argument cannot be empty.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the settings record exists in the database.
|
|
|
|
$count = $this->db->get_where('user_settings', ['id_users' => $secretary_id])->num_rows();
|
|
|
|
|
|
|
|
if (!$count) {
|
|
|
|
$this->db->insert('user_settings', ['id_users' => $secretary_id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($settings as $name => $value) {
|
|
|
|
$this->set_setting($secretary_id, $name, $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-11 18:03:54 +03:00
|
|
|
/**
|
|
|
|
* Get the secretary settings.
|
|
|
|
*
|
|
|
|
* @param int $secretary_id Secretary ID.
|
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function get_settings(int $secretary_id): array
|
|
|
|
{
|
|
|
|
$settings = $this->db->get_where('user_settings', ['id_users' => $secretary_id])->row_array();
|
|
|
|
|
|
|
|
unset($settings['id_users'], $settings['password'], $settings['salt']);
|
|
|
|
|
|
|
|
return $settings;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
/**
|
|
|
|
* Set the value of a secretary setting.
|
|
|
|
*
|
|
|
|
* @param int $secretary_id Secretary ID.
|
|
|
|
* @param string $name Setting name.
|
|
|
|
* @param mixed|null $value Setting value.
|
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function set_setting(int $secretary_id, string $name, mixed $value = null): void
|
2023-11-29 12:24:09 +03:00
|
|
|
{
|
|
|
|
if (!$this->db->update('user_settings', [$name => $value], ['id_users' => $secretary_id])) {
|
|
|
|
throw new RuntimeException('Could not set the new secretary setting value: ' . $name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
/**
|
2021-10-27 11:04:35 +03:00
|
|
|
* Update an existing secretary.
|
2016-04-27 09:21:40 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @param array $secretary Associative array with the secretary data.
|
2017-09-15 14:36:37 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @return int Returns the secretary ID.
|
2017-09-15 14:36:37 +03:00
|
|
|
*
|
2023-03-13 11:06:18 +03:00
|
|
|
* @throws RuntimeException|Exception
|
2013-08-26 14:53:11 +03:00
|
|
|
*/
|
2021-10-27 11:04:35 +03:00
|
|
|
protected function update(array $secretary): int
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2022-01-25 01:42:13 +03:00
|
|
|
$secretary['update_datetime'] = date('Y-m-d H:i:s');
|
2022-11-30 13:21:39 +03:00
|
|
|
|
2022-01-07 11:44:51 +03:00
|
|
|
$provider_ids = $secretary['providers'] ?? [];
|
2021-10-27 11:04:35 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
$settings = $secretary['settings'];
|
2022-03-25 14:46:49 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
unset($secretary['providers'], $secretary['settings']);
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (isset($settings['password'])) {
|
2021-10-27 11:04:35 +03:00
|
|
|
$existing_settings = $this->db->get_where('user_settings', ['id_users' => $secretary['id']])->row_array();
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($existing_settings)) {
|
2021-10-27 11:04:35 +03:00
|
|
|
throw new RuntimeException('No settings record found for secretary with ID: ' . $secretary['id']);
|
|
|
|
}
|
|
|
|
|
2024-01-12 15:05:24 +03:00
|
|
|
if (empty($existing_settings['salt'])) {
|
|
|
|
$existing_settings['salt'] = $settings['salt'] = generate_salt();
|
|
|
|
}
|
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
$settings['password'] = hash_password($existing_settings['salt'], $settings['password']);
|
2013-08-26 14:53:11 +03:00
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!$this->db->update('users', $secretary, ['id' => $secretary['id']])) {
|
2021-10-27 11:04:35 +03:00
|
|
|
throw new RuntimeException('Could not update secretary.');
|
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2024-05-11 18:03:54 +03:00
|
|
|
$this->set_settings($secretary['id'], $settings);
|
|
|
|
$this->set_provider_ids($secretary['id'], $provider_ids);
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
return (int) $secretary['id'];
|
2016-04-27 09:21:40 +03:00
|
|
|
}
|
|
|
|
|
2013-08-26 14:53:11 +03:00
|
|
|
/**
|
2024-05-11 18:03:54 +03:00
|
|
|
* Set the secretary provider IDs.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2023-11-29 12:24:09 +03:00
|
|
|
* @param int $secretary_id Secretary ID.
|
|
|
|
* @param array $provider_ids Provider IDs.
|
2013-08-26 14:53:11 +03:00
|
|
|
*/
|
2024-05-11 18:03:54 +03:00
|
|
|
public function set_provider_ids(int $secretary_id, array $provider_ids): void
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
// Re-insert the secretary-provider connections.
|
|
|
|
$this->db->delete('secretaries_providers', ['id_users_secretary' => $secretary_id]);
|
|
|
|
|
|
|
|
foreach ($provider_ids as $provider_id) {
|
|
|
|
$secretary_provider_connection = [
|
|
|
|
'id_users_secretary' => $secretary_id,
|
2023-12-22 13:35:41 +03:00
|
|
|
'id_users_provider' => $provider_id,
|
2023-11-29 12:24:09 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->db->insert('secretaries_providers', $secretary_provider_connection);
|
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2024-05-11 18:03:54 +03:00
|
|
|
/**
|
|
|
|
* Get the secretary provider IDs.
|
|
|
|
*
|
|
|
|
* @param int $secretary_id Secretary ID.
|
|
|
|
*/
|
|
|
|
public function get_provider_ids(int $secretary_id): array
|
|
|
|
{
|
|
|
|
$secretary_provider_connections = $this->db
|
|
|
|
->get_where('secretaries_providers', ['id_users_secretary' => $secretary_id])
|
|
|
|
->result_array();
|
|
|
|
|
|
|
|
$provider_ids = [];
|
|
|
|
|
|
|
|
foreach ($secretary_provider_connections as $secretary_provider_connection) {
|
|
|
|
$provider_ids[] = (int) $secretary_provider_connection['id_users_provider'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $provider_ids;
|
|
|
|
}
|
|
|
|
|
2013-08-26 14:53:11 +03:00
|
|
|
/**
|
2023-11-29 12:24:09 +03:00
|
|
|
* Remove an existing secretary from the database.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2023-11-29 12:24:09 +03:00
|
|
|
* @param int $secretary_id Provider ID.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2023-11-29 12:24:09 +03:00
|
|
|
* @throws RuntimeException
|
2013-08-26 14:53:11 +03:00
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
public function delete(int $secretary_id): void
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->delete('users', ['id' => $secretary_id]);
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2013-08-26 14:53:11 +03:00
|
|
|
/**
|
2021-10-27 11:04:35 +03:00
|
|
|
* Get a specific field value from the database.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @param int $secretary_id Secretary ID.
|
|
|
|
* @param string $field Name of the value to be returned.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2023-01-14 11:39:14 +03:00
|
|
|
* @return mixed Returns the selected secretary value from the database.
|
2021-10-27 11:04:35 +03:00
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException
|
2013-08-26 14:53:11 +03:00
|
|
|
*/
|
2023-01-14 11:39:14 +03:00
|
|
|
public function value(int $secretary_id, string $field): mixed
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($field)) {
|
2021-10-27 11:04:35 +03:00
|
|
|
throw new InvalidArgumentException('The field argument is cannot be empty.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($secretary_id)) {
|
2021-10-27 11:04:35 +03:00
|
|
|
throw new InvalidArgumentException('The secretary ID argument cannot be empty.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
// Check whether the secretary exists.
|
|
|
|
$query = $this->db->get_where('users', ['id' => $secretary_id]);
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!$query->num_rows()) {
|
|
|
|
throw new InvalidArgumentException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'The provided secretary ID was not found in the database: ' . $secretary_id,
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
// Check if the required field is part of the secretary data.
|
|
|
|
$secretary = $query->row_array();
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!array_key_exists($field, $secretary)) {
|
2021-10-27 11:04:35 +03:00
|
|
|
throw new InvalidArgumentException('The requested field was not found in the secretary data: ' . $field);
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
return $secretary[$field];
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
2013-09-26 19:06:57 +03:00
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
/**
|
|
|
|
* Get the value of a secretary setting.
|
|
|
|
*
|
|
|
|
* @param int $secretary_id Secretary ID.
|
|
|
|
* @param string $name Setting name.
|
|
|
|
*
|
|
|
|
* @return string Returns the value of the requested user setting.
|
|
|
|
*/
|
|
|
|
public function get_setting(int $secretary_id, string $name): string
|
|
|
|
{
|
|
|
|
$settings = $this->db->get_where('user_settings', ['id_users' => $secretary_id])->row_array();
|
2020-12-05 12:43:38 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!array_key_exists($name, $settings)) {
|
2021-10-27 11:04:35 +03:00
|
|
|
throw new RuntimeException('The requested setting value was not found: ' . $secretary_id);
|
2013-08-26 14:53:11 +03:00
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
return $settings[$name];
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
/**
|
|
|
|
* Get the query builder interface, configured for use with the users (secretary-filtered) table.
|
|
|
|
*
|
|
|
|
* @return CI_DB_query_builder
|
|
|
|
*/
|
|
|
|
public function query(): CI_DB_query_builder
|
|
|
|
{
|
|
|
|
$role_id = $this->get_secretary_role_id();
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
return $this->db->from('users')->where('id_roles', $role_id);
|
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2021-10-27 11:04:35 +03:00
|
|
|
/**
|
|
|
|
* Search secretaries by the provided keyword.
|
|
|
|
*
|
|
|
|
* @param string $keyword Search keyword.
|
|
|
|
* @param int|null $limit Record limit.
|
|
|
|
* @param int|null $offset Record offset.
|
|
|
|
* @param string|null $order_by Order by.
|
2022-11-30 13:21:39 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @return array Returns an array of secretaries.
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
public function search(string $keyword, int $limit = null, int $offset = null, string $order_by = null): array
|
2021-10-27 11:04:35 +03:00
|
|
|
{
|
|
|
|
$role_id = $this->get_secretary_role_id();
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$secretaries = $this->db
|
2021-10-27 11:04:35 +03:00
|
|
|
->select()
|
|
|
|
->from('users')
|
|
|
|
->where('id_roles', $role_id)
|
2021-11-06 17:02:40 +03:00
|
|
|
->group_start()
|
2021-10-27 11:04:35 +03:00
|
|
|
->like('first_name', $keyword)
|
|
|
|
->or_like('last_name', $keyword)
|
2022-12-12 11:15:55 +03:00
|
|
|
->or_like('CONCAT_WS(" ", first_name, last_name)', $keyword)
|
2021-10-27 11:04:35 +03:00
|
|
|
->or_like('email', $keyword)
|
|
|
|
->or_like('phone_number', $keyword)
|
|
|
|
->or_like('mobile_number', $keyword)
|
|
|
|
->or_like('address', $keyword)
|
|
|
|
->or_like('city', $keyword)
|
|
|
|
->or_like('state', $keyword)
|
|
|
|
->or_like('zip_code', $keyword)
|
|
|
|
->or_like('notes', $keyword)
|
2021-11-06 17:02:40 +03:00
|
|
|
->group_end()
|
2021-10-27 11:04:35 +03:00
|
|
|
->limit($limit)
|
|
|
|
->offset($offset)
|
|
|
|
->order_by($order_by)
|
|
|
|
->get()
|
|
|
|
->result_array();
|
2021-10-29 13:39:14 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
foreach ($secretaries as &$secretary) {
|
2024-05-11 18:03:54 +03:00
|
|
|
$this->cast($secretary);
|
|
|
|
$secretary['settings'] = $this->get_settings($secretary['id']);
|
|
|
|
$secretary['providers'] = $this->get_provider_ids($secretary['id']);
|
2021-10-29 13:39:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $secretaries;
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
2016-04-27 09:21:40 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2021-11-06 17:40:55 +03:00
|
|
|
* Load related resources to a secretary.
|
2016-04-27 09:21:40 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @param array $secretary Associative array with the secretary data.
|
|
|
|
* @param array $resources Resource names to be attached ("providers" supported).
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2021-10-27 11:04:35 +03:00
|
|
|
* @throws InvalidArgumentException
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function load(array &$secretary, array $resources): void
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($secretary) || empty($resources)) {
|
2021-10-27 11:04:35 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
foreach ($resources as $resource) {
|
|
|
|
$secretary['providers'] = match ($resource) {
|
|
|
|
'providers' => $this->db
|
2023-03-13 11:06:18 +03:00
|
|
|
->select('users.*')
|
|
|
|
->from('users')
|
|
|
|
->join('secretaries_providers', 'secretaries_providers.id_users_provider = users.id', 'inner')
|
|
|
|
->where('id_users_secretary', $secretary['id'])
|
|
|
|
->get()
|
|
|
|
->result_array(),
|
2023-11-29 12:24:09 +03:00
|
|
|
default => throw new InvalidArgumentException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'The requested secretary relation is not supported: ' . $resource,
|
|
|
|
),
|
2023-03-13 11:06:18 +03:00
|
|
|
};
|
2021-10-27 11:04:35 +03:00
|
|
|
}
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2021-11-05 11:32:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the database secretary record to the equivalent API resource.
|
|
|
|
*
|
|
|
|
* @param array $secretary Secretary data.
|
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function api_encode(array &$secretary): void
|
2021-11-05 11:32:34 +03:00
|
|
|
{
|
|
|
|
$encoded_resource = [
|
2023-11-29 12:24:09 +03:00
|
|
|
'id' => array_key_exists('id', $secretary) ? (int) $secretary['id'] : null,
|
2021-11-05 11:32:34 +03:00
|
|
|
'firstName' => $secretary['first_name'],
|
|
|
|
'lastName' => $secretary['last_name'],
|
|
|
|
'email' => $secretary['email'],
|
|
|
|
'mobile' => $secretary['mobile_number'],
|
|
|
|
'phone' => $secretary['phone_number'],
|
|
|
|
'address' => $secretary['address'],
|
|
|
|
'city' => $secretary['city'],
|
|
|
|
'state' => $secretary['state'],
|
|
|
|
'zip' => $secretary['zip_code'],
|
|
|
|
'notes' => $secretary['notes'],
|
|
|
|
'providers' => $secretary['providers'],
|
|
|
|
'timezone' => $secretary['timezone'],
|
2024-05-14 00:36:54 +03:00
|
|
|
'language' => $secretary['language'],
|
|
|
|
'ldapDn' => $secretary['ldap_dn'],
|
2021-11-05 11:32:34 +03:00
|
|
|
'settings' => [
|
|
|
|
'username' => $secretary['settings']['username'],
|
|
|
|
'notifications' => filter_var($secretary['settings']['notifications'], FILTER_VALIDATE_BOOLEAN),
|
2023-12-22 13:35:41 +03:00
|
|
|
'calendarView' => $secretary['settings']['calendar_view'],
|
|
|
|
],
|
2021-11-05 11:32:34 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
$secretary = $encoded_resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the API resource to the equivalent database secretary record.
|
|
|
|
*
|
|
|
|
* @param array $secretary API resource.
|
|
|
|
* @param array|null $base Base secretary data to be overwritten with the provided values (useful for updates).
|
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function api_decode(array &$secretary, array $base = null): void
|
2021-11-05 11:32:34 +03:00
|
|
|
{
|
|
|
|
$decoded_resource = $base ?: [];
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('id', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['id'] = $secretary['id'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('firstName', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['first_name'] = $secretary['firstName'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('lastName', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['last_name'] = $secretary['lastName'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('email', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['email'] = $secretary['email'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('mobile', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['mobile_number'] = $secretary['mobile'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('phone', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['phone_number'] = $secretary['phone'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('address', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['address'] = $secretary['address'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('city', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['city'] = $secretary['city'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('state', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['state'] = $secretary['state'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('zip', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['zip_code'] = $secretary['zip'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('notes', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['notes'] = $secretary['notes'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('timezone', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['timezone'] = $secretary['timezone'];
|
|
|
|
}
|
|
|
|
|
2024-05-14 00:36:54 +03:00
|
|
|
if (array_key_exists('language', $secretary)) {
|
|
|
|
$decoded_resource['language'] = $secretary['language'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('ldapDn', $secretary)) {
|
|
|
|
$decoded_resource['ldap_dn'] = $secretary['ldapDn'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('providers', $secretary)) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['providers'] = $secretary['providers'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('settings', $secretary)) {
|
|
|
|
if (empty($decoded_resource['settings'])) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['settings'] = [];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('username', $secretary['settings'])) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['settings']['username'] = $secretary['settings']['username'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('password', $secretary['settings'])) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['settings']['password'] = $secretary['settings']['password'];
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('notifications', $secretary['settings'])) {
|
|
|
|
$decoded_resource['settings']['notifications'] = filter_var(
|
|
|
|
$secretary['settings']['notifications'],
|
2023-12-22 13:35:41 +03:00
|
|
|
FILTER_VALIDATE_BOOLEAN,
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2021-11-05 11:32:34 +03:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (array_key_exists('calendarView', $secretary['settings'])) {
|
2021-11-05 11:32:34 +03:00
|
|
|
$decoded_resource['settings']['calendar_view'] = $secretary['settings']['calendarView'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$secretary = $decoded_resource;
|
|
|
|
}
|
2023-04-15 15:34:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Quickly check if a provider is assigned to a provider.
|
2023-10-19 17:25:45 +03:00
|
|
|
*
|
2023-04-15 15:34:42 +03:00
|
|
|
* @param int $secretary_id
|
|
|
|
* @param int $provider_id
|
2023-10-19 17:25:45 +03:00
|
|
|
*
|
2023-04-15 15:34:42 +03:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function is_provider_supported(int $secretary_id, int $provider_id): bool
|
|
|
|
{
|
|
|
|
$secretary = $this->find($secretary_id);
|
|
|
|
|
|
|
|
return in_array($provider_id, $secretary['providers']);
|
|
|
|
}
|
2023-11-29 12:24:09 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a specific secretary from the database.
|
|
|
|
*
|
|
|
|
* @param int $secretary_id The ID of the record to be returned.
|
|
|
|
*
|
|
|
|
* @return array Returns an array with the secretary data.
|
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function find(int $secretary_id): array
|
|
|
|
{
|
|
|
|
$secretary = $this->db->get_where('users', ['id' => $secretary_id])->row_array();
|
|
|
|
|
|
|
|
if (!$secretary) {
|
|
|
|
throw new InvalidArgumentException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'The provided secretary ID was not found in the database: ' . $secretary_id,
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-05-11 18:03:54 +03:00
|
|
|
$this->cast($secretary);
|
|
|
|
$secretary['settings'] = $this->get_settings($secretary['id']);
|
|
|
|
$secretary['providers'] = $this->get_provider_ids($secretary['id']);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
|
|
|
return $secretary;
|
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|