Ejemplo n.º 1
0
Archivo: Grid.php Proyecto: incube/mvc
 /** @param string $action_url
  * @param string $action_label
  * @param array $params
  * @param string $column_title */
 public function add_row_action($action_url, $action_label, array $params = array(), $column_title = "actions")
 {
     if (!in_array($column_title, $this->_columns)) {
         $this->_columns[] = $column_title;
     }
     foreach ($this->_data as $key => $data) {
         $temp = array_key_exists($column_title, $data) ? $this->_data[$key][$column_title] : "";
         $params_url = "";
         foreach ($params as $param) {
             $params_url[] = $param . DIRECTORY_SEPARATOR . $data[$param];
         }
         $this->_data[$key][$column_title] = $temp . ' ' . HTML::create_tag("a", array("href" => $action_url . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $params_url)), $action_label);
     }
 }
Ejemplo n.º 2
0
 /** Build Preconfigured html tag with validator and filters
  *
  * @param string $name
  * @param string|array $values
  *	@param string $type
  * @param string|array (for checkboxs) $default 
  * @return Incube_Element */
 public static function factory($name, $values, $options = array(), $default = array())
 {
     $options = (array) $options;
     $default = (array) $default;
     if (!array_key_exists('type', $options)) {
         if (is_bool($values)) {
             $type = "bool";
         } elseif (is_float($values)) {
             $type = "float";
         } elseif (is_numeric($values)) {
             $type = "int";
         } elseif (is_string($values)) {
             $type = "string";
         } elseif (is_array($values)) {
             $type = "select";
         } else {
             trigger_error("unidentified type of data, can't dynamically create this element", E_USER_ERROR);
         }
     } else {
         $type = $options['type'];
         unset($options['type']);
     }
     $label = null;
     $validators = array();
     $filters = array();
     switch ($type) {
         case "string":
             $tag = "input";
             $options2 = array("type" => "text", "value" => $values);
             $filters[] = new HTMLFilter();
             break;
         case "password":
             $tag = "input";
             $options2 = array("type" => "password");
             //$validator = new Incube_Validator_Regex();
             break;
         case "text":
             $tag = "textarea";
             $options2 = array("type" => "text", "style" => "width:100%; min-height:150px;");
             //$label = $values;
             $label = $values;
             $filters[] = new HTMLFilter();
             break;
         case "bool":
             $tag = "input";
             $options2 = array("type" => "checkbox", "value" => $values);
             $validator[] = new Incube_Validator_Number("bool");
             break;
         case "int":
             $tag = "input";
             $options2 = array("type" => "text", "value" => $values);
             $validators[] = new Incube_Validator_Number("int");
             break;
         case "float":
             $tag = "input";
             $options2 = array("type" => "text", "value" => $values);
             $validators[] = new Incube_Validator_Number("float");
             break;
         case "select":
             $tag = "option";
             foreach ($values as $key => $value) {
                 $tmp = in_array($value, $default) ? "{$tag} selected" : $tag;
                 $label .= HTML::create_tag($tag, array("value" => $key), $value);
             }
             $tag = "select";
             break;
         case "radio":
             $tag = "input";
             $options2 = array("value" => $values, "type" => "radio");
             break;
         case "checkbox":
             $tag = "input";
             $options2 = array("value" => $values, "type" => "checkbox");
             break;
         case "hidden":
             $tag = "input";
             $options2 = array("type" => "hidden", "value" => $values);
             break;
             //$validator = array(new Incube_Validator_TextField());
     }
     $options = array_merge($options, $options2);
     $options["name"] = "data[{$name}]";
     //TODO: add validators
     $element = new Element($tag, $options, $label);
     $element->set_validators($validators);
     $element->set_filters($filters);
     return $element;
 }