This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
memberdb/application/classes/Model/Room/Children.php
2015-09-29 15:58:41 +10:00

116 lines
2.6 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Children in a Room Configuration
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
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')),
array('ORM::tostring', array(':value')),
),
'date_stop'=>array(
array('strtotime', array(':value')),
array('ORM::tostring', array(':value')),
),
));
}
public function rules() {
$x = parent::rules();
unset($x['id']);
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(
'date_start'=>array(
array('Site::Date',array(':value')),
),
'date_stop'=>array(
array('Site::Date',array(':value')),
),
);
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);
}
}
?>