mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-29 03:12:39 +03:00
Refactor PHP controllers and models (use of protected members and corrections in docblock comments).
This commit is contained in:
parent
e3eede1745
commit
8461c0dca4
13 changed files with 305 additions and 246 deletions
|
@ -277,6 +277,7 @@ class Appointments extends CI_Controller {
|
||||||
* @param numeric $_POST['service_duration'] The selected service duration in minutes.
|
* @param numeric $_POST['service_duration'] The selected service duration in minutes.
|
||||||
* @param string $_POST['manage_mode'] Contains either 'true' or 'false' and determines the if current user
|
* @param string $_POST['manage_mode'] Contains either 'true' or 'false' and determines the if current user
|
||||||
* is managing an already booked appointment or not.
|
* is managing an already booked appointment or not.
|
||||||
|
*
|
||||||
* @return Returns a json object with the available hours.
|
* @return Returns a json object with the available hours.
|
||||||
*/
|
*/
|
||||||
public function ajax_get_available_hours() {
|
public function ajax_get_available_hours() {
|
||||||
|
@ -300,17 +301,17 @@ class Appointments extends CI_Controller {
|
||||||
// If the user has selected the "any-provider" option then we will need to search
|
// If the user has selected the "any-provider" option then we will need to search
|
||||||
// for an available provider that will provide the requested service.
|
// for an available provider that will provide the requested service.
|
||||||
if ($_POST['provider_id'] === ANY_PROVIDER) {
|
if ($_POST['provider_id'] === ANY_PROVIDER) {
|
||||||
$_POST['provider_id'] = $this->search_any_provider($_POST['service_id'], $_POST['selected_date']);
|
$_POST['provider_id'] = $this->_search_any_provider($_POST['service_id'], $_POST['selected_date']);
|
||||||
if ($_POST['provider_id'] === NULL) {
|
if ($_POST['provider_id'] === NULL) {
|
||||||
echo json_encode(array());
|
echo json_encode(array());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$empty_periods = $this->get_provider_available_time_periods($_POST['provider_id'],
|
$empty_periods = $this->_get_provider_available_time_periods($_POST['provider_id'],
|
||||||
$_POST['selected_date'], $exclude_appointments);
|
$_POST['selected_date'], $exclude_appointments);
|
||||||
|
|
||||||
$available_hours = $this->calculate_available_hours($empty_periods, $_POST['selected_date'],
|
$available_hours = $this->_calculate_available_hours($empty_periods, $_POST['selected_date'],
|
||||||
$_POST['service_duration'], filter_var($_POST['manage_mode'], FILTER_VALIDATE_BOOLEAN));
|
$_POST['service_duration'], filter_var($_POST['manage_mode'], FILTER_VALIDATE_BOOLEAN));
|
||||||
|
|
||||||
echo json_encode($available_hours);
|
echo json_encode($available_hours);
|
||||||
|
@ -349,7 +350,7 @@ class Appointments extends CI_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check appointment availability.
|
// Check appointment availability.
|
||||||
if (!$this->check_datetime_availability()) {
|
if (!$this->_check_datetime_availability()) {
|
||||||
throw new Exception($this->lang->line('requested_hour_is_unavailable'));
|
throw new Exception($this->lang->line('requested_hour_is_unavailable'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,6 +463,67 @@ class Appointments extends CI_Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [AJAX] Get Unavailable Dates
|
||||||
|
*
|
||||||
|
* Get an array with the available dates of a specific provider, service and month
|
||||||
|
* of the year. Provide the "provider_id", "service_id" and "selected_date" as GET
|
||||||
|
* parameters to the request. The "selected_date" parameter must have the Y-m-d format.
|
||||||
|
*
|
||||||
|
* @return string Returns a JSON array with the dates that are unavailable.
|
||||||
|
*/
|
||||||
|
public function ajax_get_unavailable_dates() {
|
||||||
|
try {
|
||||||
|
$provider_id = $this->input->get('provider_id');
|
||||||
|
$service_id = $this->input->get('service_id');
|
||||||
|
$selected_date = new DateTime($this->input->get('selected_date'));
|
||||||
|
$number_of_days = (int)$selected_date->format('t');
|
||||||
|
$unavailable_dates = array();
|
||||||
|
|
||||||
|
// Handle the "Any Provider" case.
|
||||||
|
if ($provider_id === ANY_PROVIDER) {
|
||||||
|
$provider_id = $this->_search_any_provider($service_id, $this->input->get('selected_date'));
|
||||||
|
if ($provider_id === NULL) { // No provider is available in the selected date.
|
||||||
|
for ($i=1; $i<=$number_of_days; $i++) {
|
||||||
|
$current_date = new DateTime($selected_date->format('Y-m') . '-' . $i);
|
||||||
|
$unavailable_dates[] = $current_date->format('Y-m-d');
|
||||||
|
}
|
||||||
|
echo json_encode($unavailable_dates);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the available time periods for every day of this month.
|
||||||
|
$this->load->model('services_model');
|
||||||
|
$service_duration = (int)$this->services_model->get_value('duration', $service_id);
|
||||||
|
|
||||||
|
for ($i=1; $i<=$number_of_days; $i++) {
|
||||||
|
$current_date = new DateTime($selected_date->format('Y-m') . '-' . $i);
|
||||||
|
|
||||||
|
if ($current_date < new DateTime()) { // Past dates become immediatelly unavailable.
|
||||||
|
$unavailable_dates[] = $current_date->format('Y-m-d');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$empty_periods = $this->_get_provider_available_time_periods($provider_id,
|
||||||
|
$current_date->format('Y-m-d'));
|
||||||
|
|
||||||
|
$available_hours = $this->_calculate_available_hours($empty_periods, $current_date->format('Y-m-d'),
|
||||||
|
$service_duration);
|
||||||
|
|
||||||
|
if (empty($available_hours)) {
|
||||||
|
$unavailable_dates[] = $current_date->format('Y-m-d');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($unavailable_dates);
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
echo json_encode(array(
|
||||||
|
'exceptions' => array(exceptionToJavaScript($exc))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the provider is still available in the selected appointment date.
|
* Check whether the provider is still available in the selected appointment date.
|
||||||
*
|
*
|
||||||
|
@ -473,7 +535,7 @@ class Appointments extends CI_Controller {
|
||||||
*
|
*
|
||||||
* @return bool Returns whether the selected datetime is still available.
|
* @return bool Returns whether the selected datetime is still available.
|
||||||
*/
|
*/
|
||||||
private function check_datetime_availability() {
|
protected function _check_datetime_availability() {
|
||||||
$this->load->model('services_model');
|
$this->load->model('services_model');
|
||||||
|
|
||||||
$appointment = $_POST['post_data']['appointment'];
|
$appointment = $_POST['post_data']['appointment'];
|
||||||
|
@ -483,13 +545,13 @@ class Appointments extends CI_Controller {
|
||||||
$exclude_appointments = (isset($appointment['id'])) ? array($appointment['id']) : array();
|
$exclude_appointments = (isset($appointment['id'])) ? array($appointment['id']) : array();
|
||||||
|
|
||||||
if ($appointment['id_users_provider'] === ANY_PROVIDER) {
|
if ($appointment['id_users_provider'] === ANY_PROVIDER) {
|
||||||
$appointment['id_users_provider'] = $this->search_any_provider($appointment['id_services'],
|
$appointment['id_users_provider'] = $this->_search_any_provider($appointment['id_services'],
|
||||||
date('Y-m-d', strtotime($appointment['start_datetime'])));
|
date('Y-m-d', strtotime($appointment['start_datetime'])));
|
||||||
$_POST['post_data']['appointment']['id_users_provider'] = $appointment['id_users_provider'];
|
$_POST['post_data']['appointment']['id_users_provider'] = $appointment['id_users_provider'];
|
||||||
return TRUE; // The selected provider is always available.
|
return TRUE; // The selected provider is always available.
|
||||||
}
|
}
|
||||||
|
|
||||||
$available_periods = $this->get_provider_available_time_periods(
|
$available_periods = $this->_get_provider_available_time_periods(
|
||||||
$appointment['id_users_provider'], date('Y-m-d', strtotime($appointment['start_datetime'])),
|
$appointment['id_users_provider'], date('Y-m-d', strtotime($appointment['start_datetime'])),
|
||||||
$exclude_appointments);
|
$exclude_appointments);
|
||||||
|
|
||||||
|
@ -530,7 +592,7 @@ class Appointments extends CI_Controller {
|
||||||
*
|
*
|
||||||
* @return array Returns an array with the available time periods of the provider.
|
* @return array Returns an array with the available time periods of the provider.
|
||||||
*/
|
*/
|
||||||
private function get_provider_available_time_periods($provider_id, $selected_date,
|
protected function _get_provider_available_time_periods($provider_id, $selected_date,
|
||||||
$exclude_appointments = array()) {
|
$exclude_appointments = array()) {
|
||||||
$this->load->model('appointments_model');
|
$this->load->model('appointments_model');
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
|
@ -674,7 +736,7 @@ class Appointments extends CI_Controller {
|
||||||
*
|
*
|
||||||
* @return int Returns the ID of the provider that can provide the service at the selected date.
|
* @return int Returns the ID of the provider that can provide the service at the selected date.
|
||||||
*/
|
*/
|
||||||
private function search_any_provider($service_id, $selected_date) {
|
protected function _search_any_provider($service_id, $selected_date) {
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
$this->load->model('services_model');
|
$this->load->model('services_model');
|
||||||
$available_providers = $this->providers_model->get_available_providers();
|
$available_providers = $this->providers_model->get_available_providers();
|
||||||
|
@ -685,8 +747,8 @@ class Appointments extends CI_Controller {
|
||||||
foreach($available_providers as $provider) {
|
foreach($available_providers as $provider) {
|
||||||
foreach($provider['services'] as $provider_service_id) {
|
foreach($provider['services'] as $provider_service_id) {
|
||||||
if ($provider_service_id == $service_id) { // Check if the provider is available for the requested date.
|
if ($provider_service_id == $service_id) { // Check if the provider is available for the requested date.
|
||||||
$empty_periods = $this->get_provider_available_time_periods($provider['id'], $selected_date);
|
$empty_periods = $this->_get_provider_available_time_periods($provider['id'], $selected_date);
|
||||||
$available_hours = $this->calculate_available_hours($empty_periods, $selected_date, $service['duration']);
|
$available_hours = $this->_calculate_available_hours($empty_periods, $selected_date, $service['duration']);
|
||||||
if (count($available_hours) > $max_hours_count) {
|
if (count($available_hours) > $max_hours_count) {
|
||||||
$provider_id = $provider['id'];
|
$provider_id = $provider['id'];
|
||||||
$max_hours_count = count($available_hours);
|
$max_hours_count = count($available_hours);
|
||||||
|
@ -706,14 +768,14 @@ class Appointments extends CI_Controller {
|
||||||
* available hour is added to the "$available_hours" array.
|
* available hour is added to the "$available_hours" array.
|
||||||
*
|
*
|
||||||
* @param array $empty_periods Contains the empty periods as generated by the
|
* @param array $empty_periods Contains the empty periods as generated by the
|
||||||
* "get_provider_available_time_periods" method.
|
* "_get_provider_available_time_periods" method.
|
||||||
* @param string $selected_date The selected date to be search (format )
|
* @param string $selected_date The selected date to be search (format )
|
||||||
* @param numeric $service_duration The service duration is required for the hour calculation.
|
* @param numeric $service_duration The service duration is required for the hour calculation.
|
||||||
* @param bool $manage_mode (optional) Whether we are currently on manage mode (editing an existing appointment).
|
* @param bool $manage_mode (optional) Whether we are currently on manage mode (editing an existing appointment).
|
||||||
*
|
*
|
||||||
* @return array Returns an array with the available hours for the appointment.
|
* @return array Returns an array with the available hours for the appointment.
|
||||||
*/
|
*/
|
||||||
private function calculate_available_hours(array $empty_periods, $selected_date, $service_duration,
|
protected function _calculate_available_hours(array $empty_periods, $selected_date, $service_duration,
|
||||||
$manage_mode = FALSE) {
|
$manage_mode = FALSE) {
|
||||||
$this->load->model('settings_model');
|
$this->load->model('settings_model');
|
||||||
|
|
||||||
|
@ -770,67 +832,6 @@ class Appointments extends CI_Controller {
|
||||||
|
|
||||||
return $available_hours;
|
return $available_hours;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* [AJAX] Get Unavailable Dates
|
|
||||||
*
|
|
||||||
* Get an array with the available dates of a specific provider, service and month
|
|
||||||
* of the year. Provide the "provider_id", "service_id" and "selected_date" as GET
|
|
||||||
* parameters to the request. The "selected_date" parameter must have the Y-m-d format.
|
|
||||||
*
|
|
||||||
* @return string Returns a JSON array with the dates that are unavailable.
|
|
||||||
*/
|
|
||||||
public function ajax_get_unavailable_dates() {
|
|
||||||
try {
|
|
||||||
$provider_id = $this->input->get('provider_id');
|
|
||||||
$service_id = $this->input->get('service_id');
|
|
||||||
$selected_date = new DateTime($this->input->get('selected_date'));
|
|
||||||
$number_of_days = (int)$selected_date->format('t');
|
|
||||||
$unavailable_dates = array();
|
|
||||||
|
|
||||||
// Handle the "Any Provider" case.
|
|
||||||
if ($provider_id === ANY_PROVIDER) {
|
|
||||||
$provider_id = $this->search_any_provider($service_id, $this->input->get('selected_date'));
|
|
||||||
if ($provider_id === NULL) { // No provider is available in the selected date.
|
|
||||||
for ($i=1; $i<=$number_of_days; $i++) {
|
|
||||||
$current_date = new DateTime($selected_date->format('Y-m') . '-' . $i);
|
|
||||||
$unavailable_dates[] = $current_date->format('Y-m-d');
|
|
||||||
}
|
|
||||||
echo json_encode($unavailable_dates);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the available time periods for every day of this month.
|
|
||||||
$this->load->model('services_model');
|
|
||||||
$service_duration = (int)$this->services_model->get_value('duration', $service_id);
|
|
||||||
|
|
||||||
for ($i=1; $i<=$number_of_days; $i++) {
|
|
||||||
$current_date = new DateTime($selected_date->format('Y-m') . '-' . $i);
|
|
||||||
|
|
||||||
if ($current_date < new DateTime()) { // Past dates become immediatelly unavailable.
|
|
||||||
$unavailable_dates[] = $current_date->format('Y-m-d');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$empty_periods = $this->get_provider_available_time_periods($provider_id,
|
|
||||||
$current_date->format('Y-m-d'));
|
|
||||||
|
|
||||||
$available_hours = $this->calculate_available_hours($empty_periods, $current_date->format('Y-m-d'),
|
|
||||||
$service_duration);
|
|
||||||
|
|
||||||
if (empty($available_hours)) {
|
|
||||||
$unavailable_dates[] = $current_date->format('Y-m-d');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode($unavailable_dates);
|
|
||||||
} catch(Exception $exc) {
|
|
||||||
echo json_encode(array(
|
|
||||||
'exceptions' => array(exceptionToJavaScript($exc))
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of file appointments.php */
|
/* End of file appointments.php */
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
* @package Controllers
|
* @package Controllers
|
||||||
*/
|
*/
|
||||||
class Backend extends CI_Controller {
|
class Backend extends CI_Controller {
|
||||||
|
/**
|
||||||
|
* Class Constructor
|
||||||
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->library('session');
|
$this->load->library('session');
|
||||||
|
@ -43,7 +46,7 @@ class Backend extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function index($appointment_hash = '') {
|
public function index($appointment_hash = '') {
|
||||||
$this->session->set_userdata('dest_url', site_url('backend'));
|
$this->session->set_userdata('dest_url', site_url('backend'));
|
||||||
if (!$this->has_privileges(PRIV_APPOINTMENTS)) return;
|
if (!$this->_has_privileges(PRIV_APPOINTMENTS)) return;
|
||||||
|
|
||||||
$this->load->model('appointments_model');
|
$this->load->model('appointments_model');
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
|
@ -93,7 +96,7 @@ class Backend extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function customers() {
|
public function customers() {
|
||||||
$this->session->set_userdata('dest_url', site_url('backend/customers'));
|
$this->session->set_userdata('dest_url', site_url('backend/customers'));
|
||||||
if (!$this->has_privileges(PRIV_CUSTOMERS)) return;
|
if (!$this->_has_privileges(PRIV_CUSTOMERS)) return;
|
||||||
|
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
$this->load->model('customers_model');
|
$this->load->model('customers_model');
|
||||||
|
@ -127,7 +130,7 @@ class Backend extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function services() {
|
public function services() {
|
||||||
$this->session->set_userdata('dest_url', site_url('backend/services'));
|
$this->session->set_userdata('dest_url', site_url('backend/services'));
|
||||||
if (!$this->has_privileges(PRIV_SERVICES)) return;
|
if (!$this->_has_privileges(PRIV_SERVICES)) return;
|
||||||
|
|
||||||
$this->load->model('customers_model');
|
$this->load->model('customers_model');
|
||||||
$this->load->model('services_model');
|
$this->load->model('services_model');
|
||||||
|
@ -157,7 +160,7 @@ class Backend extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function users() {
|
public function users() {
|
||||||
$this->session->set_userdata('dest_url', site_url('backend/users'));
|
$this->session->set_userdata('dest_url', site_url('backend/users'));
|
||||||
if (!$this->has_privileges(PRIV_USERS)) return;
|
if (!$this->_has_privileges(PRIV_USERS)) return;
|
||||||
|
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
$this->load->model('secretaries_model');
|
$this->load->model('secretaries_model');
|
||||||
|
@ -192,8 +195,8 @@ class Backend extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function settings() {
|
public function settings() {
|
||||||
$this->session->set_userdata('dest_url', site_url('backend/settings'));
|
$this->session->set_userdata('dest_url', site_url('backend/settings'));
|
||||||
if (!$this->has_privileges(PRIV_SYSTEM_SETTINGS, FALSE)
|
if (!$this->_has_privileges(PRIV_SYSTEM_SETTINGS, FALSE)
|
||||||
&& !$this->has_privileges(PRIV_USER_SETTINGS)) return;
|
&& !$this->_has_privileges(PRIV_USER_SETTINGS)) return;
|
||||||
|
|
||||||
$this->load->model('settings_model');
|
$this->load->model('settings_model');
|
||||||
$this->load->model('user_model');
|
$this->load->model('user_model');
|
||||||
|
@ -236,7 +239,7 @@ class Backend extends CI_Controller {
|
||||||
* not. If the user is not logged in then he will be prompted to log in. If he hasn't the
|
* not. If the user is not logged in then he will be prompted to log in. If he hasn't the
|
||||||
* required privileges then an info message will be displayed.
|
* required privileges then an info message will be displayed.
|
||||||
*/
|
*/
|
||||||
private function has_privileges($page, $redirect = TRUE) {
|
protected function _has_privileges($page, $redirect = TRUE) {
|
||||||
// Check if user is logged in.
|
// Check if user is logged in.
|
||||||
$user_id = $this->session->userdata('user_id');
|
$user_id = $this->session->userdata('user_id');
|
||||||
if ($user_id == FALSE) { // User not logged in, display the login view.
|
if ($user_id == FALSE) { // User not logged in, display the login view.
|
||||||
|
@ -270,7 +273,7 @@ class Backend extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function update() {
|
public function update() {
|
||||||
try {
|
try {
|
||||||
if (!$this->has_privileges(PRIV_SYSTEM_SETTINGS, TRUE))
|
if (!$this->_has_privileges(PRIV_SYSTEM_SETTINGS, TRUE))
|
||||||
throw new Exception('You do not have the required privileges for this task!');
|
throw new Exception('You do not have the required privileges for this task!');
|
||||||
|
|
||||||
$this->load->library('migration');
|
$this->load->library('migration');
|
||||||
|
@ -292,7 +295,7 @@ class Backend extends CI_Controller {
|
||||||
*
|
*
|
||||||
* @param array $view Contains the view data.
|
* @param array $view Contains the view data.
|
||||||
*/
|
*/
|
||||||
private function set_user_data(&$view) {
|
protected function set_user_data(&$view) {
|
||||||
$this->load->model('roles_model');
|
$this->load->model('roles_model');
|
||||||
|
|
||||||
// Get privileges
|
// Get privileges
|
||||||
|
|
|
@ -19,8 +19,14 @@
|
||||||
* @package Controllers
|
* @package Controllers
|
||||||
*/
|
*/
|
||||||
class Backend_api extends CI_Controller {
|
class Backend_api extends CI_Controller {
|
||||||
private $privileges;
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $privileges;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor
|
||||||
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
@ -442,8 +448,7 @@ class Backend_api extends CI_Controller {
|
||||||
/**
|
/**
|
||||||
* [AJAX] Insert of update unavailable time period to database.
|
* [AJAX] Insert of update unavailable time period to database.
|
||||||
*
|
*
|
||||||
* @param array $_POST['unavailable'] JSON encoded array that contains the unavailable
|
* @param array $_POST['unavailable'] JSON encoded array that contains the unavailable period data.
|
||||||
* period data.
|
|
||||||
*/
|
*/
|
||||||
public function ajax_save_unavailable() {
|
public function ajax_save_unavailable() {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -77,7 +77,7 @@ class User extends CI_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the forgot password page.
|
* Display the "forgot password" page.
|
||||||
*/
|
*/
|
||||||
public function forgot_password() {
|
public function forgot_password() {
|
||||||
$this->load->model('settings_model');
|
$this->load->model('settings_model');
|
||||||
|
@ -86,6 +86,9 @@ class User extends CI_Controller {
|
||||||
$this->load->view('user/forgot_password', $view);
|
$this->load->view('user/forgot_password', $view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the "not authorized" page.
|
||||||
|
*/
|
||||||
public function no_privileges() {
|
public function no_privileges() {
|
||||||
$this->load->model('settings_model');
|
$this->load->model('settings_model');
|
||||||
$view['base_url'] = $this->config->item('base_url');
|
$view['base_url'] = $this->config->item('base_url');
|
||||||
|
|
|
@ -25,9 +25,26 @@ require_once __DIR__ . '/external/google-api-php-client/contrib/Google_CalendarS
|
||||||
* @package Libraries
|
* @package Libraries
|
||||||
*/
|
*/
|
||||||
class Google_Sync {
|
class Google_Sync {
|
||||||
private $CI;
|
/**
|
||||||
private $client;
|
* CodeIgniter Instance
|
||||||
private $service;
|
*
|
||||||
|
* @var CodeIgniter
|
||||||
|
*/
|
||||||
|
protected $CI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Google API Client
|
||||||
|
*
|
||||||
|
* @var Google_Client
|
||||||
|
*/
|
||||||
|
protected $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Google Calendar Service
|
||||||
|
*
|
||||||
|
* @var Google_CalendarService
|
||||||
|
*/
|
||||||
|
protected $service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Constructor
|
* Class Constructor
|
||||||
|
@ -114,6 +131,7 @@ class Google_Sync {
|
||||||
* @parma array $company_settings Contains some company settings that are used
|
* @parma array $company_settings Contains some company settings that are used
|
||||||
* by this method. By the time the following values must be in the array:
|
* by this method. By the time the following values must be in the array:
|
||||||
* 'company_name'.
|
* 'company_name'.
|
||||||
|
*
|
||||||
* @return Google_Event Returns the Google_Event class object.
|
* @return Google_Event Returns the Google_Event class object.
|
||||||
*/
|
*/
|
||||||
public function add_appointment($appointment, $provider, $service, $customer, $company_settings) {
|
public function add_appointment($appointment, $provider, $service, $customer, $company_settings) {
|
||||||
|
@ -166,6 +184,7 @@ class Google_Sync {
|
||||||
* @parma array $company_settings Contains some company settings that are used
|
* @parma array $company_settings Contains some company settings that are used
|
||||||
* by this method. By the time the following values must be in the array:
|
* by this method. By the time the following values must be in the array:
|
||||||
* 'company_name'.
|
* 'company_name'.
|
||||||
|
*
|
||||||
* @return Google_Event Returns the Google_Event class object.
|
* @return Google_Event Returns the Google_Event class object.
|
||||||
*/
|
*/
|
||||||
public function update_appointment($appointment, $provider, $service, $customer, $company_settings) {
|
public function update_appointment($appointment, $provider, $service, $customer, $company_settings) {
|
||||||
|
@ -222,6 +241,7 @@ class Google_Sync {
|
||||||
*
|
*
|
||||||
* @param array $provider Contains the provider record data.
|
* @param array $provider Contains the provider record data.
|
||||||
* @param array $unavailable Contains unavailable period's data.
|
* @param array $unavailable Contains unavailable period's data.
|
||||||
|
*
|
||||||
* @return Google_Event Returns the google event's object.
|
* @return Google_Event Returns the google event's object.
|
||||||
*/
|
*/
|
||||||
public function add_unavailable($provider, $unavailable) {
|
public function add_unavailable($provider, $unavailable) {
|
||||||
|
@ -251,6 +271,7 @@ class Google_Sync {
|
||||||
*
|
*
|
||||||
* @param array $provider Contains the provider record data.
|
* @param array $provider Contains the provider record data.
|
||||||
* @param array $unavailable Contains the unavailable period data.
|
* @param array $unavailable Contains the unavailable period data.
|
||||||
|
*
|
||||||
* @return Google_Event Returns the Google_Event object.
|
* @return Google_Event Returns the Google_Event object.
|
||||||
*/
|
*/
|
||||||
public function update_unavailable($provider, $unavailable) {
|
public function update_unavailable($provider, $unavailable) {
|
||||||
|
@ -287,7 +308,8 @@ class Google_Sync {
|
||||||
* Get an event object from gcal
|
* Get an event object from gcal
|
||||||
*
|
*
|
||||||
* @param array $provider Contains the provider record data.
|
* @param array $provider Contains the provider record data.
|
||||||
* @param string $google_event_id Id of the google calendar event
|
* @param string $google_event_id Id of the google calendar event.
|
||||||
|
*
|
||||||
* @return Google_Event Returns the google event object.
|
* @return Google_Event Returns the google event object.
|
||||||
*/
|
*/
|
||||||
public function get_event($provider, $google_event_id) {
|
public function get_event($provider, $google_event_id) {
|
||||||
|
@ -300,6 +322,7 @@ class Google_Sync {
|
||||||
* @param string $google_calendar The name of the google calendar to be used.
|
* @param string $google_calendar The name of the google calendar to be used.
|
||||||
* @param date $start The start date of sync period.
|
* @param date $start The start date of sync period.
|
||||||
* @param date $end The end date of sync period.
|
* @param date $end The end date of sync period.
|
||||||
|
*
|
||||||
* @return object Returns an array with Google_Event objects that belong on the given
|
* @return object Returns an array with Google_Event objects that belong on the given
|
||||||
* sync period (start, end).
|
* sync period (start, end).
|
||||||
*/
|
*/
|
||||||
|
@ -321,6 +344,7 @@ class Google_Sync {
|
||||||
* Google Calendar account.
|
* Google Calendar account.
|
||||||
*
|
*
|
||||||
* @param string $google_token The user's token will be used to grant access to google calendar.
|
* @param string $google_token The user's token will be used to grant access to google calendar.
|
||||||
|
*
|
||||||
* @return array Returns an array with the available calendars.
|
* @return array Returns an array with the available calendars.
|
||||||
*/
|
*/
|
||||||
public function get_google_calendars() {
|
public function get_google_calendars() {
|
||||||
|
|
|
@ -21,7 +21,12 @@
|
||||||
* @package Libraries
|
* @package Libraries
|
||||||
*/
|
*/
|
||||||
class Notifications {
|
class Notifications {
|
||||||
private $ci;
|
/**
|
||||||
|
* CodeIgniter Instance
|
||||||
|
*
|
||||||
|
* @var CodeIgniter
|
||||||
|
*/
|
||||||
|
protected $ci;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Constructor
|
* Class Constructor
|
||||||
|
@ -40,10 +45,11 @@ class Notifications {
|
||||||
* @param array $replace_array Array that contains the variables
|
* @param array $replace_array Array that contains the variables
|
||||||
* to be replaced.
|
* to be replaced.
|
||||||
* @param string $email_html The email template hmtl.
|
* @param string $email_html The email template hmtl.
|
||||||
|
*
|
||||||
* @return string Returns the new email html that contain the
|
* @return string Returns the new email html that contain the
|
||||||
* variables of the $replace_array.
|
* variables of the $replace_array.
|
||||||
*/
|
*/
|
||||||
private function replace_template_variables($replace_array, $email_html) {
|
protected function _replace_template_variables($replace_array, $email_html) {
|
||||||
foreach($replace_array as $var=>$value) {
|
foreach($replace_array as $var=>$value) {
|
||||||
$email_html = str_replace($var, $value, $email_html);
|
$email_html = str_replace($var, $value, $email_html);
|
||||||
}
|
}
|
||||||
|
@ -69,6 +75,7 @@ class Notifications {
|
||||||
* @param string $appointment_link This link is going to enable the receiver to make changes
|
* @param string $appointment_link This link is going to enable the receiver to make changes
|
||||||
* to the appointment record.
|
* to the appointment record.
|
||||||
* @param string $receiver_address The receiver email address.
|
* @param string $receiver_address The receiver email address.
|
||||||
|
*
|
||||||
* @return bool Returns the operation result.
|
* @return bool Returns the operation result.
|
||||||
*/
|
*/
|
||||||
public function send_appointment_details($appointment_data, $provider_data, $service_data,
|
public function send_appointment_details($appointment_data, $provider_data, $service_data,
|
||||||
|
@ -110,7 +117,7 @@ class Notifications {
|
||||||
|
|
||||||
$email_html = file_get_contents(dirname(dirname(__FILE__))
|
$email_html = file_get_contents(dirname(dirname(__FILE__))
|
||||||
. '/views/emails/appointment_details.php');
|
. '/views/emails/appointment_details.php');
|
||||||
$email_html = $this->replace_template_variables($replace_array, $email_html);
|
$email_html = $this->_replace_template_variables($replace_array, $email_html);
|
||||||
|
|
||||||
// :: INSTANTIATE EMAIL OBJECT AND SEND EMAIL
|
// :: INSTANTIATE EMAIL OBJECT AND SEND EMAIL
|
||||||
$mail = new PHPMailer();
|
$mail = new PHPMailer();
|
||||||
|
@ -183,7 +190,7 @@ class Notifications {
|
||||||
|
|
||||||
$email_html = file_get_contents(dirname(dirname(__FILE__))
|
$email_html = file_get_contents(dirname(dirname(__FILE__))
|
||||||
. '/views/emails/delete_appointment.php');
|
. '/views/emails/delete_appointment.php');
|
||||||
$email_html = $this->replace_template_variables($replace_array, $email_html);
|
$email_html = $this->_replace_template_variables($replace_array, $email_html);
|
||||||
|
|
||||||
// :: SETUP EMAIL OBJECT AND SEND NOTIFICATION
|
// :: SETUP EMAIL OBJECT AND SEND NOTIFICATION
|
||||||
$mail = new PHPMailer();
|
$mail = new PHPMailer();
|
||||||
|
@ -221,7 +228,7 @@ class Notifications {
|
||||||
|
|
||||||
$email_html = file_get_contents(dirname(dirname(__FILE__))
|
$email_html = file_get_contents(dirname(dirname(__FILE__))
|
||||||
. '/views/emails/new_password.php');
|
. '/views/emails/new_password.php');
|
||||||
$email_html = $this->replace_template_variables($replace_array, $email_html);
|
$email_html = $this->_replace_template_variables($replace_array, $email_html);
|
||||||
|
|
||||||
// :: SETUP EMAIL OBJECT AND SEND NOTIFICATION
|
// :: SETUP EMAIL OBJECT AND SEND NOTIFICATION
|
||||||
$mail = new PHPMailer();
|
$mail = new PHPMailer();
|
||||||
|
|
|
@ -41,9 +41,9 @@ class Appointments_Model extends CI_Model {
|
||||||
|
|
||||||
// Perform insert() or update() operation.
|
// Perform insert() or update() operation.
|
||||||
if (!isset($appointment['id'])) {
|
if (!isset($appointment['id'])) {
|
||||||
$appointment['id'] = $this->insert($appointment);
|
$appointment['id'] = $this->_insert($appointment);
|
||||||
} else {
|
} else {
|
||||||
$this->update($appointment);
|
$this->_update($appointment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $appointment['id'];
|
return $appointment['id'];
|
||||||
|
@ -89,7 +89,7 @@ class Appointments_Model extends CI_Model {
|
||||||
* data. Each key has the same name with the database fields.
|
* data. Each key has the same name with the database fields.
|
||||||
* @return int Returns the id of the new record.
|
* @return int Returns the id of the new record.
|
||||||
*/
|
*/
|
||||||
private function insert($appointment) {
|
protected function _insert($appointment) {
|
||||||
$appointment['book_datetime'] = date('Y-m-d H:i:s');
|
$appointment['book_datetime'] = date('Y-m-d H:i:s');
|
||||||
$appointment['hash'] = $this->generate_hash();
|
$appointment['hash'] = $this->generate_hash();
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ class Appointments_Model extends CI_Model {
|
||||||
* @param array $appointment Associative array with the appointment's
|
* @param array $appointment Associative array with the appointment's
|
||||||
* data. Each key has the same name with the database fields.
|
* data. Each key has the same name with the database fields.
|
||||||
*/
|
*/
|
||||||
private function update($appointment) {
|
protected function _update($appointment) {
|
||||||
$this->db->where('id', $appointment['id']);
|
$this->db->where('id', $appointment['id']);
|
||||||
if (!$this->db->update('ea_appointments', $appointment)) {
|
if (!$this->db->update('ea_appointments', $appointment)) {
|
||||||
throw new Exception('Could not update appointment record.');
|
throw new Exception('Could not update appointment record.');
|
||||||
|
|
|
@ -47,9 +47,9 @@ class Customers_Model extends CI_Model {
|
||||||
|
|
||||||
// :: INSERT OR UPDATE CUSTOMER RECORD
|
// :: INSERT OR UPDATE CUSTOMER RECORD
|
||||||
if (!isset($customer['id'])) {
|
if (!isset($customer['id'])) {
|
||||||
$customer['id'] = $this->insert($customer);
|
$customer['id'] = $this->_insert($customer);
|
||||||
} else {
|
} else {
|
||||||
$this->update($customer);
|
$this->_update($customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $customer['id'];
|
return $customer['id'];
|
||||||
|
@ -90,7 +90,7 @@ class Customers_Model extends CI_Model {
|
||||||
* data. Each key has the same name with the database fields.
|
* data. Each key has the same name with the database fields.
|
||||||
* @return int Returns the id of the new record.
|
* @return int Returns the id of the new record.
|
||||||
*/
|
*/
|
||||||
private function insert($customer) {
|
protected function _insert($customer) {
|
||||||
// Before inserting the customer we need to get the customer's role id
|
// Before inserting the customer we need to get the customer's role id
|
||||||
// from the database and assign it to the new record as a foreign key.
|
// from the database and assign it to the new record as a foreign key.
|
||||||
$customer_role_id = $this->db
|
$customer_role_id = $this->db
|
||||||
|
@ -118,7 +118,7 @@ class Customers_Model extends CI_Model {
|
||||||
* data. Each key has the same name with the database fields.
|
* data. Each key has the same name with the database fields.
|
||||||
* @return int Returns the updated record id.
|
* @return int Returns the updated record id.
|
||||||
*/
|
*/
|
||||||
private function update($customer) {
|
protected function _update($customer) {
|
||||||
// Do not update empty string values.
|
// Do not update empty string values.
|
||||||
foreach ($customer as $key => $value) {
|
foreach ($customer as $key => $value) {
|
||||||
if ($value === '')
|
if ($value === '')
|
||||||
|
|
|
@ -69,9 +69,9 @@ class Providers_Model extends CI_Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($provider['id'])) {
|
if (!isset($provider['id'])) {
|
||||||
$provider['id'] = $this->insert($provider);
|
$provider['id'] = $this->_insert($provider);
|
||||||
} else {
|
} else {
|
||||||
$provider['id'] = $this->update($provider);
|
$provider['id'] = $this->_update($provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
return intval($provider['id']);
|
return intval($provider['id']);
|
||||||
|
@ -109,7 +109,7 @@ class Providers_Model extends CI_Model {
|
||||||
* @return int Returns the new record id.
|
* @return int Returns the new record id.
|
||||||
* @throws Exception When the insert operation fails.
|
* @throws Exception When the insert operation fails.
|
||||||
*/
|
*/
|
||||||
public function insert($provider) {
|
protected function _insert($provider) {
|
||||||
$this->load->helper('general');
|
$this->load->helper('general');
|
||||||
|
|
||||||
// Get provider role id.
|
// Get provider role id.
|
||||||
|
@ -144,7 +144,7 @@ class Providers_Model extends CI_Model {
|
||||||
* @return int Returns the record id.
|
* @return int Returns the record id.
|
||||||
* @throws Exception When the update operation fails.
|
* @throws Exception When the update operation fails.
|
||||||
*/
|
*/
|
||||||
public function update($provider) {
|
protected function _update($provider) {
|
||||||
$this->load->helper('general');
|
$this->load->helper('general');
|
||||||
|
|
||||||
// Store service and settings (must not be present on the $provider array).
|
// Store service and settings (must not be present on the $provider array).
|
||||||
|
@ -507,7 +507,7 @@ class Providers_Model extends CI_Model {
|
||||||
* @param array $settings Contains the setting values.
|
* @param array $settings Contains the setting values.
|
||||||
* @param numeric $provider_id Record id of the provider.
|
* @param numeric $provider_id Record id of the provider.
|
||||||
*/
|
*/
|
||||||
private function save_settings($settings, $provider_id) {
|
protected function save_settings($settings, $provider_id) {
|
||||||
if (!is_numeric($provider_id)) {
|
if (!is_numeric($provider_id)) {
|
||||||
throw new Exception('Invalid $provider_id argument given :' . $provider_id);
|
throw new Exception('Invalid $provider_id argument given :' . $provider_id);
|
||||||
}
|
}
|
||||||
|
@ -535,7 +535,7 @@ class Providers_Model extends CI_Model {
|
||||||
* @throws Exception When the $services argument type is not array.
|
* @throws Exception When the $services argument type is not array.
|
||||||
* @throws Exception When the $provider_id argumetn type is not numeric.
|
* @throws Exception When the $provider_id argumetn type is not numeric.
|
||||||
*/
|
*/
|
||||||
private function save_services($services, $provider_id) {
|
protected function save_services($services, $provider_id) {
|
||||||
// Validate method arguments.
|
// Validate method arguments.
|
||||||
if (!is_array($services)) {
|
if (!is_array($services)) {
|
||||||
throw new Exception('Invalid argument type $services: ' . $services);
|
throw new Exception('Invalid argument type $services: ' . $services);
|
||||||
|
|
|
@ -56,9 +56,9 @@ class Secretaries_Model extends CI_Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($secretary['id'])) {
|
if (!isset($secretary['id'])) {
|
||||||
$secretary['id'] = $this->insert($secretary);
|
$secretary['id'] = $this->_insert($secretary);
|
||||||
} else {
|
} else {
|
||||||
$secretary['id'] = $this->update($secretary);
|
$secretary['id'] = $this->_update($secretary);
|
||||||
}
|
}
|
||||||
|
|
||||||
return intval($secretary['id']);
|
return intval($secretary['id']);
|
||||||
|
@ -96,7 +96,7 @@ class Secretaries_Model extends CI_Model {
|
||||||
* @return int Returns the new record id.
|
* @return int Returns the new record id.
|
||||||
* @throws Exception When the insert operation fails.
|
* @throws Exception When the insert operation fails.
|
||||||
*/
|
*/
|
||||||
public function insert($secretary) {
|
protected function _insert($secretary) {
|
||||||
$this->load->helper('general');
|
$this->load->helper('general');
|
||||||
|
|
||||||
$providers = $secretary['providers'];
|
$providers = $secretary['providers'];
|
||||||
|
@ -127,7 +127,7 @@ class Secretaries_Model extends CI_Model {
|
||||||
* @return int Retuns the record id.
|
* @return int Retuns the record id.
|
||||||
* @throws Exception When the update operation fails.
|
* @throws Exception When the update operation fails.
|
||||||
*/
|
*/
|
||||||
public function update($secretary) {
|
protected function _update($secretary) {
|
||||||
$this->load->helper('general');
|
$this->load->helper('general');
|
||||||
|
|
||||||
$providers = $secretary['providers'];
|
$providers = $secretary['providers'];
|
||||||
|
@ -392,7 +392,7 @@ class Secretaries_Model extends CI_Model {
|
||||||
* @param array $providers Contains the provider ids that are handled by the secretary.
|
* @param array $providers Contains the provider ids that are handled by the secretary.
|
||||||
* @param numeric $secretary_id The selected secretary record.
|
* @param numeric $secretary_id The selected secretary record.
|
||||||
*/
|
*/
|
||||||
private function save_providers($providers, $secretary_id) {
|
protected function save_providers($providers, $secretary_id) {
|
||||||
if (!is_array($providers)) {
|
if (!is_array($providers)) {
|
||||||
throw new Exception('Invalid argument given $providers: ' . print_r($providers, TRUE));
|
throw new Exception('Invalid argument given $providers: ' . print_r($providers, TRUE));
|
||||||
}
|
}
|
||||||
|
@ -416,7 +416,7 @@ class Secretaries_Model extends CI_Model {
|
||||||
* @param array $settings Contains the setting values.
|
* @param array $settings Contains the setting values.
|
||||||
* @param numeric $secretary_id Record id of the secretary.
|
* @param numeric $secretary_id Record id of the secretary.
|
||||||
*/
|
*/
|
||||||
private function save_settings($settings, $secretary_id) {
|
protected function save_settings($settings, $secretary_id) {
|
||||||
if (!is_numeric($secretary_id)) {
|
if (!is_numeric($secretary_id)) {
|
||||||
throw new Exception('Invalid $provider_id argument given :' . $secretary_id);
|
throw new Exception('Invalid $provider_id argument given :' . $secretary_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,15 +29,16 @@ class Services_Model extends CI_Model {
|
||||||
*
|
*
|
||||||
* @param array $service Contains the service data. If an 'id' value is provided then
|
* @param array $service Contains the service data. If an 'id' value is provided then
|
||||||
* the record will be updated.
|
* the record will be updated.
|
||||||
|
*
|
||||||
* @return numeric Returns the record id.
|
* @return numeric Returns the record id.
|
||||||
*/
|
*/
|
||||||
public function add($service) {
|
public function add($service) {
|
||||||
$this->validate($service);
|
$this->validate($service);
|
||||||
|
|
||||||
if (!isset($service['id'])) {
|
if (!isset($service['id'])) {
|
||||||
$service['id'] = $this->insert($service);
|
$service['id'] = $this->_insert($service);
|
||||||
} else {
|
} else {
|
||||||
$this->update($service);
|
$this->_update($service);
|
||||||
}
|
}
|
||||||
|
|
||||||
return intval($service['id']);
|
return intval($service['id']);
|
||||||
|
@ -47,9 +48,10 @@ class Services_Model extends CI_Model {
|
||||||
* Insert service record into database.
|
* Insert service record into database.
|
||||||
*
|
*
|
||||||
* @param array $service Contains the service record data.
|
* @param array $service Contains the service record data.
|
||||||
|
*
|
||||||
* @return int Returns the new service record id.
|
* @return int Returns the new service record id.
|
||||||
*/
|
*/
|
||||||
public function insert($service) {
|
protected function _insert($service) {
|
||||||
if (!$this->db->insert('ea_services', $service)) {
|
if (!$this->db->insert('ea_services', $service)) {
|
||||||
throw new Exception('Could not insert service record.');
|
throw new Exception('Could not insert service record.');
|
||||||
}
|
}
|
||||||
|
@ -62,7 +64,7 @@ class Services_Model extends CI_Model {
|
||||||
* @param array $service Contains the service data. The record id needs to be included in
|
* @param array $service Contains the service data. The record id needs to be included in
|
||||||
* the array.
|
* the array.
|
||||||
*/
|
*/
|
||||||
public function update($service) {
|
protected function _update($service) {
|
||||||
$this->db->where('id', $service['id']);
|
$this->db->where('id', $service['id']);
|
||||||
if (!$this->db->update('ea_services', $service)) {
|
if (!$this->db->update('ea_services', $service)) {
|
||||||
throw new Exception('Could not update service record');
|
throw new Exception('Could not update service record');
|
||||||
|
@ -96,6 +98,7 @@ class Services_Model extends CI_Model {
|
||||||
* Validate a service record data.
|
* Validate a service record data.
|
||||||
*
|
*
|
||||||
* @param array $service Contains the service data.
|
* @param array $service Contains the service data.
|
||||||
|
*
|
||||||
* @return bool Returns the validation result.
|
* @return bool Returns the validation result.
|
||||||
*/
|
*/
|
||||||
public function validate($service) {
|
public function validate($service) {
|
||||||
|
@ -175,6 +178,7 @@ class Services_Model extends CI_Model {
|
||||||
* Delete a service record from database.
|
* Delete a service record from database.
|
||||||
*
|
*
|
||||||
* @param numeric $service_id Record id to be deleted.
|
* @param numeric $service_id Record id to be deleted.
|
||||||
|
*
|
||||||
* @return bool Returns the delete operation result.
|
* @return bool Returns the delete operation result.
|
||||||
*/
|
*/
|
||||||
public function delete($service_id) {
|
public function delete($service_id) {
|
||||||
|
@ -194,9 +198,9 @@ class Services_Model extends CI_Model {
|
||||||
* Get a specific row from the services db table.
|
* Get a specific row from the services db table.
|
||||||
*
|
*
|
||||||
* @param numeric $service_id The record's id to be returned.
|
* @param numeric $service_id The record's id to be returned.
|
||||||
* @return array Returns an associative array with the selected
|
*
|
||||||
* record's data. Each key has the same name as the database
|
* @return array Returns an associative array with the selected record's data. Each key
|
||||||
* field names.
|
* has the same name as the database field names.
|
||||||
*/
|
*/
|
||||||
public function get_row($service_id) {
|
public function get_row($service_id) {
|
||||||
if (!is_numeric($service_id)) {
|
if (!is_numeric($service_id)) {
|
||||||
|
@ -211,6 +215,7 @@ class Services_Model extends CI_Model {
|
||||||
* @param string $field_name The field name of the value to be
|
* @param string $field_name The field name of the value to be
|
||||||
* returned.
|
* returned.
|
||||||
* @param int $service_id The selected record's id.
|
* @param int $service_id The selected record's id.
|
||||||
|
*
|
||||||
* @return string Returns the records value from the database.
|
* @return string Returns the records value from the database.
|
||||||
*/
|
*/
|
||||||
public function get_value($field_name, $service_id) {
|
public function get_value($field_name, $service_id) {
|
||||||
|
@ -242,6 +247,7 @@ class Services_Model extends CI_Model {
|
||||||
*
|
*
|
||||||
* @param string $whereClause (OPTIONAL) The WHERE clause of
|
* @param string $whereClause (OPTIONAL) The WHERE clause of
|
||||||
* the query to be executed. DO NOT INCLUDE 'WHERE' KEYWORD.
|
* the query to be executed. DO NOT INCLUDE 'WHERE' KEYWORD.
|
||||||
|
*
|
||||||
* @return array Returns the rows from the database.
|
* @return array Returns the rows from the database.
|
||||||
*/
|
*/
|
||||||
public function get_batch($where_clause = NULL) {
|
public function get_batch($where_clause = NULL) {
|
||||||
|
@ -255,8 +261,7 @@ class Services_Model extends CI_Model {
|
||||||
/**
|
/**
|
||||||
* This method returns all the services from the database.
|
* This method returns all the services from the database.
|
||||||
*
|
*
|
||||||
* @return array Returns an object array with all the
|
* @return array Returns an object array with all the database services.
|
||||||
* database services.
|
|
||||||
*/
|
*/
|
||||||
public function get_available_services() {
|
public function get_available_services() {
|
||||||
$this->db->distinct();
|
$this->db->distinct();
|
||||||
|
@ -275,6 +280,7 @@ class Services_Model extends CI_Model {
|
||||||
* Add (insert or update) a service category record into database.
|
* Add (insert or update) a service category record into database.
|
||||||
*
|
*
|
||||||
* @param array $category Containst the service category data.
|
* @param array $category Containst the service category data.
|
||||||
|
*
|
||||||
* @return int Returns the record id.s
|
* @return int Returns the record id.s
|
||||||
*/
|
*/
|
||||||
public function add_category($category) {
|
public function add_category($category) {
|
||||||
|
@ -297,6 +303,7 @@ class Services_Model extends CI_Model {
|
||||||
* Delete a service category record from the database.
|
* Delete a service category record from the database.
|
||||||
*
|
*
|
||||||
* @param numeric $category_id Record id to be deleted.
|
* @param numeric $category_id Record id to be deleted.
|
||||||
|
*
|
||||||
* @return bool Returns the delete operation result.
|
* @return bool Returns the delete operation result.
|
||||||
*/
|
*/
|
||||||
public function delete_category($category_id) {
|
public function delete_category($category_id) {
|
||||||
|
@ -318,6 +325,7 @@ class Services_Model extends CI_Model {
|
||||||
* Get a service category record data.
|
* Get a service category record data.
|
||||||
*
|
*
|
||||||
* @param numeric $category_id Record id to be retrieved.
|
* @param numeric $category_id Record id to be retrieved.
|
||||||
|
*
|
||||||
* @return array Returns the record data from the database.
|
* @return array Returns the record data from the database.
|
||||||
*/
|
*/
|
||||||
public function get_category($category_id) {
|
public function get_category($category_id) {
|
||||||
|
@ -349,6 +357,7 @@ class Services_Model extends CI_Model {
|
||||||
* a service category record into database in order to secure the record integrity.
|
* a service category record into database in order to secure the record integrity.
|
||||||
*
|
*
|
||||||
* @param array $category Contains the service category data.
|
* @param array $category Contains the service category data.
|
||||||
|
*
|
||||||
* @return bool Returns the validation result.
|
* @return bool Returns the validation result.
|
||||||
*/
|
*/
|
||||||
public function validate_category($category) {
|
public function validate_category($category) {
|
||||||
|
|
|
@ -27,16 +27,15 @@ class Settings_Model extends CI_Model {
|
||||||
/**
|
/**
|
||||||
* Get setting value from database.
|
* Get setting value from database.
|
||||||
*
|
*
|
||||||
* This method returns a system setting from the
|
* This method returns a system setting from the database.
|
||||||
* database.
|
|
||||||
*
|
*
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
*
|
*
|
||||||
* @param string $name The database setting name.
|
* @param string $name The database setting name.
|
||||||
* @return string Returns the database value for
|
*
|
||||||
* the selected setting.
|
* @return string Returns the database value for the selected setting.
|
||||||
*/
|
*/
|
||||||
function get_setting($name) {
|
public function get_setting($name) {
|
||||||
if (!is_string($name)) { // Check argument type.
|
if (!is_string($name)) { // Check argument type.
|
||||||
throw new Exception('$name argument is not a string : ' . $name);
|
throw new Exception('$name argument is not a string : ' . $name);
|
||||||
}
|
}
|
||||||
|
@ -59,9 +58,10 @@ class Settings_Model extends CI_Model {
|
||||||
*
|
*
|
||||||
* @param string $name The setting name.
|
* @param string $name The setting name.
|
||||||
* @param type $value The setting value.
|
* @param type $value The setting value.
|
||||||
|
*
|
||||||
* @return int Returns the setting database id.
|
* @return int Returns the setting database id.
|
||||||
*/
|
*/
|
||||||
function set_setting($name, $value) {
|
public function set_setting($name, $value) {
|
||||||
if (!is_string($name)) {
|
if (!is_string($name)) {
|
||||||
throw new Exception('$name argument is not a string : ' . $name);
|
throw new Exception('$name argument is not a string : ' . $name);
|
||||||
}
|
}
|
||||||
|
@ -94,9 +94,10 @@ class Settings_Model extends CI_Model {
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
*
|
*
|
||||||
* @param string $name The setting name to be removed.
|
* @param string $name The setting name to be removed.
|
||||||
|
*
|
||||||
* @return bool Returns the delete operation result.
|
* @return bool Returns the delete operation result.
|
||||||
*/
|
*/
|
||||||
function remove_setting($name) {
|
public function remove_setting($name) {
|
||||||
if (!is_string($name)) {
|
if (!is_string($name)) {
|
||||||
throw new Exception('$name is not a string : ' . $name);
|
throw new Exception('$name is not a string : ' . $name);
|
||||||
}
|
}
|
||||||
|
@ -115,6 +116,7 @@ class Settings_Model extends CI_Model {
|
||||||
* saving them one by one.
|
* saving them one by one.
|
||||||
*
|
*
|
||||||
* @param array $settings Contains all the system settings.
|
* @param array $settings Contains all the system settings.
|
||||||
|
*
|
||||||
* @return bool Returns the save operation result.
|
* @return bool Returns the save operation result.
|
||||||
*
|
*
|
||||||
* @throws Exception When the update operation won't work for a specific setting.
|
* @throws Exception When the update operation won't work for a specific setting.
|
||||||
|
|
|
@ -30,6 +30,7 @@ class User_Model extends CI_Model {
|
||||||
* Returns the user settings from the database.
|
* Returns the user settings from the database.
|
||||||
*
|
*
|
||||||
* @param numeric $user_id User record id of which the settings will be returned.
|
* @param numeric $user_id User record id of which the settings will be returned.
|
||||||
|
*
|
||||||
* @return array Returns an array with user settings.
|
* @return array Returns an array with user settings.
|
||||||
*/
|
*/
|
||||||
public function get_settings($user_id) {
|
public function get_settings($user_id) {
|
||||||
|
@ -43,6 +44,7 @@ class User_Model extends CI_Model {
|
||||||
* This method saves the user settings into the database.
|
* This method saves the user settings into the database.
|
||||||
*
|
*
|
||||||
* @param array $user Contains the current users settings.
|
* @param array $user Contains the current users settings.
|
||||||
|
*
|
||||||
* @return bool Returns the operation result.
|
* @return bool Returns the operation result.
|
||||||
*/
|
*/
|
||||||
public function save_settings($user) {
|
public function save_settings($user) {
|
||||||
|
@ -72,6 +74,7 @@ class User_Model extends CI_Model {
|
||||||
* Retrieve user's salt from database.
|
* Retrieve user's salt from database.
|
||||||
*
|
*
|
||||||
* @param string $username This will be used to find the user record.
|
* @param string $username This will be used to find the user record.
|
||||||
|
*
|
||||||
* @return string Returns the salt db value.
|
* @return string Returns the salt db value.
|
||||||
*/
|
*/
|
||||||
public function get_salt($username) {
|
public function get_salt($username) {
|
||||||
|
@ -84,8 +87,8 @@ class User_Model extends CI_Model {
|
||||||
*
|
*
|
||||||
* @param string $username Given user's name.
|
* @param string $username Given user's name.
|
||||||
* @param type $password Given user's password (not hashed yet).
|
* @param type $password Given user's password (not hashed yet).
|
||||||
* @return array|null Returns the session data of the logged in user or null on
|
*
|
||||||
* failure.
|
* @return array|null Returns the session data of the logged in user or null on failure.
|
||||||
*/
|
*/
|
||||||
public function check_login($username, $password) {
|
public function check_login($username, $password) {
|
||||||
$this->load->helper('general');
|
$this->load->helper('general');
|
||||||
|
@ -109,6 +112,7 @@ class User_Model extends CI_Model {
|
||||||
* Get the given user's display name (first + last name).
|
* Get the given user's display name (first + last name).
|
||||||
*
|
*
|
||||||
* @param numeric $user_id The given user record id.
|
* @param numeric $user_id The given user record id.
|
||||||
|
*
|
||||||
* @return string Returns the user display name.
|
* @return string Returns the user display name.
|
||||||
*/
|
*/
|
||||||
public function get_user_display_name($user_id) {
|
public function get_user_display_name($user_id) {
|
||||||
|
@ -124,6 +128,7 @@ class User_Model extends CI_Model {
|
||||||
*
|
*
|
||||||
* @param string $username
|
* @param string $username
|
||||||
* @param string $email
|
* @param string $email
|
||||||
|
*
|
||||||
* @return string|bool Returns the new password on success or FALSE on failure.
|
* @return string|bool Returns the new password on success or FALSE on failure.
|
||||||
*/
|
*/
|
||||||
public function regenerate_password($username, $email) {
|
public function regenerate_password($username, $email) {
|
||||||
|
|
Loading…
Reference in a new issue