From 4a7cdd96b298945883df73fa064d5910bb7ba18a Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sat, 23 Oct 2021 13:21:30 +0200 Subject: [PATCH] Added helper file with setting related functions. --- application/helpers/setting_helper.php | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 application/helpers/setting_helper.php diff --git a/application/helpers/setting_helper.php b/application/helpers/setting_helper.php new file mode 100644 index 00000000..88f74d2a --- /dev/null +++ b/application/helpers/setting_helper.php @@ -0,0 +1,60 @@ + + * @copyright Copyright (c) 2013 - 2020, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.1.0 + * ---------------------------------------------------------------------------- */ + +if ( ! function_exists('setting')) +{ + /** + * 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']); + * + * @param array|string $key + * @param mixed $default + * + * @return mixed|NULL Returns the requested value or NULL if you assign a new setting value. + * + * @throws InvalidArgumentException + */ + function setting($key = NULL, $default = NULL) + { + /** @var EA_Controller $CI */ + $CI = &get_instance(); + + if (empty($key)) + { + throw new InvalidArgumentException('The $key argument cannot be empty.'); + } + + if (is_array($key)) + { + foreach ($key as $item => $value) + { + $CI->session->set_userdata($item, $value); + } + + return NULL; + } + + $value = $CI->session->userdata($key); + + return $value ?? $default; + } +}