2020-04-22 22:48:56 +03:00
|
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2016-07-08 22:23:03 +03:00
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2024-01-01 01:14:38 +03:00
|
|
|
|
* MaketRandevu - MAKET Randevu Portalı
|
2016-07-08 22:23:03 +03:00
|
|
|
|
*
|
|
|
|
|
* @package EasyAppointments
|
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2020-11-14 22:36:25 +03:00
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
|
* @link https://easyappointments.org
|
2021-11-06 17:03:08 +03:00
|
|
|
|
* @since v1.5.0
|
2016-07-08 22:23:03 +03:00
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-03 10:38:59 +03:00
|
|
|
|
* Admins API v1 controller.
|
2016-07-08 22:23:03 +03:00
|
|
|
|
*
|
|
|
|
|
* @package Controllers
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
class Admins_api_v1 extends EA_Controller
|
|
|
|
|
{
|
2016-07-08 22:23:03 +03:00
|
|
|
|
/**
|
2021-11-06 17:03:08 +03:00
|
|
|
|
* Admins_api_v1 constructor.
|
2016-07-08 22:23:03 +03:00
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2016-07-08 22:23:03 +03:00
|
|
|
|
parent::__construct();
|
2021-11-03 10:38:59 +03:00
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
|
$this->load->model('admins_model');
|
2021-11-03 10:38:59 +03:00
|
|
|
|
|
|
|
|
|
$this->load->library('api');
|
|
|
|
|
|
|
|
|
|
$this->api->auth();
|
|
|
|
|
|
|
|
|
|
$this->api->model('admins_model');
|
2016-07-08 22:23:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-06 17:03:08 +03:00
|
|
|
|
* Get an admin collection.
|
2016-07-08 22:23:03 +03:00
|
|
|
|
*/
|
2021-11-06 17:03:08 +03:00
|
|
|
|
public function index()
|
2017-09-15 14:36:37 +03:00
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$keyword = $this->api->request_keyword();
|
|
|
|
|
|
|
|
|
|
$limit = $this->api->request_limit();
|
|
|
|
|
|
|
|
|
|
$offset = $this->api->request_offset();
|
2020-12-05 12:14:13 +03:00
|
|
|
|
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$order_by = $this->api->request_order_by();
|
2017-09-15 14:36:37 +03:00
|
|
|
|
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$fields = $this->api->request_fields();
|
|
|
|
|
|
2021-11-06 17:41:11 +03:00
|
|
|
|
$with = $this->api->request_with();
|
2021-11-06 17:34:54 +03:00
|
|
|
|
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$admins = empty($keyword)
|
2023-11-29 12:24:09 +03:00
|
|
|
|
? $this->admins_model->get(null, $limit, $offset, $order_by)
|
2021-11-03 10:38:59 +03:00
|
|
|
|
: $this->admins_model->search($keyword, $limit, $offset, $order_by);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
foreach ($admins as &$admin) {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$this->admins_model->api_encode($admin);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($fields)) {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$this->admins_model->only($admin, $fields);
|
|
|
|
|
}
|
2021-11-06 17:34:54 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($with)) {
|
2021-11-06 17:41:11 +03:00
|
|
|
|
$this->admins_model->load($admin, $with);
|
2021-11-06 17:34:54 +03:00
|
|
|
|
}
|
2016-07-10 16:53:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_response($admins);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a single admin.
|
|
|
|
|
*
|
|
|
|
|
* @param int|null $id Admin ID.
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
public function show(int $id = null)
|
2021-11-06 17:03:08 +03:00
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$fields = $this->api->request_fields();
|
|
|
|
|
|
2021-11-06 17:41:11 +03:00
|
|
|
|
$with = $this->api->request_with();
|
2021-11-06 17:34:54 +03:00
|
|
|
|
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$admin = $this->admins_model->find($id);
|
|
|
|
|
|
|
|
|
|
$this->admins_model->api_encode($admin);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($fields)) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$this->admins_model->only($admin, $fields);
|
|
|
|
|
}
|
2016-07-10 16:53:22 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($with)) {
|
2021-11-06 17:41:11 +03:00
|
|
|
|
$this->admins_model->load($admin, $with);
|
2021-11-06 17:34:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!$admin) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
response('', 404);
|
2017-09-15 14:36:37 +03:00
|
|
|
|
|
2021-11-03 10:38:59 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_response($admin);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
json_exception($e);
|
2016-07-10 16:53:22 +03:00
|
|
|
|
}
|
2016-07-08 22:23:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-26 06:41:25 +03:00
|
|
|
|
* Store a new admin.
|
2016-07-08 22:23:03 +03:00
|
|
|
|
*/
|
2021-11-06 17:03:08 +03:00
|
|
|
|
public function store()
|
2017-09-15 14:36:37 +03:00
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$admin = request();
|
|
|
|
|
|
|
|
|
|
$this->admins_model->api_decode($admin);
|
2017-09-15 14:36:37 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (array_key_exists('id', $admin)) {
|
2016-07-10 16:53:22 +03:00
|
|
|
|
unset($admin['id']);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!array_key_exists('settings', $admin)) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
throw new InvalidArgumentException('No settings property provided.');
|
2020-12-17 17:49:04 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$admin_id = $this->admins_model->save($admin);
|
|
|
|
|
|
|
|
|
|
$created_admin = $this->admins_model->find($admin_id);
|
|
|
|
|
|
|
|
|
|
$this->admins_model->api_encode($created_admin);
|
2016-07-10 16:53:22 +03:00
|
|
|
|
|
2021-11-03 10:38:59 +03:00
|
|
|
|
json_response($created_admin, 201);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
json_exception($e);
|
2016-07-10 16:53:22 +03:00
|
|
|
|
}
|
2016-07-08 22:23:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-03 10:38:59 +03:00
|
|
|
|
* Update an admin.
|
2016-07-08 22:23:03 +03:00
|
|
|
|
*
|
2021-11-03 10:38:59 +03:00
|
|
|
|
* @param int $id Admin ID.
|
2016-07-08 22:23:03 +03:00
|
|
|
|
*/
|
2021-11-06 17:03:08 +03:00
|
|
|
|
public function update(int $id)
|
2017-09-15 14:36:37 +03:00
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$occurrences = $this->admins_model->get(['id' => $id]);
|
2016-07-08 22:23:03 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (empty($occurrences)) {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
response('', 404);
|
|
|
|
|
|
|
|
|
|
return;
|
2016-07-10 16:53:22 +03:00
|
|
|
|
}
|
2017-09-15 14:36:37 +03:00
|
|
|
|
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$original_admin = $occurrences[0];
|
|
|
|
|
|
|
|
|
|
$admin = request();
|
|
|
|
|
|
|
|
|
|
$this->admins_model->api_decode($admin, $original_admin);
|
|
|
|
|
|
|
|
|
|
$admin_id = $this->admins_model->save($admin);
|
|
|
|
|
|
|
|
|
|
$updated_admin = $this->admins_model->find($admin_id);
|
|
|
|
|
|
|
|
|
|
$this->admins_model->api_encode($updated_admin);
|
|
|
|
|
|
|
|
|
|
json_response($updated_admin);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
json_exception($e);
|
2016-07-10 16:53:22 +03:00
|
|
|
|
}
|
2016-07-08 22:23:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-03 10:38:59 +03:00
|
|
|
|
* Delete an admin.
|
2016-07-08 22:23:03 +03:00
|
|
|
|
*
|
2021-11-03 10:38:59 +03:00
|
|
|
|
* @param int $id Admin ID.
|
2016-07-08 22:23:03 +03:00
|
|
|
|
*/
|
2021-11-06 17:03:08 +03:00
|
|
|
|
public function destroy(int $id)
|
2017-09-15 14:36:37 +03:00
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$occurrences = $this->admins_model->get(['id' => $id]);
|
2016-07-10 16:53:22 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (empty($occurrences)) {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
response('', 404);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-08 22:23:03 +03:00
|
|
|
|
|
2021-11-03 10:38:59 +03:00
|
|
|
|
$this->admins_model->delete($id);
|
2021-11-06 17:34:54 +03:00
|
|
|
|
|
2021-11-06 17:03:08 +03:00
|
|
|
|
response('', 204);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-03 10:38:59 +03:00
|
|
|
|
json_exception($e);
|
2016-07-10 16:53:22 +03:00
|
|
|
|
}
|
2016-07-08 22:23:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|