1 <?php
2
3 4 5 6
7
8 9 10 11 12
13 class MultiEnum extends Enum {
14 function __construct($name, $enum = NULL, $default = NULL) {
15
16 parent::__construct($name, $enum, null);
17
18
19 $this->default = null;
20 if($default) {
21 $defaults = preg_split('/ *, */',trim($default));
22 foreach($defaults as $thisDefault) {
23 if(!in_array($thisDefault, $this->enum)) {
24 user_error("Enum::__construct() The default value '$thisDefault' does not match "
25 . "any item in the enumeration", E_USER_ERROR);
26 return;
27 }
28 }
29 $this->default = implode(',',$defaults);
30 }
31 }
32
33 function requireField(){
34
35 $values=array('type'=>'set', 'parts'=>array('enums'=>$this->enum, 'character set'=>'utf8', 'collate'=> 'utf8_unicode_ci', 'default'=>Convert::raw2sql($this->default), 'table'=>$this->tableName, 'arrayValue'=>$this->arrayValue));
36 DB::requireField($this->tableName, $this->name, $values);
37
38 }
39
40
41 42 43
44 function formField($title = null, $name = null, $hasEmpty = false, $value = "", $form = null) {
45 if(!$title) $title = $this->name;
46 if(!$name) $name = $this->name;
47
48 $field = new CheckboxSetField($name, $title, $this->enumValues($hasEmpty), $value, $form);
49
50 return $field;
51 }
52 }
53
54 ?>
[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.
-