mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-25 17:33:19 +03:00
Fixes #66 thanks to bikimike solution.
This commit is contained in:
parent
561fc8d859
commit
1e31c11341
1 changed files with 116 additions and 101 deletions
|
@ -550,11 +550,10 @@ class Appointments extends CI_Controller {
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
|
|
||||||
// Get the provider's working plan and reserved appointments.
|
// Get the provider's working plan and reserved appointments.
|
||||||
$working_plan = json_decode($this->providers_model
|
$working_plan = json_decode($this->providers_model->get_setting('working_plan', $provider_id), true);
|
||||||
->get_setting('working_plan', $provider_id), true);
|
|
||||||
|
|
||||||
$where_clause = array(
|
$where_clause = array(
|
||||||
'DATE(start_datetime)' => date('Y-m-d', strtotime($selected_date)),
|
//'DATE(start_datetime)' => date('Y-m-d', strtotime($selected_date)),
|
||||||
'id_users_provider' => $provider_id
|
'id_users_provider' => $provider_id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -577,36 +576,56 @@ class Appointments extends CI_Controller {
|
||||||
$available_periods_with_breaks = array();
|
$available_periods_with_breaks = array();
|
||||||
|
|
||||||
if (isset($selected_date_working_plan['breaks'])) {
|
if (isset($selected_date_working_plan['breaks'])) {
|
||||||
if (count($selected_date_working_plan['breaks'])) {
|
$start = new DateTime($selected_date_working_plan['start']);
|
||||||
foreach($selected_date_working_plan['breaks'] as $index=>$break) {
|
$end = new DateTime($selected_date_working_plan['end']);
|
||||||
// Split the working plan to available time periods that do not
|
|
||||||
// contain the breaks in them.
|
|
||||||
$last_break_index = $index - 1;
|
|
||||||
|
|
||||||
if (count($available_periods_with_breaks) === 0) {
|
|
||||||
$start_hour = $selected_date_working_plan['start'];
|
|
||||||
$end_hour = $break['start'];
|
|
||||||
} else {
|
|
||||||
$start_hour = $selected_date_working_plan['breaks'][$last_break_index]['end'];
|
|
||||||
$end_hour = $break['start'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$available_periods_with_breaks[] = array(
|
|
||||||
'start' => $start_hour,
|
|
||||||
'end' => $end_hour
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the period from the last break to the end of the day.
|
|
||||||
$available_periods_with_breaks[] = array(
|
|
||||||
'start' => $selected_date_working_plan['breaks'][$index]['end'],
|
|
||||||
'end' => $selected_date_working_plan['end']
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$available_periods_with_breaks[] = array(
|
$available_periods_with_breaks[] = array(
|
||||||
'start' => $selected_date_working_plan['start'],
|
'start' => $selected_date_working_plan['start'],
|
||||||
'end' => $selected_date_working_plan['end']
|
'end' => $selected_date_working_plan['end']
|
||||||
);
|
);
|
||||||
|
// Split the working plan to available time periods that do not
|
||||||
|
// contain the breaks in them.
|
||||||
|
foreach($selected_date_working_plan['breaks'] as $index=>$break) {
|
||||||
|
$break_start = new DateTime($break['start']);
|
||||||
|
$break_end = new DateTime($break['end']);
|
||||||
|
if ($break_start < $start)
|
||||||
|
$break_start = $start;
|
||||||
|
if ($break_end > $end)
|
||||||
|
$break_end = $end;
|
||||||
|
if ($break_start >= $break_end)
|
||||||
|
continue;
|
||||||
|
foreach ($available_periods_with_breaks as $key => $open_period)
|
||||||
|
{
|
||||||
|
$s = new DateTime($open_period['start']);
|
||||||
|
$e = new DateTime($open_period['end']);
|
||||||
|
if ($s < $break_end && $break_start < $e) // check for overlap
|
||||||
|
{
|
||||||
|
$changed = FALSE;
|
||||||
|
if ($s < $break_start)
|
||||||
|
{
|
||||||
|
$open_start = $s;
|
||||||
|
$open_end = $break_start;
|
||||||
|
$available_periods_with_breaks[] = array(
|
||||||
|
'start' => $open_start->format("H:i"),
|
||||||
|
'end' => $open_end->format("H:i")
|
||||||
|
);
|
||||||
|
$changed = TRUE;
|
||||||
|
}
|
||||||
|
if ($break_end < $e)
|
||||||
|
{
|
||||||
|
$open_start = $break_end;
|
||||||
|
$open_end = $e;
|
||||||
|
$available_periods_with_breaks[] = array(
|
||||||
|
'start' => $open_start->format("H:i"),
|
||||||
|
'end' => $open_end->format("H:i")
|
||||||
|
);
|
||||||
|
$changed = TRUE;
|
||||||
|
}
|
||||||
|
if ($changed)
|
||||||
|
{
|
||||||
|
unset($available_periods_with_breaks[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,7 +639,6 @@ class Appointments extends CI_Controller {
|
||||||
$a_end = strtotime($appointment['end_datetime']);
|
$a_end = strtotime($appointment['end_datetime']);
|
||||||
$p_start = strtotime($selected_date . ' ' . $period['start']);
|
$p_start = strtotime($selected_date . ' ' . $period['start']);
|
||||||
$p_end = strtotime($selected_date . ' ' .$period['end']);
|
$p_end = strtotime($selected_date . ' ' .$period['end']);
|
||||||
|
|
||||||
if ($a_start <= $p_start && $a_end <= $p_end && $a_end <= $p_start) {
|
if ($a_start <= $p_start && $a_end <= $p_end && $a_end <= $p_start) {
|
||||||
// The appointment does not belong in this time period, so we
|
// The appointment does not belong in this time period, so we
|
||||||
// will not change anything.
|
// will not change anything.
|
||||||
|
@ -628,7 +646,6 @@ class Appointments extends CI_Controller {
|
||||||
// The appointment starts before the period and finishes somewhere inside.
|
// The appointment starts before the period and finishes somewhere inside.
|
||||||
// We will need to break this period and leave the available part.
|
// We will need to break this period and leave the available part.
|
||||||
$period['start'] = date('H:i', $a_end);
|
$period['start'] = date('H:i', $a_end);
|
||||||
|
|
||||||
} else if ($a_start >= $p_start && $a_end <= $p_end) {
|
} else if ($a_start >= $p_start && $a_end <= $p_end) {
|
||||||
// The appointment is inside the time period, so we will split the period
|
// The appointment is inside the time period, so we will split the period
|
||||||
// into two new others.
|
// into two new others.
|
||||||
|
@ -641,12 +658,10 @@ class Appointments extends CI_Controller {
|
||||||
'start' => date('H:i', $a_end),
|
'start' => date('H:i', $a_end),
|
||||||
'end' => date('H:i', $p_end)
|
'end' => date('H:i', $p_end)
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if ($a_start >= $p_start && $a_end >= $p_start && $a_start <= $p_end) {
|
} else if ($a_start >= $p_start && $a_end >= $p_start && $a_start <= $p_end) {
|
||||||
// The appointment starts in the period and finishes out of it. We will
|
// The appointment starts in the period and finishes out of it. We will
|
||||||
// need to remove the time that is taken from the appointment.
|
// need to remove the time that is taken from the appointment.
|
||||||
$period['end'] = date('H:i', $a_start);
|
$period['end'] = date('H:i', $a_start);
|
||||||
|
|
||||||
} else if ($a_start >= $p_start && $a_end >= $p_end && $a_start >= $p_end) {
|
} else if ($a_start >= $p_start && $a_end >= $p_end && $a_start >= $p_end) {
|
||||||
// The appointment does not belong in the period so do not change anything.
|
// The appointment does not belong in the period so do not change anything.
|
||||||
} else if ($a_start <= $p_start && $a_end >= $p_end && $a_start <= $p_end) {
|
} else if ($a_start <= $p_start && $a_end >= $p_end && $a_start <= $p_end) {
|
||||||
|
|
Loading…
Reference in a new issue