Skip to content
This repository
Browse code

API: Deprecate EnumField::Lower() and EnumField::Upper() to LowerCase…

…() and UpperCase() for consistency with StringField
  • Loading branch information...
commit a38bfc577c5d3035577f2d4b585ba5bf7f2daf1e 1 parent 8d3d3a7
Will Rossiter authored July 18, 2012

Showing 1 changed file with 56 additions and 26 deletions. Show diff stats Hide diff stats

  1. 82  model/fieldtypes/Enum.php
82  model/fieldtypes/Enum.php
... ...
@@ -1,12 +1,13 @@
1 1
 <?php
2 2
 /**
3 3
  * Class Enum represents an enumeration of a set of strings.
  4
+ *
4 5
  * See {@link DropdownField} for a {@link FormField} to select enum values.
5 6
  * 
6 7
  * @package framework
7 8
  * @subpackage model
8 9
  */
9  
-class Enum extends DBField {
  10
+class Enum extends StringField {
10 11
 	
11 12
 	protected $enum, $default;
12 13
 	
@@ -15,22 +16,28 @@ class Enum extends DBField {
15 16
 	/**
16 17
 	 * Create a new Enum field.
17 18
 	 * 
18  
-	 * Example usage in {@link DataObject::$db} with comma-separated string notation ('Val1' is default)
  19
+	 * Example usage in {@link DataObject::$db} with comma-separated string 
  20
+	 * notation ('Val1' is default)
  21
+	 *
19 22
 	 * <code>
20 23
 	 *  "MyField" => "Enum('Val1, Val2, Val3', 'Val1')"
21 24
 	 * </code>
22 25
 	 * 
23  
-	 * Example usage in in {@link DataObject::$db} with array notation ('Val1' is default)
  26
+	 * Example usage in in {@link DataObject::$db} with array notation 
  27
+	 * ('Val1' is default)
  28
+	 *
24 29
 	 * <code>
25 30
 	 * "MyField" => "Enum(array('Val1', 'Val2', 'Val3'), 'Val1')"
26 31
 	 * </code>
27 32
 	 * 
28  
-	 * @param enum: A string containing a comma separated list of options or an array of Vals.
29  
-	 * @param default The default option, which is either NULL or one of the items in the enumeration.
  33
+	 * @param enum: A string containing a comma separated list of options or an 
  34
+	 *				array of Vals.
  35
+	 * @param string The default option, which is either NULL or one of the 
  36
+	 *				 items in the enumeration.
30 37
 	 */
31  
-	function __construct($name = null, $enum = NULL, $default = NULL) {
  38
+	public function __construct($name = null, $enum = NULL, $default = NULL) {
32 39
 		if($enum) {
33  
-			if(!is_array($enum)){
  40
+			if(!is_array($enum)) {
34 41
 				$enum = preg_split("/ *, */", trim($enum));
35 42
 			}
36 43
 
@@ -49,19 +56,38 @@ function __construct($name = null, $enum = NULL, $default = NULL) {
49 56
 				$this->default = reset($enum);
50 57
 			}
51 58
 		}
  59
+
52 60
 		parent::__construct($name);
53 61
 	}
54 62
 	
55  
-	function requireField(){
56  
-		$parts=Array('datatype'=>'enum', 'enums'=>Convert::raw2sql($this->enum), 'character set'=>'utf8', 'collate'=> 'utf8_general_ci', 'default'=>Convert::raw2sql($this->default), 'table'=>$this->tableName, 'arrayValue'=>$this->arrayValue);
57  
-		$values=Array('type'=>'enum', 'parts'=>$parts);
  63
+	/**
  64
+	 * @return void
  65
+	 */
  66
+	public function requireField() {
  67
+		$parts = array(
  68
+			'datatype' => 'enum', 
  69
+			'enums' => Convert::raw2sql($this->enum), 
  70
+			'character set' => 'utf8', 
  71
+			'collate' => 'utf8_general_ci', 
  72
+			'default' => Convert::raw2sql($this->default), 
  73
+			'table' => $this->tableName, 
  74
+			'arrayValue' => $this->arrayValue
  75
+		);
  76
+		
  77
+		$values = array(
  78
+			'type' => 'enum', 
  79
+			'parts' => $parts
  80
+		);
  81
+
58 82
 		DB::requireField($this->tableName, $this->name, $values);
59  
-}
  83
+	}
60 84
 	
61 85
 	/**
62  
-	 * Return a dropdown field suitable for editing this field 
  86
+	 * Return a dropdown field suitable for editing this field.
  87
+	 *
  88
+	 * @return DropdownField
63 89
 	 */
64  
-	function formField($title = null, $name = null, $hasEmpty = false, $value = "", $form = null, $emptyString = null) {
  90
+	public function formField($title = null, $name = null, $hasEmpty = false, $value = "", $form = null, $emptyString = null) {
65 91
 		if(!$title) $title = $this->name;
66 92
 		if(!$name) $name = $this->name;
67 93
 
@@ -71,28 +97,32 @@ function formField($title = null, $name = null, $hasEmpty = false, $value = "",
71 97
 		return $field;
72 98
 	}
73 99
 
  100
+	/**
  101
+	 * @return DropdownField
  102
+	 */
74 103
 	public function scaffoldFormField($title = null, $params = null) {
75 104
 		return $this->formField($title);
76 105
 	}
77 106
 
78  
-	function scaffoldSearchField($title = null) {
  107
+	/**
  108
+	 * @param string
  109
+	 *
  110
+	 * @return DropdownField
  111
+	 */
  112
+	public function scaffoldSearchField($title = null) {
79 113
 		$anyText = _t('Enum.ANY', 'Any');
80 114
 		return $this->formField($title, null, false, '', null, "($anyText)");
81 115
 	}
82 116
 	
83 117
 	/**
84  
-	 * Return the values of this enum, suitable for insertion into a dropdown field.
  118
+	 * Returns the values of this enum as an array, suitable for insertion into 
  119
+	 * a {@link DropdownField}
  120
+	 *
  121
+	 * @param boolean
  122
+	 *
  123
+	 * @return array
85 124
 	 */
86  
-	function enumValues($hasEmpty = false) {
  125
+	public function enumValues($hasEmpty = false) {
87 126
 		return ($hasEmpty) ? array_merge(array('' => ''), ArrayLib::valuekey($this->enum)) : ArrayLib::valuekey($this->enum);
88 127
 	}
89  
-	
90  
-	function Lower() {
91  
-		return StringField::LowerCase();
92  
-	}
93  
-	function Upper() {
94  
-		return StringField::UpperCase();
95  
-	}
96  
-}
97  
-
98  
-
  128
+}

0 notes on commit a38bfc5

Please sign in to comment.
Something went wrong with that request. Please try again.