public final function get_table(moojon_base_model $accessor = null)
 {
     if (get_class($this) == 'moojon_has_many_to_many_relationship') {
         $return = $accessor->get_table() == $this->foreign_table ? $this->name : $this->foreign_table;
     } else {
         $return = $this->foreign_table;
     }
     return moojon_inflect::singularize($return);
 }
예제 #2
0
 public static function get_relationship_param_data_types(moojon_base_relationship $relationship, moojon_base_model $accessor)
 {
     switch (get_class($relationship)) {
         case 'moojon_has_one_relationship':
         case 'moojon_belongs_to_relationship':
             $foreign_key = $relationship->get_foreign_key();
             $column = $accessor->get_column($foreign_key);
             return array(":{$foreign_key}" => $column->get_data_type());
             break;
         case 'moojon_has_many_relationship':
         case 'moojon_has_many_to_many_relationship':
             $key = $relationship->get_key();
             $column = $accessor->get_column($key);
             return array(":{$key}" => $column->get_data_type());
             break;
     }
 }
예제 #3
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;
}
예제 #4
0
function rest_actions(moojon_base_model $model, moojon_rest_route $route = null, $action = null, $attributes = array())
{
    $action = $action ? $action : strtolower(ACTION);
    $route = $route ? $route : moojon_routes::get_rest_route($model->get_table());
    $actions = $route->get_actions();
    $lis = array();
    switch ($action) {
        case 'index':
            if (in_array('_new', $actions)) {
                $lis[] = li_tag(new_member_tag($model));
            }
            break;
        case '_new':
            if (in_array('index', $actions)) {
                $lis[] = li_tag(collection_tag($model));
            }
            break;
        case 'show':
            if (in_array('edit', $actions)) {
                $lis[] = li_tag(edit_member_tag($model));
            }
            if (in_array('delete', $actions)) {
                $lis[] = li_tag(delete_member_tag($model));
            }
            break;
        case 'edit':
            if (in_array('show', $actions)) {
                $lis[] = li_tag(member_tag($model));
            }
            if (in_array('delete', $actions)) {
                $lis[] = li_tag(delete_member_tag($model));
            }
            break;
        case 'delete':
            if (in_array('show', $actions)) {
                $lis[] = li_tag(member_tag($model));
            }
            if (in_array('edit', $actions)) {
                $lis[] = li_tag(edit_member_tag($model));
            }
            break;
        default:
            $lis = array();
            break;
    }
    return div_tag(ul_tag($lis), $attributes);
}
 public function remove(moojon_base_model $model)
 {
     for ($x = 0; $x < count($this) - 1; $x++) {
         $record = $this[$x];
         $same = true;
         foreach ($record->get_columns() as $column) {
             $column_name = $column->get_name();
             if ($record->{$column_name} != $model->{$column_name}) {
                 $same = false;
             }
         }
         if ($same) {
             array_splice($this, $x, 1);
             $x--;
             $model->delete();
             $model = null;
         }
     }
 }