mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-19 16:06:32 +02:00
efef025027
BUG Fix incorrect method visibility on SS_Database BUG Fix obvious PHPDoc errors in SilverStripe\ORM\FieldType BUG Fix incorrect case on some method invocations API Remove some deprecated code
54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\ORM\FieldType;
|
|
|
|
use DropdownField;
|
|
use SilverStripe\ORM\DB;
|
|
|
|
/**
|
|
* @package framework
|
|
* @subpackage orm
|
|
*/
|
|
|
|
/**
|
|
* Represents a single year field.
|
|
*
|
|
* @package framework
|
|
* @subpackage orm
|
|
*/
|
|
class DBYear extends DBField {
|
|
|
|
public function requireField() {
|
|
$parts=Array('datatype'=>'year', 'precision'=>4, 'arrayValue'=>$this->arrayValue);
|
|
$values=Array('type'=>'year', 'parts'=>$parts);
|
|
DB::require_field($this->tableName, $this->name, $values);
|
|
}
|
|
|
|
public function scaffoldFormField($title = null, $params = 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|bool $start starting date to count down from
|
|
* @param int|bool $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] = $i;
|
|
}
|
|
return $years;
|
|
}
|
|
|
|
}
|