array('model'=>'Room_Children','foreign_key'=>'child_id','far_key'=>'id'), ); public function filters() { return Arr::merge(parent::filters(),array( 'dob'=>array(array('strtotime', array(':value'))), )); } protected $_display_filters = array( 'dob'=>array( array('Site::Date',array(':value')), ), ); protected $_sub_items_load = array( 'room'=>'date_start,date_stop', ); private function _dob() { $x = new DateTime(); return $x->setTimestamp($this->dob); } public function age($asat=NULL,$format='%Yy%Mm') { if (is_null($asat)) $asat = time(); $dob = $this->_dob(); $today = new DateTime(); $today->setTimestamp($asat); return $format == '%w' ? sprintf('%02dw',$dob->diff($today)->days/7) : $dob->diff($today)->format($format); } public function date_enrol_min() { $dob = $this->_dob(); $dob->add(new DateInterval('P'.$this->_start)); return $format ? $result->format(Kohana::$config->load('config')->date_format) : $result->format('U'); } public function date_enrol_max($format=FALSE) { $dob = $this->_dob(); $dob->add(new DateInterval('P'.$this->_max)); $last = new DateTime(sprintf('%s-%s',$dob->format('Y'),$this->_max_date)); $x = $dob->diff($last); $result = new DateTime(sprintf('%s-%s',$dob->format('Y')+($x->invert ? 1 : 0),$this->_max_return)); return $format ? $result->format(Company::instance()->date_format()) : $result->format('U'); } 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'])); $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 ($rco->changed() AND (! $rco->save())) $rco->reload()->values($_POST['room']); return $this->reload(); } } ?>