2014-09-05 05:13:25 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class supports Company Rooms
|
|
|
|
*
|
|
|
|
* @package Membership Database
|
|
|
|
* @category Models
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2014 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
|
|
|
class Model_Rooms extends ORM {
|
2014-09-05 12:19:22 +00:00
|
|
|
protected $_belongs_to = array(
|
|
|
|
'site'=>array('model'=>'Setup'),
|
|
|
|
);
|
2014-09-05 05:13:25 +00:00
|
|
|
protected $_has_many = array(
|
|
|
|
'dates'=>array('model'=>'Room_Dates','far_key'=>'id','foreign_key'=>'room_id'),
|
2014-09-05 12:19:22 +00:00
|
|
|
'children'=>array('model'=>'Room_Children','far_key'=>'id','foreign_key'=>'room_id'),
|
2014-09-05 05:13:25 +00:00
|
|
|
);
|
|
|
|
|
2014-09-05 12:19:22 +00:00
|
|
|
public function availability_dates($date,$days=0,$code='A') {
|
2014-09-05 05:13:25 +00:00
|
|
|
$result = array();
|
2014-09-05 12:19:22 +00:00
|
|
|
$x = $date;
|
2014-09-05 05:13:25 +00:00
|
|
|
|
|
|
|
$date_end = $date+$days*86400;
|
2014-09-05 12:19:22 +00:00
|
|
|
$open_dates = $this->site->open_dates($date,$days);
|
|
|
|
foreach ($this->dates->where('code','=',$code)->where_startstop($date,$date_end)->find_all() as $o) {
|
2014-09-05 05:13:25 +00:00
|
|
|
$x = $date;
|
|
|
|
|
|
|
|
while ($x<$date_end) {
|
|
|
|
// If we havent made the start date yet, we need to advance
|
|
|
|
if (! $open_dates[$x]
|
|
|
|
OR ($o->date_start > $x AND (is_null($o->date_stop) OR $o->date_stop > $date_end))
|
|
|
|
OR ((is_null($o->date_start) OR $o->date_start > $x) AND $o->date_stop > $date_end)
|
|
|
|
OR (! is_null($o->date_start) AND ! is_null($o->date_stop))) {
|
|
|
|
|
|
|
|
if (! isset($result[$x]) OR ! $result[$x])
|
|
|
|
$result[$x] = 0;
|
|
|
|
|
|
|
|
$x += 86400;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that this record covers our current date
|
|
|
|
if ($o->date_stop < $x AND ! is_null($o->date_stop))
|
|
|
|
break;
|
|
|
|
|
|
|
|
$result[$x] = $o->avail(date('w',$x));
|
|
|
|
$x += 86400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we broke out and our date $days hasnt ben evaluated, we are closed
|
|
|
|
while ($x<$date_end) {
|
|
|
|
if (! isset($result[$x]) OR ! $result[$x])
|
|
|
|
$result[$x] = 0;
|
|
|
|
|
|
|
|
$x += 86400;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2014-09-05 12:19:22 +00:00
|
|
|
|
|
|
|
// 'P' - Permanent
|
|
|
|
public function child_list_date($date,$days,$code='P') {
|
|
|
|
$result = array();
|
|
|
|
$x = $date;
|
|
|
|
|
|
|
|
$date_end = $date+$days*86400;
|
|
|
|
$open_dates = $this->site->open_dates($date,$days);
|
|
|
|
foreach ($this->children->where('code','=',$code)->where_startstop($date,$date_end)->find_all() as $o) {
|
|
|
|
$x = $date;
|
|
|
|
|
|
|
|
while ($x<$date_end) {
|
|
|
|
// If we havent made the start date yet, we need to advance
|
|
|
|
if (! $open_dates[$x]
|
|
|
|
OR ($o->date_start > $x AND (is_null($o->date_stop) OR $o->date_stop > $date_end))
|
|
|
|
OR ((is_null($o->date_start) OR $o->date_start > $x) AND $o->date_stop > $date_end)
|
|
|
|
OR (! is_null($o->date_start) AND ! is_null($o->date_stop))) {
|
|
|
|
|
|
|
|
if (! isset($result[$x]) OR ! $result[$x])
|
|
|
|
$result[$x] = array();
|
|
|
|
|
|
|
|
$x += 86400;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that this record covers our current date
|
|
|
|
if ($o->date_stop < $x AND ! is_null($o->date_stop))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (! isset($result[$x]))
|
|
|
|
$result[$x] = array();
|
|
|
|
|
|
|
|
if ($o->day(date('w',$x)))
|
|
|
|
array_push($result[$x],$o->child);
|
|
|
|
|
|
|
|
$x += 86400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we broke out and our date $days hasnt ben evaluated, we are closed
|
|
|
|
while ($x<$date_end) {
|
|
|
|
if (! isset($result[$x]) OR ! $result[$x])
|
|
|
|
$result[$x] = array();
|
|
|
|
|
|
|
|
$x += 86400;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function room_availablity($date,$days) {
|
|
|
|
// We start with our availablity
|
|
|
|
$result = $this->availability_dates($date,$days);
|
|
|
|
|
|
|
|
// Less Permanents
|
|
|
|
foreach ($this->child_list_date($date,$days) as $k => $v)
|
|
|
|
$result[$k] -= count($v);
|
|
|
|
|
|
|
|
// Add Absent
|
|
|
|
foreach ($this->child_list_date($date,$days,'a') as $k => $v)
|
|
|
|
$result[$k] += count($v);
|
|
|
|
|
|
|
|
// Less Casuals
|
|
|
|
foreach ($this->child_list_date($date,$days,'C') as $k => $v)
|
|
|
|
$result[$k] -= count($v);
|
|
|
|
|
|
|
|
// Less Waitlist
|
|
|
|
foreach ($this->child_list_date($date,$days,'W') as $k => $v)
|
|
|
|
$result[$k] -= count($v);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2014-09-05 05:13:25 +00:00
|
|
|
}
|
|
|
|
?>
|