silverstripe-framework/core/model/fieldtypes/Year.php
Ingo Schommer a24ccecb69 FEATURE Added ForeignKey and used it in relation- and databasefield getters in DataObject
FEATURE Added FormScaffolder for more flexible scaffolding of FieldSets from DataObject metadata
API CHANGE Removed DataObject->addScaffoldRelationFields(), now in separate class FormScaffolder
API CHANGE Changed parameters for DataObject->scaffoldSearchFields() to unify them with scaffoldFormFields()
API CHANGE Added optional $params parameter to DataObject->getCMSFields() to be passed on to scaffoldFormFields()
API CHANGE Renamed DataObject->getFormFields() to getFrontEndFields()
ENHANCEMENT Added $params parameter to all DBField->scaffoldFormField() subclasses
API CHANGE Added third optional parameter $object to DBField::create() to comply with ForeignKey and PrimaryKey constructors

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64157 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-10-13 22:20:41 +00:00

46 lines
1.0 KiB
PHP

<?php
/**
* @package sapphire
* @subpackage model
*/
/**
* 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, $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;
}
return $years;
}
}
?>