1 |
jonen |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* This file contains the base FEDataList class |
4 |
|
|
* |
5 |
jonen |
1.2 |
* $Id: FEDataList.inc,v 1.11 2003/07/16 01:04:37 hemna Exp $ |
6 |
jonen |
1.1 |
* |
7 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
8 |
|
|
* @author Suren Markosyan <suren@bcsweb.com> |
9 |
|
|
* @package phpHtmlLib |
10 |
|
|
* @subpackage FormProcessing |
11 |
|
|
* |
12 |
|
|
* @copyright LGPL - See LICENCE |
13 |
|
|
* |
14 |
|
|
*/ |
15 |
|
|
|
16 |
|
|
/** |
17 |
|
|
* This is the DataList FormElement which builds a |
18 |
|
|
* a complex FEBoxElement. It has no validation method. |
19 |
|
|
* |
20 |
|
|
* |
21 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
22 |
|
|
* @author Suren Markossian <suren@bcsweb.com> |
23 |
|
|
* @package phpHtmlLib |
24 |
|
|
* @subpackage FormProcessing |
25 |
|
|
* |
26 |
|
|
* @copyright LGPL - See LICENCE |
27 |
|
|
*/ |
28 |
|
|
class FEDataList extends FEBoxElement { |
29 |
|
|
|
30 |
|
|
/** |
31 |
|
|
* Holds the list of available |
32 |
|
|
* data elements |
33 |
|
|
* |
34 |
|
|
*/ |
35 |
|
|
var $_data_list = array(); |
36 |
|
|
|
37 |
|
|
/** |
38 |
|
|
* The constructor |
39 |
|
|
* |
40 |
|
|
* @param label string - text label for the element |
41 |
|
|
* @param bool required - is this a required element |
42 |
|
|
* @param array data_list - list of data elements (name=>value) |
43 |
|
|
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
44 |
|
|
*/ |
45 |
|
|
function FEDataList($label, $required = TRUE, $width = NULL, $height = NULL, $data_list = array()) { |
46 |
|
|
$this->FEBoxElement($label, $required, $width, $height); |
47 |
jonen |
1.2 |
$this->set_list_data( $data_list ); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* This function sets the array of data |
52 |
|
|
* to be used in the data list |
53 |
|
|
* |
54 |
|
|
* @param array data_list - list of data elements (name=>value) |
55 |
|
|
*/ |
56 |
|
|
function set_list_data( $data_list = array() ) { |
57 |
jonen |
1.1 |
$this->_data_list = $data_list; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/** |
62 |
|
|
* This provides a method |
63 |
|
|
* for the FormContent |
64 |
|
|
* to get access to the |
65 |
|
|
* text associated with a |
66 |
|
|
* field. This is only available |
67 |
|
|
* on FormElements that have text |
68 |
|
|
* associated with a field. |
69 |
|
|
* It is used during Confirmation |
70 |
|
|
* |
71 |
|
|
* @param mixed - the value to look up |
72 |
|
|
* @return string - the text associated |
73 |
|
|
*/ |
74 |
|
|
function get_value_text($value) { |
75 |
|
|
$flip = array_flip($this->_data_list); |
76 |
jonen |
1.2 |
if (array_key_exists($value, $flip)) { |
77 |
|
|
return $flip[$value]; |
78 |
|
|
} else { |
79 |
|
|
return NULL; |
80 |
|
|
} |
81 |
jonen |
1.1 |
} |
82 |
|
|
|
83 |
|
|
/** |
84 |
|
|
* |
85 |
|
|
* This function is responsible for performing complete |
86 |
|
|
* validation and setting the appropriate error message |
87 |
|
|
* in case of a failed validation |
88 |
|
|
* |
89 |
jonen |
1.2 |
* @param FormValidation object |
90 |
jonen |
1.1 |
*/ |
91 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
92 |
jonen |
1.1 |
// we make sure that the value is in the data list |
93 |
|
|
$values = $this->get_value(); |
94 |
|
|
if (is_array($values) ) { |
95 |
|
|
foreach( $values as $value ) { |
96 |
|
|
if (!in_array($value, $this->_data_list)) { |
97 |
|
|
$this->set_error_message("Invalid value"); |
98 |
|
|
return FALSE; |
99 |
|
|
} |
100 |
|
|
} |
101 |
|
|
} else { |
102 |
|
|
if (!in_array($values, $this->_data_list)) { |
103 |
|
|
$this->set_error_message("Invalid value"); |
104 |
|
|
return FALSE; |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
|
109 |
|
|
return TRUE; |
110 |
|
|
} |
111 |
|
|
} |
112 |
|
|
?> |