Created
September 19, 2016 11:12
-
-
Save shvelo/8872b9c5a8a46eeb3c6cc3cba82abd6b to your computer and use it in GitHub Desktop.
I wrote this 5 years ago, I think it's for determining available times for booking car wash, but I have no idea how it works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function get_available_times($serv, $date = false) | |
{ | |
$CI = &get_instance(); | |
$opening = 9 * 60; | |
$closing = 19 * 60; | |
$available = array(); | |
if ($date === false) { | |
$date = date('Y-m-d'); | |
} | |
$service = $CI->db->get_where('services', array('id' => $serv))->result(); | |
if ($service === false) { | |
return false; | |
} | |
$service = $service[0]; | |
$orders = $CI->db->where('date', $date)->where('status !=', 'deactivated')->order_by('time', 'asc')->get('booking')->result(); | |
$open = $opening; | |
foreach ($orders as $n => $order) { | |
if ($n > 0) { | |
$open = $orders[$n - 1]->end; | |
} | |
if ($n === count($orders)) { | |
$start = $closing; | |
} else { | |
$start = $order->time; | |
} | |
$div = floor(($start - $open) / $service->duration); | |
if ($div >= 1) { | |
for ($i = 1; $i <= $div; ++$i) { | |
$available[] = $open + ($service->duration * ($i - 1)); | |
} | |
} | |
$open = $order->end; | |
} | |
$div = ($closing - $open) / $service->duration; | |
if ($div >= 1) { | |
for ($i = 1; $i <= $div; ++$i) { | |
$available[] = $open + ($service->duration * ($i - 1)); | |
} | |
} | |
return $available; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment