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

116 lines
2.6 KiB
PHP
Raw Normal View History

2014-09-05 12:19:22 +00:00
<?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(),
2014-12-01 03:01:02 +00:00
'room'=>array('model'=>'Rooms'),
2014-09-05 12:19:22 +00:00
);
2014-10-22 11:22:47 +00:00
public function filters() {
return Arr::merge(parent::filters(),array(
2014-12-01 03:01:02 +00:00
'date_start'=>array(
array('strtotime', array(':value')),
array('ORM::tostring', array(':value')),
),
'date_stop'=>array(
array('strtotime', array(':value')),
array('ORM::tostring', array(':value')),
),
2014-10-22 11:22:47 +00:00
));
}
public function rules() {
$x = parent::rules();
unset($x['id']);
2014-12-01 03:01:02 +00:00
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')),
),
));
2014-10-22 11:22:47 +00:00
}
protected $_display_filters = array(
'date_start'=>array(
array('Site::Date',array(':value')),
),
'date_stop'=>array(
array('Site::Date',array(':value')),
),
);
2014-09-05 12:19:22 +00:00
public function day($day) {
return $this->{'d_'.$day};
}
2014-12-01 03:01:02 +00:00
/**
* 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);
}
2014-09-05 12:19:22 +00:00
}
?>