2021-11-18 07:23:54 +03:00
|
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2024-01-01 01:14:38 +03:00
|
|
|
|
* MaketRandevu - MAKET Randevu Portalı
|
2021-11-18 07:23:54 +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-18 07:23:54 +03:00
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
|
* @since v1.0.0
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-26 05:54:13 +03:00
|
|
|
|
* Service-categories controller.
|
2021-11-18 07:23:54 +03:00
|
|
|
|
*
|
2023-10-26 05:54:13 +03:00
|
|
|
|
* Handles the service-categories related operations.
|
2021-11-18 07:23:54 +03:00
|
|
|
|
*
|
|
|
|
|
* @package Controllers
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
class Service_categories extends EA_Controller
|
|
|
|
|
{
|
2021-11-18 07:23:54 +03:00
|
|
|
|
/**
|
2023-10-26 05:54:13 +03:00
|
|
|
|
* Service-categories constructor.
|
2021-11-18 07:23:54 +03:00
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$this->load->model('service_categories_model');
|
2021-11-18 07:23:54 +03:00
|
|
|
|
$this->load->model('roles_model');
|
|
|
|
|
|
|
|
|
|
$this->load->library('accounts');
|
|
|
|
|
$this->load->library('timezones');
|
2022-06-19 20:05:45 +03:00
|
|
|
|
$this->load->library('webhooks_client');
|
2021-11-18 07:23:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-26 05:54:13 +03:00
|
|
|
|
* Render the backend service-categories page.
|
2021-11-18 07:23:54 +03:00
|
|
|
|
*
|
2023-10-26 05:54:13 +03:00
|
|
|
|
* On this page admin users will be able to manage service-categories, which are eventually selected by customers during the
|
2021-11-18 07:23:54 +03:00
|
|
|
|
* booking process.
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2023-10-26 07:09:05 +03:00
|
|
|
|
session(['dest_url' => site_url('service_categories')]);
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
2022-01-17 20:24:02 +03:00
|
|
|
|
$user_id = session('user_id');
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (cannot('view', PRIV_SERVICES)) {
|
|
|
|
|
if ($user_id) {
|
2022-01-17 20:24:02 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
|
}
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
2022-01-17 20:24:02 +03:00
|
|
|
|
redirect('login');
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
|
|
|
|
$role_slug = session('role_slug');
|
|
|
|
|
|
2022-01-10 11:26:28 +03:00
|
|
|
|
script_vars([
|
|
|
|
|
'user_id' => $user_id,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'role_slug' => $role_slug,
|
2022-01-10 11:26:28 +03:00
|
|
|
|
]);
|
|
|
|
|
|
2021-12-18 19:22:40 +03:00
|
|
|
|
html_vars([
|
2023-10-26 06:09:46 +03:00
|
|
|
|
'page_title' => lang('service_categories'),
|
2021-11-18 07:23:54 +03:00
|
|
|
|
'active_menu' => PRIV_SERVICES,
|
|
|
|
|
'user_display_name' => $this->accounts->get_user_display_name($user_id),
|
|
|
|
|
'timezones' => $this->timezones->to_array(),
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
|
2021-11-18 07:23:54 +03:00
|
|
|
|
]);
|
2021-12-18 19:22:40 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$this->load->view('pages/service_categories');
|
2021-11-18 07:23:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-26 05:54:13 +03:00
|
|
|
|
* Filter service-categories by the provided keyword.
|
2021-11-18 07:23:54 +03:00
|
|
|
|
*/
|
|
|
|
|
public function search()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
|
|
|
|
if (cannot('view', PRIV_SERVICES)) {
|
2021-12-18 19:22:40 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 07:23:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$keyword = request('keyword', '');
|
|
|
|
|
|
2022-10-16 18:07:01 +03:00
|
|
|
|
$order_by = 'update_datetime DESC';
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
|
|
|
|
$limit = request('limit', 1000);
|
2021-12-18 19:22:40 +03:00
|
|
|
|
|
|
|
|
|
$offset = 0;
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$service_categories = $this->service_categories_model->search($keyword, $limit, $offset, $order_by);
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
json_response($service_categories);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-18 07:23:54 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-26 06:41:25 +03:00
|
|
|
|
* Store a new service-category.
|
2021-11-18 07:23:54 +03:00
|
|
|
|
*/
|
2023-10-26 06:41:25 +03:00
|
|
|
|
public function store()
|
2021-11-18 07:23:54 +03:00
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
|
|
|
|
if (cannot('add', PRIV_SERVICES)) {
|
2021-12-18 19:22:40 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 07:23:54 +03:00
|
|
|
|
}
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$service_category = request('service_category');
|
2022-03-25 14:29:17 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$this->service_categories_model->only($service_category, ['name', 'description']);
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$service_category_id = $this->service_categories_model->save($service_category);
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$service_category = $this->service_categories_model->find($service_category_id);
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
2023-10-26 06:12:10 +03:00
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
2021-11-18 07:23:54 +03:00
|
|
|
|
json_response([
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'success' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'id' => $service_category_id,
|
2021-11-18 07:23:54 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
json_exception($e);
|
2021-11-18 07:23:54 +03:00
|
|
|
|
}
|
2023-11-29 12:24:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Find a service-category.
|
|
|
|
|
*/
|
|
|
|
|
public function find()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if (cannot('view', PRIV_SERVICES)) {
|
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$service_category_id = request('service_category_id');
|
|
|
|
|
|
|
|
|
|
$service_category = $this->service_categories_model->find($service_category_id);
|
|
|
|
|
|
|
|
|
|
json_response($service_category);
|
|
|
|
|
} catch (Throwable $e) {
|
2021-11-18 07:23:54 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-26 05:54:13 +03:00
|
|
|
|
* Update a service-category.
|
2021-11-18 07:23:54 +03:00
|
|
|
|
*/
|
|
|
|
|
public function update()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
|
|
|
|
if (cannot('edit', PRIV_SERVICES)) {
|
2021-12-18 19:22:40 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 07:23:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$service_category = request('service_category');
|
2022-03-25 14:29:17 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$this->service_categories_model->only($service_category, ['id', 'name', 'description']);
|
2022-03-25 14:29:17 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$service_category_id = $this->service_categories_model->save($service_category);
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$service_category = $this->service_categories_model->find($service_category_id);
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
2023-10-26 06:12:10 +03:00
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
2021-11-18 07:23:54 +03:00
|
|
|
|
json_response([
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'success' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'id' => $service_category_id,
|
2021-11-18 07:23:54 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-18 07:23:54 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-26 05:54:13 +03:00
|
|
|
|
* Remove a service-category.
|
2021-11-18 07:23:54 +03:00
|
|
|
|
*/
|
|
|
|
|
public function destroy()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
|
|
|
|
if (cannot('delete', PRIV_SERVICES)) {
|
2021-12-18 19:22:40 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 07:23:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$service_category_id = request('service_category_id');
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$service_category = $this->service_categories_model->find($service_category_id);
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
2023-10-26 05:54:13 +03:00
|
|
|
|
$this->service_categories_model->delete($service_category_id);
|
2021-11-18 07:23:54 +03:00
|
|
|
|
|
2023-10-26 06:12:10 +03:00
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_DELETE, $service_category);
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
2021-11-18 07:23:54 +03:00
|
|
|
|
json_response([
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'success' => true,
|
2021-11-18 07:23:54 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-12-14 09:18:46 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-18 07:23:54 +03:00
|
|
|
|
}
|