示例#1
0
 function input($tag, $content, $data, $attributes)
 {
     $name = $attributes["name"];
     $valueKey = $attributes["value"];
     //(array_key_exists("value",$attributes)) ? $data->get($attributes["value"]) : "";
     $value = TemplateLogic::content($valueKey, $data);
     $options = Options::parse($attributes["options"]);
     $validate = array_key_exists("validate", $attributes) ? $attributes["validate"] : false;
     if ($validate) {
         if (array_key_exists("class", $options)) {
             $options["class"] = "validate(" . $validate . ") " . $options["class"];
         } else {
             $options["class"] = "validate(" . $validate . ")";
         }
     }
     //$attributes["validate"];
     //var_dump($validate);
     switch ($tag) {
         case "check":
             $checked = array_key_exists("checked", $attributes) && $value == TemplateLogic::content($attributes["checked"], $data);
             $result = check_tag($name, $value, $checked, $options);
             break;
         case "text":
             $result = textarea_tag($name, $value, $options);
             break;
         case "file":
             $result = filefield_tag($name, $options);
             break;
         case "field":
             $result = textfield_tag($name, $value, $options);
             break;
         case "radio":
             $checked = array_key_exists("checked", $attributes) && $value == TemplateLogic::content($attributes["checked"], $data);
             $result = radio_tag($name, $value, $checked, $options);
             break;
         case "pass":
             $result = password_tag($name, $value, $options);
             break;
         case "option":
             $selected = $data->get("selected") == $value;
             $result = option_tag($name, $value, $selected);
             break;
         case "hidden":
             $result = hidden_tag($name, $value, $options);
             break;
     }
     return $result;
 }
示例#2
0
function control(moojon_base_model $model, $column_name, $attributes = array())
{
    $column = $model->get_column($column_name);
    $return = div_tag(label_tag(title_text($column_name) . ':', $column_name));
    $has_one_relationship = find_has_one_relationship($model, $column_name);
    $belongs_to_relationship = find_belongs_to_relationship($model, $column_name);
    if (!$has_one_relationship && !$belongs_to_relationship) {
        switch (get_class($column)) {
            case 'moojon_binary_column':
                $control = binary_tag($model, $column, $attributes);
                break;
            case 'moojon_boolean_column':
                $control = boolean_tag($model, $column, $attributes);
                break;
            case 'moojon_date_column':
                $control = date_tag($model, $column, $attributes);
                break;
            case 'moojon_datetime_column':
                $control = datetime_tag($model, $column, $attributes);
                break;
            case 'moojon_decimal_column':
                $control = decimal_tag($model, $column, $attributes);
                break;
            case 'moojon_float_column':
                $control = float_tag($model, $column, $attributes);
                break;
            case 'moojon_integer_column':
                $control = integer_tag($model, $column, $attributes);
                break;
            case 'moojon_primary_key':
                $control = primary_key_tag($model, $column, $attributes);
                break;
            case 'moojon_string_column':
                if ($column->is_password()) {
                    return password_tag($model, $column, $attributes);
                } else {
                    if ($column->is_file()) {
                        return file_tag($model, $column, $attributes);
                    } else {
                        $control = string_tag($model, $column, $attributes);
                    }
                }
                break;
            case 'moojon_text_column':
                $control = text_tag($model, $column, $attributes);
                break;
            case 'moojon_time_column':
                $control = time_tag($model, $column, $attributes);
                break;
            case 'moojon_timestamp_column':
                $control = timestamp_tag($model, $column, $attributes);
                break;
        }
    } else {
        if ($has_one_relationship) {
            $control = has_one_tag(null, $model, $column, $has_one_relationship, $attributes);
            if (get_class($control) != 'moojon_select_tag') {
                $return->clear_children();
            }
        } else {
            if ($belongs_to_relationship) {
                $control = belongs_to_tag(null, $model, $column, $belongs_to_relationship, $attributes);
                if (get_class($control) != 'moojon_select_tag') {
                    $return->clear_children();
                }
            }
        }
    }
    $return->add_child($control);
    return $return;
}