2021-10-23 14:21:30 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2021-10-23 14:21:30 +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
|
2021-10-23 14:29:31 +03:00
|
|
|
* @since v1.5.0
|
2021-10-23 14:21:30 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!function_exists('setting')) {
|
2021-10-23 14:21:30 +03:00
|
|
|
/**
|
|
|
|
* Get / set the specified setting value.
|
|
|
|
*
|
|
|
|
* If an array is passed as the key, we will assume you want to set an array of values.
|
|
|
|
*
|
|
|
|
* Example "Get":
|
|
|
|
*
|
|
|
|
* $company_name = session('company_name', FALSE);
|
|
|
|
*
|
|
|
|
* Example "Set":
|
|
|
|
*
|
|
|
|
* setting(['company_name' => 'ACME Inc']);
|
|
|
|
*
|
2023-03-13 11:06:18 +03:00
|
|
|
* @param array|string|null $key Setting key.
|
|
|
|
* @param mixed|null $default Default value in case the requested setting has no value.
|
2021-10-23 14:21:30 +03:00
|
|
|
*
|
2021-10-28 14:27:14 +03:00
|
|
|
* @return mixed|NULL Returns the requested value or NULL if you assign a new setting value.
|
2021-10-23 14:21:30 +03:00
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
2024-12-19 21:13:51 +03:00
|
|
|
function setting(array|string|null $key = null, mixed $default = null): mixed
|
2021-10-23 14:21:30 +03:00
|
|
|
{
|
|
|
|
/** @var EA_Controller $CI */
|
|
|
|
$CI = &get_instance();
|
|
|
|
|
2021-10-28 14:27:14 +03:00
|
|
|
$CI->load->model('settings_model');
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($key)) {
|
2021-10-23 14:21:30 +03:00
|
|
|
throw new InvalidArgumentException('The $key argument cannot be empty.');
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (is_array($key)) {
|
|
|
|
foreach ($key as $name => $value) {
|
|
|
|
$setting = $CI->settings_model
|
|
|
|
->query()
|
|
|
|
->where('name', $name)
|
|
|
|
->get()
|
|
|
|
->row_array();
|
2021-10-28 14:27:14 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($setting)) {
|
2021-10-28 14:27:14 +03:00
|
|
|
$setting = [
|
2023-12-22 13:35:41 +03:00
|
|
|
'name' => $name,
|
2021-10-28 14:27:14 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-10-16 18:06:17 +03:00
|
|
|
$setting['value'] = $value;
|
|
|
|
|
2021-10-28 14:27:14 +03:00
|
|
|
$CI->settings_model->save($setting);
|
2021-10-23 14:21:30 +03:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
return null;
|
2021-10-23 14:21:30 +03:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$setting = $CI->settings_model
|
|
|
|
->query()
|
|
|
|
->where('name', $key)
|
|
|
|
->get()
|
|
|
|
->row_array();
|
2021-10-23 14:21:30 +03:00
|
|
|
|
2021-12-17 11:01:12 +03:00
|
|
|
return $setting['value'] ?? $default;
|
2021-10-23 14:21:30 +03:00
|
|
|
}
|
|
|
|
}
|