2021-11-06 17:03:08 +03:00
|
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2023-12-31 21:46:27 +03:00
|
|
|
|
* IFLRandevu - İzmir Fen Lisesi Randevu Portalı
|
2021-11-06 17:03:08 +03:00
|
|
|
|
*
|
|
|
|
|
* @package EasyAppointments
|
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2021-11-06 17:03:08 +03:00
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
|
* @since v1.5.0
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Settings API v1 controller.
|
|
|
|
|
*
|
|
|
|
|
* @package Controllers
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
class Settings_api_v1 extends EA_Controller
|
|
|
|
|
{
|
2021-11-06 17:03:08 +03:00
|
|
|
|
/**
|
|
|
|
|
* Settings_api_v1 constructor.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
|
|
$this->load->library('api');
|
|
|
|
|
|
|
|
|
|
$this->api->auth();
|
|
|
|
|
|
|
|
|
|
$this->api->model('settings_model');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a setting collection.
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$keyword = $this->api->request_keyword();
|
|
|
|
|
|
|
|
|
|
$limit = $this->api->request_limit();
|
|
|
|
|
|
|
|
|
|
$offset = $this->api->request_offset();
|
|
|
|
|
|
|
|
|
|
$order_by = $this->api->request_order_by();
|
|
|
|
|
|
|
|
|
|
$fields = $this->api->request_fields();
|
|
|
|
|
|
|
|
|
|
$settings = empty($keyword)
|
2023-11-29 12:24:09 +03:00
|
|
|
|
? $this->settings_model->get(null, $limit, $offset, $order_by)
|
2021-11-06 17:03:08 +03:00
|
|
|
|
: $this->settings_model->search($keyword, $limit, $offset, $order_by);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
foreach ($settings as &$setting) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$this->settings_model->api_encode($setting);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($fields)) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$this->settings_model->only($setting, $fields);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
json_response($settings);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a setting value by name.
|
|
|
|
|
*
|
|
|
|
|
* @param string $name Setting name.
|
|
|
|
|
*/
|
|
|
|
|
public function show(string $name)
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$value = setting($name);
|
|
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
|
'name' => $name,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'value' => $value,
|
2021-11-06 17:03:08 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a setting value by name.
|
|
|
|
|
*
|
|
|
|
|
* @param string $name Setting name.
|
|
|
|
|
*/
|
|
|
|
|
public function update(string $name)
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$value = request('value');
|
|
|
|
|
|
|
|
|
|
setting([$name => $value]);
|
|
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
|
'name' => $name,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'value' => $value,
|
2021-11-06 17:03:08 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|