diff --git a/application/config/constants.php b/application/config/constants.php index 1e30f6d0..29ff6b99 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -72,6 +72,7 @@ const PRIV_USERS = 'users'; 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'; diff --git a/application/controllers/Blocked_periods.php b/application/controllers/Blocked_periods.php new file mode 100644 index 00000000..44092a04 --- /dev/null +++ b/application/controllers/Blocked_periods.php @@ -0,0 +1,235 @@ + + * @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); + } + } +} diff --git a/application/core/EA_Controller.php b/application/core/EA_Controller.php index 59cdf8d7..a7a568a6 100644 --- a/application/core/EA_Controller.php +++ b/application/core/EA_Controller.php @@ -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 diff --git a/application/language/arabic/translations_lang.php b/application/language/arabic/translations_lang.php index 6980da69..85da6d77 100755 --- a/application/language/arabic/translations_lang.php +++ b/application/language/arabic/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/bulgarian/translations_lang.php b/application/language/bulgarian/translations_lang.php index 7504c73b..9af09eb0 100755 --- a/application/language/bulgarian/translations_lang.php +++ b/application/language/bulgarian/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/catalan/translations_lang.php b/application/language/catalan/translations_lang.php index 9ad5a04f..7114a37c 100644 --- a/application/language/catalan/translations_lang.php +++ b/application/language/catalan/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/chinese/translations_lang.php b/application/language/chinese/translations_lang.php index 880459f9..fb23ec6c 100755 --- a/application/language/chinese/translations_lang.php +++ b/application/language/chinese/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/croatian/translations_lang.php b/application/language/croatian/translations_lang.php index baba51bd..831ad323 100644 --- a/application/language/croatian/translations_lang.php +++ b/application/language/croatian/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/czech/translations_lang.php b/application/language/czech/translations_lang.php index e1ec07bb..7a10a28c 100644 --- a/application/language/czech/translations_lang.php +++ b/application/language/czech/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/danish/translations_lang.php b/application/language/danish/translations_lang.php index 079effbb..9d42f08c 100755 --- a/application/language/danish/translations_lang.php +++ b/application/language/danish/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/dutch/translations_lang.php b/application/language/dutch/translations_lang.php index 5b6d094f..890196bf 100755 --- a/application/language/dutch/translations_lang.php +++ b/application/language/dutch/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/english/translations_lang.php b/application/language/english/translations_lang.php index 680f6ecd..c793ad75 100755 --- a/application/language/english/translations_lang.php +++ b/application/language/english/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/estonian/translations_lang.php b/application/language/estonian/translations_lang.php index fae4cd18..5349a188 100644 --- a/application/language/estonian/translations_lang.php +++ b/application/language/estonian/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/finnish/translations_lang.php b/application/language/finnish/translations_lang.php index 6c164a7b..877e14d5 100755 --- a/application/language/finnish/translations_lang.php +++ b/application/language/finnish/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/french/translations_lang.php b/application/language/french/translations_lang.php index 0c3663ac..10863709 100755 --- a/application/language/french/translations_lang.php +++ b/application/language/french/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/german/translations_lang.php b/application/language/german/translations_lang.php index f1c57c36..2e8e8bd0 100755 --- a/application/language/german/translations_lang.php +++ b/application/language/german/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/greek/translations_lang.php b/application/language/greek/translations_lang.php index 21bc1ba5..eba704aa 100755 --- a/application/language/greek/translations_lang.php +++ b/application/language/greek/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/hebrew/translations_lang.php b/application/language/hebrew/translations_lang.php index dc0b90fa..8e676803 100644 --- a/application/language/hebrew/translations_lang.php +++ b/application/language/hebrew/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/hindi/translations_lang.php b/application/language/hindi/translations_lang.php index a6b64866..5ee9a83a 100755 --- a/application/language/hindi/translations_lang.php +++ b/application/language/hindi/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/hungarian/translations_lang.php b/application/language/hungarian/translations_lang.php index c0f5a5ef..a86af978 100755 --- a/application/language/hungarian/translations_lang.php +++ b/application/language/hungarian/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/italian/translations_lang.php b/application/language/italian/translations_lang.php index e47ca121..c681f35f 100755 --- a/application/language/italian/translations_lang.php +++ b/application/language/italian/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/japanese/translations_lang.php b/application/language/japanese/translations_lang.php index c68ef8a1..f58b0ee7 100755 --- a/application/language/japanese/translations_lang.php +++ b/application/language/japanese/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/luxembourgish/translations_lang.php b/application/language/luxembourgish/translations_lang.php index 999bc2ac..348fedca 100755 --- a/application/language/luxembourgish/translations_lang.php +++ b/application/language/luxembourgish/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/marathi/translations_lang.php b/application/language/marathi/translations_lang.php index e5640a72..53da1c04 100644 --- a/application/language/marathi/translations_lang.php +++ b/application/language/marathi/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/persian/translations_lang.php b/application/language/persian/translations_lang.php index ed189cf6..d22a3035 100644 --- a/application/language/persian/translations_lang.php +++ b/application/language/persian/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/polish/translations_lang.php b/application/language/polish/translations_lang.php index cc855ec0..4a358231 100755 --- a/application/language/polish/translations_lang.php +++ b/application/language/polish/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/portuguese-br/translations_lang.php b/application/language/portuguese-br/translations_lang.php index 0a3db192..613a54d6 100755 --- a/application/language/portuguese-br/translations_lang.php +++ b/application/language/portuguese-br/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/portuguese/translations_lang.php b/application/language/portuguese/translations_lang.php index 8383d129..4a62a0dd 100755 --- a/application/language/portuguese/translations_lang.php +++ b/application/language/portuguese/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/romanian/translations_lang.php b/application/language/romanian/translations_lang.php index d0614654..633c77e2 100755 --- a/application/language/romanian/translations_lang.php +++ b/application/language/romanian/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/russian/translations_lang.php b/application/language/russian/translations_lang.php index 0f5ea688..0a48556a 100644 --- a/application/language/russian/translations_lang.php +++ b/application/language/russian/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/serbian/translations_lang.php b/application/language/serbian/translations_lang.php index 78a93f24..26aee298 100644 --- a/application/language/serbian/translations_lang.php +++ b/application/language/serbian/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/slovak/translations_lang.php b/application/language/slovak/translations_lang.php index 546220ad..73202610 100755 --- a/application/language/slovak/translations_lang.php +++ b/application/language/slovak/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/spanish/translations_lang.php b/application/language/spanish/translations_lang.php index 9337da29..bdcd1d0c 100755 --- a/application/language/spanish/translations_lang.php +++ b/application/language/spanish/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/swedish/translations_lang.php b/application/language/swedish/translations_lang.php index 7cca2a17..a5796c3d 100644 --- a/application/language/swedish/translations_lang.php +++ b/application/language/swedish/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/language/turkish/translations_lang.php b/application/language/turkish/translations_lang.php index 6bf0fd6d..73dd8de9 100755 --- a/application/language/turkish/translations_lang.php +++ b/application/language/turkish/translations_lang.php @@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on $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 diff --git a/application/migrations/045_drop_delete_datetime_column_from_all_tables.php b/application/migrations/045_drop_delete_datetime_column_from_all_tables.php index c6b407b5..d3eb39f0 100644 --- a/application/migrations/045_drop_delete_datetime_column_from_all_tables.php +++ b/application/migrations/045_drop_delete_datetime_column_from_all_tables.php @@ -17,7 +17,7 @@ class Migration_Drop_delete_datetime_column_from_all_tables extends EA_Migration */ protected $tables = [ 'appointments', - 'categories', + 'service_categories', 'consents', 'roles', 'services', diff --git a/application/migrations/045_revert_rename_service_categories_table_to_categories.php b/application/migrations/046_revert_rename_service_categories_table_to_categories.php similarity index 100% rename from application/migrations/045_revert_rename_service_categories_table_to_categories.php rename to application/migrations/046_revert_rename_service_categories_table_to_categories.php diff --git a/application/migrations/046_revert_rename_id_service_categories_column_of_services_table.php b/application/migrations/047_revert_rename_id_service_categories_column_of_services_table.php similarity index 100% rename from application/migrations/046_revert_rename_id_service_categories_column_of_services_table.php rename to application/migrations/047_revert_rename_id_service_categories_column_of_services_table.php diff --git a/application/migrations/048_create_blocked_periods_table.php b/application/migrations/048_create_blocked_periods_table.php new file mode 100644 index 00000000..1c62d733 --- /dev/null +++ b/application/migrations/048_create_blocked_periods_table.php @@ -0,0 +1,71 @@ + + * @copyright Copyright (c) Alex Tselegidis + * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link https://easyappointments.org + * @since v1.4.0 + * ---------------------------------------------------------------------------- */ + +class Migration_Create_blocked_periods_table extends EA_Migration { + /** + * Upgrade method. + */ + public function up() + { + if ( ! $this->db->table_exists('blocked_periods')) + { + $this->dbforge->add_field([ + 'id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'auto_increment' => TRUE + ], + 'create_datetime' => [ + 'type' => 'DATETIME', + 'null' => TRUE + ], + 'update_datetime' => [ + 'type' => 'DATETIME', + 'null' => TRUE + ], + 'name' => [ + 'type' => 'VARCHAR', + 'constraint' => '256', + 'null' => TRUE, + ], + 'start_datetime' => [ + 'type' => 'DATETIME', + 'null' => TRUE, + ], + 'end_datetime' => [ + 'type' => 'DATETIME', + 'null' => TRUE, + ], + 'description' => [ + 'type' => 'TEXT', + 'null' => TRUE, + ], + ]); + + $this->dbforge->add_key('id', TRUE); + + $this->dbforge->create_table('blocked_periods', TRUE, ['engine' => 'InnoDB']); + } + } + + /** + * Downgrade method. + */ + public function down() + { + if ($this->db->table_exists('blocked_periods')) + { + $this->dbforge->drop_table('blocked_periods'); + } + } +} diff --git a/application/migrations/049_add_blocked_periods_column_to_roles_table.php b/application/migrations/049_add_blocked_periods_column_to_roles_table.php new file mode 100644 index 00000000..62662df4 --- /dev/null +++ b/application/migrations/049_add_blocked_periods_column_to_roles_table.php @@ -0,0 +1,48 @@ + + * @copyright Copyright (c) Alex Tselegidis + * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link https://easyappointments.org + * @since v1.4.0 + * ---------------------------------------------------------------------------- */ + +class Migration_Add_blocked_periods_column_to_roles_table extends EA_Migration { + /** + * Upgrade method. + */ + public function up() + { + if ( ! $this->db->field_exists('blocked_periods', 'roles')) + { + $fields = [ + 'blocked_periods' => [ + 'type' => 'INT', + 'constraint' => '11', + 'null' => TRUE + ] + ]; + + $this->dbforge->add_column('roles', $fields); + + $this->db->update('roles', ['blocked_periods' => '15'], ['slug' => 'admin']); + + $this->db->update('roles', ['blocked_periods' => '0'], ['slug !=' => 'admin']); + } + } + + /** + * Downgrade method. + */ + public function down() + { + if ($this->db->field_exists('blocked_periods', 'roles')) + { + $this->dbforge->drop_column('roles', 'blocked_periods'); + } + } +} diff --git a/application/models/Blocked_periods_model.php b/application/models/Blocked_periods_model.php new file mode 100644 index 00000000..73089aad --- /dev/null +++ b/application/models/Blocked_periods_model.php @@ -0,0 +1,357 @@ + + * @copyright Copyright (c) Alex Tselegidis + * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link https://easyappointments.org + * @since v1.0.0 + * ---------------------------------------------------------------------------- */ + +/** + * Blocked-Periods model. + * + * Handles all the database operations of the blocked-period resource. + * + * @package Models + */ +class Blocked_periods_model extends EA_Model { + /** + * @var array + */ + protected array $casts = [ + 'id' => 'integer', + ]; + + /** + * @var array + */ + protected array $api_resource = [ + 'id' => 'id', + 'name' => 'name', + 'start' => 'start_datetime', + 'end' => 'end_datetime', + 'description' => 'description', + ]; + + /** + * Save (insert or update) a blocked-period. + * + * @param array $blocked_period Associative array with the blocked-period data. + * + * @return int Returns the blocked-period ID. + * + * @throws InvalidArgumentException + */ + public function save(array $blocked_period): int + { + $this->validate($blocked_period); + + if (empty($blocked_period['id'])) + { + return $this->insert($blocked_period); + } + else + { + return $this->update($blocked_period); + } + } + + /** + * Validate the blocked-period data. + * + * @param array $blocked_period Associative array with the blocked-period data. + * + * @throws InvalidArgumentException + */ + public function validate(array $blocked_period) + { + // If a blocked-period ID is provided then check whether the record really exists in the database. + if ( ! empty($blocked_period['id'])) + { + $count = $this->db->get_where('blocked_periods', ['id' => $blocked_period['id']])->num_rows(); + + if ( ! $count) + { + throw new InvalidArgumentException('The provided blocked-period ID does not exist in the database: ' . $blocked_period['id']); + } + } + + // Make sure all required fields are provided. + if ( + empty($blocked_period['name']) + ) + { + throw new InvalidArgumentException('Not all required fields are provided: ' . print_r($blocked_period, TRUE)); + } + } + + /** + * Insert a new blocked-period into the database. + * + * @param array $blocked_period Associative array with the blocked-period data. + * + * @return int Returns the blocked-period ID. + * + * @throws RuntimeException + */ + protected function insert(array $blocked_period): int + { + $blocked_period['create_datetime'] = date('Y-m-d H:i:s'); + $blocked_period['update_datetime'] = date('Y-m-d H:i:s'); + + if ( ! $this->db->insert('blocked_periods', $blocked_period)) + { + throw new RuntimeException('Could not insert blocked-period.'); + } + + return $this->db->insert_id(); + } + + /** + * Update an existing blocked-period. + * + * @param array $blocked_period Associative array with the blocked-period data. + * + * @return int Returns the blocked-period ID. + * + * @throws RuntimeException + */ + protected function update(array $blocked_period): int + { + $blocked_period['update_datetime'] = date('Y-m-d H:i:s'); + + if ( ! $this->db->update('blocked_periods', $blocked_period, ['id' => $blocked_period['id']])) + { + throw new RuntimeException('Could not update blocked periods.'); + } + + return $blocked_period['id']; + } + + /** + * Remove an existing blocked-period from the database. + * + * @param int $blocked_period_id Blocked period ID. + * + * @throws RuntimeException + */ + public function delete(int $blocked_period_id): void + { + $this->db->delete('blocked_periods', ['id' => $blocked_period_id]); + } + + /** + * Get a specific blocked-period from the database. + * + * @param int $blocked_period_id The ID of the record to be returned. + * + * @return array Returns an array with the blocked-period data. + * + * @throws InvalidArgumentException + */ + public function find(int $blocked_period_id): array + { + $blocked_period = $this->db->get_where('blocked_periods', ['id' => $blocked_period_id])->row_array(); + + if ( ! $blocked_period) + { + throw new InvalidArgumentException('The provided blocked-period ID was not found in the database: ' . $blocked_period_id); + } + + $this->cast($blocked_period); + + return $blocked_period; + } + + /** + * Get a specific field value from the database. + * + * @param int $blocked_period_id Blocked period ID. + * @param string $field Name of the value to be returned. + * + * @return mixed Returns the selected blocked-period value from the database. + * + * @throws InvalidArgumentException + */ + public function value(int $blocked_period_id, string $field): mixed + { + if (empty($field)) + { + throw new InvalidArgumentException('The field argument is cannot be empty.'); + } + + if (empty($blocked_period_id)) + { + throw new InvalidArgumentException('The blocked-period ID argument cannot be empty.'); + } + + // Check whether the service exists. + $query = $this->db->get_where('blocked_periods', ['id' => $blocked_period_id]); + + if ( ! $query->num_rows()) + { + throw new InvalidArgumentException('The provided blocked-period ID was not found in the database: ' . $blocked_period_id); + } + + // Check if the required field is part of the blocked-period data. + $blocked_period = $query->row_array(); + + $this->cast($blocked_period); + + if ( ! array_key_exists($field, $blocked_period)) + { + throw new InvalidArgumentException('The requested field was not found in the blocked-period data: ' . $field); + } + + return $blocked_period[$field]; + } + + /** + * Get all services that match the provided criteria. + * + * @param array|string|null $where Where conditions + * @param int|null $limit Record limit. + * @param int|null $offset Record offset. + * @param string|null $order_by Order by. + * + * @return array Returns an array of blocked periods. + */ + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array + { + if ($where !== NULL) + { + $this->db->where($where); + } + + if ($order_by !== NULL) + { + $this->db->order_by($order_by); + } + + $blocked_periods = $this->db->get('blocked_periods', $limit, $offset)->result_array(); + + foreach ($blocked_periods as &$blocked_period) + { + $this->cast($blocked_period); + } + + return $blocked_periods; + } + + /** + * Get the query builder interface, configured for use with the blocked periods table. + * + * @return CI_DB_query_builder + */ + public function query(): CI_DB_query_builder + { + return $this->db->from('blocked_periods'); + } + + /** + * Search blocked periods by the provided keyword. + * + * @param string $keyword Search keyword. + * @param int|null $limit Record limit. + * @param int|null $offset Record offset. + * @param string|null $order_by Order by. + * + * @return array Returns an array of blocked periods. + */ + public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array + { + $blocked_periods = $this + ->db + ->select() + ->from('blocked_periods') + ->group_start() + ->like('name', $keyword) + ->or_like('description', $keyword) + ->group_end() + ->limit($limit) + ->offset($offset) + ->order_by($order_by) + ->get() + ->result_array(); + + foreach ($blocked_periods as &$blocked_period) + { + $this->cast($blocked_period); + } + + return $blocked_periods; + } + + /** + * Load related resources to a blocked-period. + * + * @param array $blocked_period Associative array with the blocked-period data. + * @param array $resources Resource names to be attached. + * + * @throws InvalidArgumentException + */ + public function load(array &$blocked_period, array $resources) + { + // Blocked periods do not currently have any related resources. + } + + /** + * Convert the database blocked-period record to the equivalent API resource. + * + * @param array $blocked_period Blocked period data. + */ + public function api_encode(array &$blocked_period) + { + $encoded_resource = [ + 'id' => array_key_exists('id', $blocked_period) ? (int)$blocked_period['id'] : NULL, + 'name' => $blocked_period['name'], + 'start' => array_key_exists('start_datetime', $blocked_period) ? $blocked_period['start_datetime'] : NULL, + 'end' => array_key_exists('end_datetime', $blocked_period) ? $blocked_period['end_datetime'] : NULL, + 'description' => array_key_exists('description', $blocked_period) ? $blocked_period['description'] : NULL + ]; + + $blocked_period = $encoded_resource; + } + + /** + * Convert the API resource to the equivalent database blocked-period record. + * + * @param array $blocked_period API resource. + * @param array|null $base Base blocked-period data to be overwritten with the provided values (useful for updates). + */ + public function api_decode(array &$blocked_period, array $base = NULL) + { + $decoded_resource = $base ?: []; + + if (array_key_exists('id', $blocked_period)) + { + $decoded_resource['id'] = $blocked_period['id']; + } + + if (array_key_exists('name', $blocked_period)) + { + $decoded_resource['name'] = $blocked_period['name']; + } + + if (array_key_exists('start', $blocked_period)) + { + $decoded_resource['start_datetime'] = $blocked_period['start']; + } + + if (array_key_exists('end', $blocked_period)) + { + $decoded_resource['end_datetime'] = $blocked_period['end']; + } + + if (array_key_exists('description', $blocked_period)) + { + $decoded_resource['description'] = $blocked_period['description']; + } + + $blocked_period = $decoded_resource; + } +} diff --git a/application/views/pages/blocked_periods.php b/application/views/pages/blocked_periods.php new file mode 100644 index 00000000..83162c96 --- /dev/null +++ b/application/views/pages/blocked_periods.php @@ -0,0 +1,110 @@ + + + + +