diff --git a/src/application/controllers/appointments.php b/src/application/controllers/appointments.php index 00830ece..3d6a4618 100644 --- a/src/application/controllers/appointments.php +++ b/src/application/controllers/appointments.php @@ -5,11 +5,45 @@ class Appointments extends CI_Controller { * This page displays the book appointment wizard * for the customers. */ - public function index() - { + public function index() { + // Get business name. $this->load->model('Settings'); $viewData['businessName'] = $this->Settings->getSetting('business_name'); + // Get the available services and providers. + $this->load->model('Services'); + $viewData['availableServices'] = $this->Services->getAvailableServices(); + + $this->load->model('Providers'); + $viewData['availableProviders'] = $this->Providers->getAvailableProviders(); // Provider rows contain an array of which services they can provide. + + // Load the book appointment view. $this->load->view('appointments/book', $viewData); } + + /** + * This method answers to an AJAX request. It calculates the + * available hours for the given service, provider and date. + * + * @param array $_POST['postData'] An associative array that + * contains the user selected service, provider and date. + */ + public function getAvailableHours() { + /*** CHECK BUSINESS WORKING HOURS ***/ + /*** CHECK PROVIDERS WORKING HOURS ***/ + /*** CHECK ALREADY BOOKED APPOINTMENTS ***/ + /*** RETURN AVAILABLE HOURS ***/ + + // ------------------------------------------------------------------ + // For now we just need to return a sample array. Dynamic calculation + // will be adding in future development. + $startTime = strtotime($_POST['selectedDate'] . ' 08:00') / 60; // Convert to minutes + $endTime = strtotime($_POST['selectedDate'] . ' 16:00') / 60; // Convert to minutes + + for ($i=0; ($startTime*60 + $i*60)<=($endTime*60); $i+=intval($_POST['serviceDuration'])) { + $availableHours[] = date('H:i', $startTime * 60 + $i * 60); + } + + echo json_encode($availableHours); + } } diff --git a/src/application/models/providers.php b/src/application/models/providers.php index b6eddc13..7182fe3e 100644 --- a/src/application/models/providers.php +++ b/src/application/models/providers.php @@ -1,7 +1,44 @@ +class Providers extends CI_Model { + public function __construct() { + parent::__construct(); + } + + /** + * This method returns the available providers and + * the services that can provide. + * + * @return array Returns an array with the providers + * data. + */ + public function getAvailableProviders() { + $sql = ' + SELECT ea_users.* + FROM ea_users + INNER JOIN ea_roles + ON ea_users.id_roles = ea_roles.id + WHERE ea_roles.slug = "provider"'; + + $providers = $this->db->query($sql)->result_array(); + + foreach($providers as &$provider) { + $sql = ' + SELECT id_services + FROM ea_services_providers + WHERE id_users = ' . $this->db->escape($provider['id']); + + $providerServices = $this->db->query($sql)->result_array(); + + if (!isset($provider['services'])) { + $provider['services'] = array(); + } + + foreach($providerServices as $providerService) { + $provider['services'][] = $providerService['id_services']; + } + } + + return $providers; + } +} +?> \ No newline at end of file diff --git a/src/application/models/services.php b/src/application/models/services.php index fac32b90..800acf33 100644 --- a/src/application/models/services.php +++ b/src/application/models/services.php @@ -10,10 +10,8 @@ class Services extends CI_Model { * @return array Returns an object array with all the * database services. */ - function getAllServices() { - $query = $this->db->query('SELECT *'); - - return $this->db->get('ea_services'); + function getAvailableServices() { + return $this->db->get('ea_services')->result_array(); } } ?> diff --git a/src/application/models/settings.php b/src/application/models/settings.php index f46f368d..92955290 100644 --- a/src/application/models/settings.php +++ b/src/application/models/settings.php @@ -27,7 +27,6 @@ class Settings extends CI_Model { * * @param string $name The setting name. * @param type $value The setting value. - * * @return bool Returns the operation success - failure * result. */ diff --git a/src/application/views/appointments/book.php b/src/application/views/appointments/book.php index a7e46c7e..f4c7d206 100644 --- a/src/application/views/appointments/book.php +++ b/src/application/views/appointments/book.php @@ -1,6 +1,8 @@
+ + @@ -13,13 +15,151 @@ + @@ -51,35 +191,96 @@