array( array('Site::date',array(':value')), ), 'date_stop'=>array( array('Site::date',array(':value')), ), ); /** * List our codes * CODE: * + O (open) - site is open for business (start/end cannot overlap) * + S (school year) - this is a year for school terms @see mdb_term_dates (only year is used from start) * @todo: Code O (open) start/end dates cannot overlap with existing records - put in validation that it cannot be saved. */ public function codes() { return [ 'O'=>'Open', 'S'=>'School Year', ]; } /** * Return if this day is open */ public function open($day) { return $this->{'d_'.$day}; } public function where_year($year) { $id = 0; foreach ($this->list_years() as $k => $v) if ($v == $year) { $id = $k; break; } // If we get hear, we didnt find the years return ORM::factory('Site_Dates',$id ? $id : NULL); } /** * Return the year this record peratins to * @note: Only valid for School Years (code S) */ public function year() { if ($this->code != 'S') throw HTTP_Exception::factory(501,'Invalid call to :method, code [:code] is incorrect',[':method'=>__METHOD__,':code'=>$this->code]); return $this->date_start ? date('Y',$this->date_start) : NULL; } public function list_years() { $result = array(); foreach (ORM::factory('Site_Dates')->where('code','=','S')->where('date_stop','>',time())->find_all()->as_array() as $sdo) $result[$sdo->id] = $sdo->year(); return $result; } } ?>