Skip to content

Commit

Permalink
Add blocked period CRUD operations to the app (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed Nov 3, 2023
1 parent 38f872d commit fbcd35f
Show file tree
Hide file tree
Showing 44 changed files with 1,454 additions and 1 deletion.
1 change: 1 addition & 0 deletions application/config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
const PRIV_SYSTEM_SETTINGS = 'system_settings';
const PRIV_USER_SETTINGS = 'user_settings';
const PRIV_WEBHOOKS = 'webhooks';
const PRIV_BLOCKED_PERIODS = 'blocked_periods';

const DATE_FORMAT_DMY = 'DMY';
const DATE_FORMAT_MDY = 'MDY';
Expand Down
235 changes: 235 additions & 0 deletions application/controllers/Blocked_periods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');

/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <[email protected]>
* @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
*/
class Blocked_periods extends EA_Controller {
/**
* 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');

if (cannot('view', PRIV_BLOCKED_PERIODS))
{
if ($user_id)
{
abort(403, 'Forbidden');
}

redirect('login');

return;
}

$role_slug = session('role_slug');

script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
]);

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(),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
]);

$this->load->view('pages/blocked_periods');
}

/**
* Filter blocked-periods by the provided keyword.
*/
public function search()
{
try
{
if (cannot('view', PRIV_BLOCKED_PERIODS))
{
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);
}
catch (Throwable $e)
{
json_exception($e);
}
}

/**
* Store a new service-category.
*/
public function store()
{
try
{
if (cannot('add', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}

$service_category = request('service_category');

$this->blocked_periods_model->only($service_category, [
'name',
'description'
]);

$service_category_id = $this->blocked_periods_model->save($service_category);

$service_category = $this->blocked_periods_model->find($service_category_id);

$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);

json_response([
'success' => TRUE,
'id' => $service_category_id
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}

/**
* Update a service-category.
*/
public function update()
{
try
{
if (cannot('edit', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}

$service_category = request('service_category');

$this->blocked_periods_model->only($service_category, [
'id',
'name',
'description'
]);

$service_category_id = $this->blocked_periods_model->save($service_category);

$service_category = $this->blocked_periods_model->find($service_category_id);

$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);

json_response([
'success' => TRUE,
'id' => $service_category_id
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}

/**
* Remove a service-category.
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}

$service_category_id = request('service_category_id');

$service_category = $this->blocked_periods_model->find($service_category_id);

$this->blocked_periods_model->delete($service_category_id);

$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_DELETE, $service_category);

json_response([
'success' => TRUE,
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}

/**
* Find a service-category.
*/
public function find()
{
try
{
if (cannot('view', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}

$service_category_id = request('service_category_id');

$service_category = $this->blocked_periods_model->find($service_category_id);

json_response($service_category);
}
catch (Throwable $e)
{
json_exception($e);
}
}
}
1 change: 1 addition & 0 deletions application/core/EA_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
* @property Unavailabilities_model $unavailabilities_model
* @property Users_model $users_model
* @property Webhooks_model $webhooks_model
* @property Blocked_periods_model $blocked_periods_model
*
* @property Accounts $accounts
* @property Api $api
Expand Down
5 changes: 5 additions & 0 deletions application/language/arabic/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/bulgarian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/catalan/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/chinese/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/croatian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/czech/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/danish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/dutch/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/english/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/estonian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/finnish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/french/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/german/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
5 changes: 5 additions & 0 deletions application/language/greek/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End
Loading

0 comments on commit fbcd35f

Please sign in to comment.