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/Site/Dates.php
2016-08-31 02:13:05 +10:00

80 lines
1.9 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Site Operating Dates
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*
*/
class Model_Site_Dates extends ORM {
protected $_created_column = NULL;
protected $_updated_column = NULL;
protected $_display_filters = array(
'date_start'=>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;
}
}
?>