mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-18 07:26:40 +02:00
41 lines
960 B
PHP
41 lines
960 B
PHP
|
<?php
|
||
|
/**
|
||
|
* Represents a single year field.
|
||
|
*
|
||
|
* @package sapphire
|
||
|
* @subpackage model
|
||
|
*/
|
||
|
class Year extends DBField {
|
||
|
|
||
|
function requireField() {
|
||
|
DB::requireField($this->tableName, $this->name, "year(4)");
|
||
|
}
|
||
|
|
||
|
public function scaffoldFormField($title = null) {
|
||
|
$selectBox = new DropdownField($this->name, $title);
|
||
|
$selectBox->setSource($this->getDefaultOptions());
|
||
|
return $selectBox;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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;
|
||
|
$years = array();
|
||
|
for($i=$start;$i>=$end;$i--) {
|
||
|
$years[] = $i;
|
||
|
}
|
||
|
return $years;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
?>
|