mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-26 12:36:07 +02:00
API: Deprecate SS_Datetime. The DBField subclasses are have all been renamed to start with “DB” and be in the SilverStripe\Model\FieldType namespace. To keep DataObject definitions concise, the original short variations of their names are preserved as service definitions. Most of the field generation code doesn’t need to change, but where field classes are referenced directly, changes will be needed. SS_Datetime, which is commonly referenced outside the model system itself, has been preserved as a subclass of DBDatetime. This has been marked as deprecated and can be removed in SilverStripe 5. A few places that referred to $db and $casting values weren’t using the Injector to instantiate the relevant classes. This meant that the remapping we have created as part of moving classes into a namespace didn’t work.
54 lines
1.2 KiB
PHP
Executable File
54 lines
1.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace SilverStripe\Model\FieldType;
|
|
|
|
use DB;
|
|
use DropdownField;
|
|
|
|
/**
|
|
* @package framework
|
|
* @subpackage model
|
|
*/
|
|
|
|
/**
|
|
* Represents a single year field.
|
|
*
|
|
* @package framework
|
|
* @subpackage model
|
|
*/
|
|
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 $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] = $i;
|
|
}
|
|
return $years;
|
|
}
|
|
|
|
}
|