2008-05-14 07:54:11 +02:00
|
|
|
<?php
|
2008-08-06 05:31:42 +02:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
|
|
|
*/
|
|
|
|
|
2008-05-14 07:54:11 +02:00
|
|
|
/**
|
|
|
|
* Represents a single year field.
|
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
|
|
|
*/
|
|
|
|
class Year extends DBField {
|
|
|
|
|
|
|
|
function requireField() {
|
2009-02-17 04:54:10 +01:00
|
|
|
$parts=Array('datatype'=>'year', 'precision'=>4);
|
|
|
|
$values=Array('type'=>'year', 'parts'=>$parts);
|
|
|
|
DB::requireField($this->tableName, $this->name, $values);
|
2008-05-14 07:54:11 +02:00
|
|
|
}
|
|
|
|
|
2008-10-14 00:20:41 +02:00
|
|
|
public function scaffoldFormField($title = null, $params = null) {
|
2008-05-14 07:54:11 +02:00
|
|
|
$selectBox = new DropdownField($this->name, $title);
|
|
|
|
$selectBox->setSource($this->getDefaultOptions());
|
|
|
|
return $selectBox;
|
|
|
|
}
|
|
|
|
|
2008-08-09 07:04:15 +02:00
|
|
|
/**
|
|
|
|
* Returns a list of default options that can
|
|
|
|
* be used to populate a select box, or compare against
|
|
|
|
* input values. Starts by default at the current year,
|
|
|
|
* and counts back to 1900.
|
|
|
|
*
|
|
|
|
* @param int $start starting date to count down from
|
|
|
|
* @param int $end end date to count down to
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getDefaultOptions($start=false, $end=false) {
|
|
|
|
if (!$start) $start = (int)date('Y');
|
|
|
|
if (!$end) $end = 1900;
|
2008-05-14 07:54:11 +02:00
|
|
|
$years = array();
|
|
|
|
for($i=$start;$i>=$end;$i--) {
|
|
|
|
$years[] = $i;
|
|
|
|
}
|
|
|
|
return $years;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|