General Progress
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports Children
|
||||
* This class supports Children
|
||||
*
|
||||
* @package Membership Database
|
||||
* @category Models
|
||||
@@ -26,13 +26,19 @@ class Model_Child extends ORM {
|
||||
}
|
||||
|
||||
protected $_display_filters = array(
|
||||
'date_orig'=>array(
|
||||
array('Site::Date',array(':value')),
|
||||
),
|
||||
'date_last'=>array(
|
||||
array('Site::Date',array(':value')),
|
||||
),
|
||||
'dob'=>array(
|
||||
array('Site::Date',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
protected $_sub_items_load = array(
|
||||
'room'=>'date_start,date_stop',
|
||||
'room'=>array('date_start','date_stop'),
|
||||
);
|
||||
|
||||
private function _dob() {
|
||||
@@ -54,7 +60,7 @@ class Model_Child extends ORM {
|
||||
}
|
||||
|
||||
public function date($value) {
|
||||
return is_numeric($value) ? $value : strtotime($value);
|
||||
return is_numeric($value) ? $value : strtotime($value);
|
||||
}
|
||||
|
||||
public function date_enrol_min() {
|
||||
@@ -76,27 +82,83 @@ class Model_Child extends ORM {
|
||||
return $format ? $result->format(Company::instance()->date_format()) : $result->format('U');
|
||||
}
|
||||
|
||||
public function days($room_id,$date_start,$days,$code,$markup=FALSE) {
|
||||
$result = '';
|
||||
|
||||
$date_end = $date_start+$days*86400;
|
||||
$open_dates = Company::instance()->so()->open_dates($date_start,$days);
|
||||
|
||||
$o = $this->room->where('code','=',$code);
|
||||
$o->where_startstop($date_start,$date_end);
|
||||
if (! is_null($room_id))
|
||||
$o->where('room_id','=',$room_id);
|
||||
|
||||
// Set all open dayes to 0
|
||||
foreach ($open_dates as $k=>$v)
|
||||
if ($v === TRUE)
|
||||
$open_dates[$k] = 0;
|
||||
|
||||
foreach ($o->find_all() as $date => $rco) {
|
||||
foreach ($open_dates as $day=>$open) {
|
||||
if ($open === FALSE or $rco->date_start > $day OR $rco->date_stop < $day)
|
||||
continue;
|
||||
|
||||
$open_dates[$day] = $rco->day(date('w',$day));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($open_dates as $day=>$open) {
|
||||
$dayname = substr(date('D',$day),0,1);
|
||||
|
||||
if ($open === FALSE)
|
||||
$result .= $markup ? sprintf('<span class="fa-stack text-danger"><i class="fa fa-square fa-stack-2x"></i><span class="fa-stack-1x" style="color: white;">%s</span></span>',$dayname) : '-';
|
||||
elseif ($open)
|
||||
$result .= $markup ? sprintf('<span class="fa-stack text-success"><i class="fa %s fa-stack-2x"></i><strong class="fa-stack-1x" style="color: %s;">%s</strong></span>',($code=='P' ? 'fa-circle' : 'fa-circle-o'),($code=='P' ? 'white' : 'black'),$dayname) : $dayname;
|
||||
else
|
||||
$result .= $markup ? sprintf('<span class="fa-stack"><i class="fa fa-square-o fa-stack-2x"></i><strong class="fa-stack-1x">%s</strong></span>',$dayname) : strtolower($dayname);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function name() {
|
||||
return sprintf('%s, %s',strtoupper($this->family_name),$this->first_name);
|
||||
}
|
||||
|
||||
public function save(Validation $validation=NULL) {
|
||||
$changed = $this->changed();
|
||||
|
||||
parent::save($validation);
|
||||
|
||||
// Insert into waitlist
|
||||
$rco = ORM::factory('Room_Children',array('child_id'=>$this,'code'=>$_POST['room']['code']));
|
||||
// Process our Sub-Items and Validate them.
|
||||
Sort::MASort($this->_sub_items,array('code','room_id','date_start','date_stop'));
|
||||
$last = NULL;
|
||||
foreach ($this->_sub_items as $rco) {
|
||||
// If no dates are selected, clear this record.
|
||||
if (! $rco->have_days()) {
|
||||
if ($rco->loaded())
|
||||
$rco->delete();
|
||||
|
||||
$rco->values($_POST['room']);
|
||||
$rco->child_id = (string)$this;
|
||||
|
||||
foreach ($_POST['room']['R'] as $k => $v) {
|
||||
if (! $v OR isset($_POST['room']['d_'.$k]))
|
||||
continue;
|
||||
}
|
||||
|
||||
$rco->{'d_'.$k} = NULL;
|
||||
// If there is no last item, we'll accept this as is.
|
||||
if (is_null($last) OR ($last->date_stop <= $rco->date_start)) {
|
||||
$rco->save($validation);
|
||||
$last = $rco;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// @todo: If our dates overlap, fix that
|
||||
// @todo: Check that casual days dont overlap with permanent days
|
||||
// @todo: Check that absent days are attending days
|
||||
// @todo: Check that waitlist days dont overlap with permanent days
|
||||
|
||||
if ($rco->changed() AND (! $rco->save()))
|
||||
$rco->reload();
|
||||
}
|
||||
|
||||
if ($rco->changed() AND (! $rco->save()))
|
||||
$rco->reload()->values($_POST['room']);
|
||||
|
||||
return $this->reload();
|
||||
}
|
||||
}
|
||||
|
@@ -12,12 +12,19 @@
|
||||
class Model_Room_Children extends ORM {
|
||||
protected $_belongs_to = array(
|
||||
'child'=>array(),
|
||||
'room'=>array('model'=>'Rooms'),
|
||||
);
|
||||
|
||||
public function filters() {
|
||||
return Arr::merge(parent::filters(),array(
|
||||
'date_start'=>array(array('strtotime', array(':value'))),
|
||||
'date_stop'=>array(array('strtotime', array(':value'))),
|
||||
'date_start'=>array(
|
||||
array('strtotime', array(':value')),
|
||||
array('ORM::tostring', array(':value')),
|
||||
),
|
||||
'date_stop'=>array(
|
||||
array('strtotime', array(':value')),
|
||||
array('ORM::tostring', array(':value')),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -26,7 +33,20 @@ class Model_Room_Children extends ORM {
|
||||
|
||||
unset($x['id']);
|
||||
|
||||
return $x;
|
||||
return Arr::merge($x,array(
|
||||
'date_start'=>array(
|
||||
array('not_empty'),
|
||||
),
|
||||
'date_stop'=>array(
|
||||
array('not_empty'),
|
||||
array(array($this,'validate_datestop'),array(':validation')),
|
||||
),
|
||||
'code' => array(
|
||||
array(array($this,'validate_absentnoshow'),array(':validation',':value')),
|
||||
array(array($this,'validate_absentnotice'),array(':validation',':value')),
|
||||
array(array($this,'validate_casualrequest'),array(':validation',':value')),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
protected $_display_filters = array(
|
||||
@@ -38,9 +58,58 @@ class Model_Room_Children extends ORM {
|
||||
),
|
||||
);
|
||||
|
||||
// @todo: Code A (availble) start/end dates cannot overlap with existing records - put in validation that it cannot be saved.
|
||||
public function day($day) {
|
||||
return $this->{'d_'.$day};
|
||||
}
|
||||
|
||||
/**
|
||||
* Has a day been selected
|
||||
*/
|
||||
public function have_days() {
|
||||
for ($i=0;$i<7;$i++)
|
||||
if ($this->day($i))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* No show date cannot be in the future
|
||||
*/
|
||||
public function validate_absentnoshow($array,$code) {
|
||||
return ($code != 'A') OR ($array['date_start'] < time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice date cannot be in the past
|
||||
*/
|
||||
public function validate_absentnotice($array,$code) {
|
||||
return ($code != 'a') OR ($array['date_start'] > time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Casual Request cannot be in the past
|
||||
*/
|
||||
public function validate_casualrequest($array,$code) {
|
||||
return ($code != 'c') OR ($array['date_start'] > time());
|
||||
}
|
||||
|
||||
/**
|
||||
* End date cannot be earlier than start date
|
||||
*/
|
||||
public function validate_datestop($array) {
|
||||
return $array['date_start'] <= $array['date_stop'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Since we use checkboxes for dates, we need to unselect dates not selected
|
||||
*/
|
||||
public function values(array $values, array $expected = NULL) {
|
||||
for ($i=0;$i<7;$i++)
|
||||
if ($this->day($i) AND empty($values['d_'.$i]))
|
||||
$this->{'d_'.$i} = NULL;
|
||||
|
||||
return parent::values($values,$expected);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -18,6 +18,8 @@ class Model_Rooms extends ORM {
|
||||
'children'=>array('model'=>'Room_Children','far_key'=>'id','foreign_key'=>'room_id'),
|
||||
);
|
||||
|
||||
protected $_form = array('id'=>'id','value'=>'name');
|
||||
|
||||
public function availability_dates($date,$days=0,$code='A') {
|
||||
$result = array();
|
||||
$x = $date;
|
||||
|
@@ -78,6 +78,21 @@ class Model_Setup extends ORM {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function available_places($date_start,$days=0) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->rooms->find_all() as $ro) {
|
||||
foreach ($ro->room_availablity($date_start,$days) as $date => $total) {
|
||||
if (! isset($result[$date]))
|
||||
$result[$date] = 0;
|
||||
|
||||
$result[$date] += $total;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function module_config_id($key=NULL) {
|
||||
$result = array();
|
||||
|
||||
|
Reference in New Issue
Block a user