General Progress
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user