00001 <?php
00002
00003
00004
00005 if (!defined('APP_MULTISELECT_THRESHOLD')) define ('APP_MULTISELECT_THRESHOLD', 5);
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 class WidgetInput implements IWidget {
00044 public $name;
00045 public $label;
00046 public $type;
00047 public $value;
00048 public $params;
00049
00050
00051
00052
00053 const NO_BREAK = 128;
00054
00055
00056
00057 const WRAP_LABEL = 256;
00058
00059
00060
00061 const FORCE_CHECKBOXES = 512;
00062
00063
00064
00065 const FORCE_SELECT_BOX = 1024;
00066
00067
00068
00069 const NO_LABEL = 2048;
00070
00071
00072 const TEXT = 'text';
00073 const PASSWORD = 'password';
00074 const SELECT = 'select';
00075 const MULTISELECT = 'multiselect';
00076 const HIDDEN = 'hidden';
00077 const CHECKBOX = 'checkbox';
00078 const TEXTAREA = 'textarea';
00079 const SUBMIT = 'submit';
00080 const RADIO = 'radio';
00081 const FILE = 'file';
00082 const DATE = 'date';
00083
00084 public static function output($name, $label, $value = '', $type = self::TEXT, $params = array(), $policy = self::NONE) {
00085 $widget = new WidgetInput($name, $label, $value, $type, $params);
00086 return $widget->render($policy);
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096 public function __construct($name, $label, $value, $type, $params) {
00097 $this->name = $name;
00098 $this->label = $label;
00099 $this->type = $type;
00100 $this->value = is_array($value) ? Arr::get_item_recursive($value, $name, '') : $value;
00101 $this->params = Arr::force($params, false);
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 public function render($policy = self::NONE) {
00111 Load::classes_in_directory('view/widgets/input', array('base', $this->type), 'input.widget', true);
00112 $cls = 'InputWidget' . Load::filename_to_classname($this->type);
00113 if (class_exists($cls)) {
00114 $delegate = new $cls($this->name, $this->label, $this->value, $this->params);
00115 return $delegate->render($policy);
00116 }
00117 else {
00118 throw new Exception('input: unknown type "' . $this->type . '"');
00119 }
00120 }
00121 }