iflrandevu/application/controllers/Appointments.php

185 lines
4.3 KiB
PHP
Raw Normal View History

<?php defined('BASEPATH') or exit('No direct script access allowed');
2015-10-05 01:32:47 +03:00
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
2020-11-14 22:36:25 +03:00
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
2015-10-05 01:32:47 +03:00
* @since v1.0.0
* ---------------------------------------------------------------------------- */
/**
2021-11-06 18:21:27 +03:00
* Appointments controller.
*
* Handles the appointments related operations.
*
* Notice: This file used to have the booking page related code which since v1.5 has now moved to the Booking.php
* controller for improved consistency.
2015-10-05 01:32:47 +03:00
*
* @package Controllers
*/
class Appointments extends EA_Controller {
/**
2021-11-06 18:21:27 +03:00
* Appointments constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->model('appointments_model');
$this->load->model('roles_model');
$this->load->library('accounts');
$this->load->library('timezones');
}
2015-10-05 01:32:47 +03:00
/**
* Support backwards compatibility for appointment links that still point to this URL.
*
* @param string $appointment_hash
*
* @deprecated Since 1.5
2015-10-05 01:32:47 +03:00
*/
public function index(string $appointment_hash = '')
{
redirect('booking/' . $appointment_hash);
2015-10-05 01:32:47 +03:00
}
/**
* Filter appointments by the provided keyword.
2015-10-05 01:32:47 +03:00
*/
public function search()
{
try
{
if (cannot('view', PRIV_APPOINTMENTS))
{
abort(403, 'Forbidden');
2015-10-05 01:32:47 +03:00
}
$keyword = request('keyword', '');
$order_by = 'name ASC';
2015-10-05 01:32:47 +03:00
$limit = request('limit', 1000);
$offset = 0;
2015-10-05 01:32:47 +03:00
$appointments = $this->appointments_model->search($keyword, $limit, $offset, $order_by);
json_response($appointments);
2017-09-23 02:30:22 +03:00
}
catch (Throwable $e)
{
json_exception($e);
2015-11-23 23:58:32 +02:00
}
}
2015-10-05 01:32:47 +03:00
/**
* Create a appointment.
2015-10-05 01:32:47 +03:00
*/
public function create()
{
try
{
$appointment = json_decode(request('appointment'), TRUE);
if (cannot('add', PRIV_APPOINTMENTS))
{
abort(403, 'Forbidden');
}
$appointment_id = $this->appointments_model->save($appointment);
json_response([
'success' => TRUE,
'id' => $appointment_id
]);
2017-09-23 02:30:22 +03:00
}
catch (Throwable $e)
{
json_exception($e);
2015-10-05 01:32:47 +03:00
}
}
/**
* Update a appointment.
*/
public function update()
{
try
{
$appointment = json_decode(request('appointment'), TRUE);
if (cannot('edit', PRIV_APPOINTMENTS))
{
abort(403, 'Forbidden');
}
$appointment_id = $this->appointments_model->save($appointment);
json_response([
'success' => TRUE,
'id' => $appointment_id
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Remove a appointment.
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_APPOINTMENTS))
{
abort(403, 'Forbidden');
}
$appointment_id = request('appointment_id');
$this->appointments_model->delete($appointment_id);
json_response([
'success' => TRUE,
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
2021-12-14 09:18:46 +03:00
/**
* Find an appointment.
*/
public function find()
{
try
{
if (cannot('view', PRIV_APPOINTMENTS))
2021-12-14 09:18:46 +03:00
{
abort(403, 'Forbidden');
2021-12-14 09:18:46 +03:00
}
$appointment_id = request('appointment_id');
$appointment = $this->appointments_model->find($appointment_id);
json_response($appointment);
}
catch (Throwable $e)
{
json_exception($e);
}
}
2015-10-05 01:32:47 +03:00
}