Exemplo n.º 1
0
 public static function get_relationship_object_where(moojon_base_relationship $relationship, moojon_base_model $accessor)
 {
     $key = $relationship->get_key();
     switch (get_class($relationship)) {
         case 'moojon_has_one_relationship':
             $foreign_table = $relationship->get_foreign_table();
             $foreign_key = $relationship->get_foreign_key();
             $return = "`{$foreign_table}`.`{$key}` = :{$foreign_key}";
             break;
         case 'moojon_has_many_relationship':
             $foreign_table = $relationship->get_foreign_table();
             $foreign_key = moojon_primary_key::get_foreign_key(get_class($accessor));
             $return = "`{$foreign_table}`.`{$foreign_key}` = :{$key}";
             break;
         case 'moojon_has_many_to_many_relationship':
             $foreign_table = moojon_inflect::pluralize($relationship->get_class($accessor));
             $foreign_key1 = moojon_primary_key::get_foreign_key($relationship->get_foreign_table());
             $foreign_key2 = moojon_primary_key::get_foreign_key(get_class($accessor));
             $return = "`{$key}` IN (SELECT `{$foreign_key1}` FROM `{$foreign_table}` WHERE `{$foreign_key2}` = :{$key})";
             break;
         case 'moojon_belongs_to_relationship':
             $foreign_key = moojon_primary_key::get_foreign_key(get_class($accessor));
             $return = "`{$key}` = :{$foreign_key}";
             break;
     }
     return $return;
 }
Exemplo n.º 2
0
function belongs_to_tag(moojon_model_collection $models = null, moojon_base_model $model, moojon_base_column $column, moojon_base_relationship $relationship, $attributes = array())
{
    $return = false;
    $name = $column->get_name();
    $attributes = try_set_name_and_id_attributes($attributes, $model, $column);
    $foreign_key = $relationship->get_foreign_key();
    $key = $relationship->get_key();
    $return = div_tag();
    if ($value = moojon_request::get_or_null($name)) {
        $return->add_child(redirection_tag(moojon_server::redirection()));
        if ($foreign_key_value = moojon_request::get_or_null($foreign_key)) {
            $value = $foreign_key_value;
        } else {
            if ($model->{$key} == $value) {
                $value = 0;
            }
        }
    } else {
        $value = 0;
    }
    $attributes['value'] = $value;
    $return->add_child(hidden_input_tag($attributes));
    return $return;
}