2023-11-03 20:25:23 +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ı
|
2023-11-03 20:25:23 +03:00
|
|
|
|
*
|
|
|
|
|
* @package EasyAppointments
|
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
|
* @since v1.0.0
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Blocked_periods controller.
|
|
|
|
|
*
|
|
|
|
|
* Handles the blocked-periods related operations.
|
|
|
|
|
*
|
|
|
|
|
* @package Controllers
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
class Blocked_periods extends EA_Controller
|
|
|
|
|
{
|
2023-11-03 20:25:23 +03:00
|
|
|
|
/**
|
|
|
|
|
* Blocked_periods constructor.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
|
|
$this->load->model('blocked_periods_model');
|
|
|
|
|
$this->load->model('roles_model');
|
|
|
|
|
|
|
|
|
|
$this->load->library('accounts');
|
|
|
|
|
$this->load->library('timezones');
|
|
|
|
|
$this->load->library('webhooks_client');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Render the backend blocked-periods page.
|
|
|
|
|
*
|
|
|
|
|
* On this page admin users will be able to manage blocked-periods, which are eventually selected by customers during the
|
|
|
|
|
* booking process.
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
session(['dest_url' => site_url('blocked_periods')]);
|
|
|
|
|
|
|
|
|
|
$user_id = session('user_id');
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (cannot('view', PRIV_BLOCKED_PERIODS)) {
|
|
|
|
|
if ($user_id) {
|
2023-11-03 20:25:23 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redirect('login');
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$role_slug = session('role_slug');
|
|
|
|
|
|
|
|
|
|
script_vars([
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
'role_slug' => $role_slug,
|
2023-11-17 10:04:27 +03:00
|
|
|
|
'date_format' => setting('date_format'),
|
|
|
|
|
'time_format' => setting('time_format'),
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'first_weekday' => setting('first_weekday'),
|
2023-11-03 20:25:23 +03:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
html_vars([
|
|
|
|
|
'page_title' => lang('blocked_periods'),
|
|
|
|
|
'active_menu' => PRIV_BLOCKED_PERIODS,
|
|
|
|
|
'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),
|
2023-11-03 20:25:23 +03:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->load->view('pages/blocked_periods');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Filter blocked-periods by the provided keyword.
|
|
|
|
|
*/
|
|
|
|
|
public function search()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
|
|
|
|
if (cannot('view', PRIV_BLOCKED_PERIODS)) {
|
2023-11-03 20:25:23 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$keyword = request('keyword', '');
|
|
|
|
|
|
|
|
|
|
$order_by = 'update_datetime DESC';
|
|
|
|
|
|
|
|
|
|
$limit = request('limit', 1000);
|
|
|
|
|
|
|
|
|
|
$offset = 0;
|
|
|
|
|
|
|
|
|
|
$blocked_periods = $this->blocked_periods_model->search($keyword, $limit, $offset, $order_by);
|
|
|
|
|
|
|
|
|
|
json_response($blocked_periods);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2023-11-03 20:25:23 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a new service-category.
|
|
|
|
|
*/
|
|
|
|
|
public function store()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
|
|
|
|
if (cannot('add', PRIV_BLOCKED_PERIODS)) {
|
2023-11-03 20:25:23 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$blocked_period = request('blocked_period');
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$this->blocked_periods_model->only($blocked_period, ['name', 'start_datetime', 'end_datetime', 'notes']);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$blocked_period_id = $this->blocked_periods_model->save($blocked_period);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_BLOCKED_PERIOD_SAVE, $blocked_period);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
|
|
|
|
json_response([
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'success' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'id' => $blocked_period_id,
|
2023-11-03 20:25:23 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
json_exception($e);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
}
|
2023-11-29 12:24:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Find a service-category.
|
|
|
|
|
*/
|
|
|
|
|
public function find()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if (cannot('view', PRIV_BLOCKED_PERIODS)) {
|
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$blocked_period_id = request('blocked_period_id');
|
|
|
|
|
|
|
|
|
|
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
|
|
|
|
|
|
|
|
|
|
json_response($blocked_period);
|
|
|
|
|
} catch (Throwable $e) {
|
2023-11-03 20:25:23 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update a service-category.
|
|
|
|
|
*/
|
|
|
|
|
public function update()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
|
|
|
|
if (cannot('edit', PRIV_BLOCKED_PERIODS)) {
|
2023-11-03 20:25:23 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$blocked_period = request('blocked_period');
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$this->blocked_periods_model->only($blocked_period, [
|
2023-11-03 20:25:23 +03:00
|
|
|
|
'id',
|
|
|
|
|
'name',
|
2023-11-17 10:04:27 +03:00
|
|
|
|
'start_datetime',
|
|
|
|
|
'end_datetime',
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'notes',
|
2023-11-03 20:25:23 +03:00
|
|
|
|
]);
|
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$blocked_period_id = $this->blocked_periods_model->save($blocked_period);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_BLOCKED_PERIOD_SAVE, $blocked_period);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
|
|
|
|
json_response([
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'success' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'id' => $blocked_period_id,
|
2023-11-03 20:25:23 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2023-11-03 20:25:23 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove a service-category.
|
|
|
|
|
*/
|
|
|
|
|
public function destroy()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
|
|
|
|
if (cannot('delete', PRIV_BLOCKED_PERIODS)) {
|
2023-11-03 20:25:23 +03:00
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$blocked_period_id = request('blocked_period_id');
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$this->blocked_periods_model->delete($blocked_period_id);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
2023-11-17 10:04:27 +03:00
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_BLOCKED_PERIOD_DELETE, $blocked_period);
|
2023-11-03 20:25:23 +03:00
|
|
|
|
|
|
|
|
|
json_response([
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'success' => true,
|
2023-11-03 20:25:23 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2023-11-03 20:25:23 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|