1 <?php
2 3 4 5
6
7 8 9 10 11 12
13 class Year extends DBField {
14
15 function requireField() {
16 $parts=Array('datatype'=>'year', 'precision'=>4, 'arrayValue'=>$this->arrayValue);
17 $values=Array('type'=>'year', 'parts'=>$parts);
18 DB::requireField($this->tableName, $this->name, $values);
19 }
20
21 public function scaffoldFormField($title = null, $params = null) {
22 $selectBox = new DropdownField($this->name, $title);
23 $selectBox->setSource($this->getDefaultOptions());
24 return $selectBox;
25 }
26
27 28 29 30 31 32 33 34 35 36
37 private function getDefaultOptions($start=false, $end=false) {
38 if (!$start) $start = (int)date('Y');
39 if (!$end) $end = 1900;
40 $years = array();
41 for($i=$start;$i>=$end;$i--) {
42 $years[] = $i;
43 }
44 return $years;
45 }
46
47 }
48 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-