function relationship_tables(moojon_base_model $model, $relationships = array(), $column_names = array(), $attributes = array(), $no_records_messages = array(), $count = null) { if ($model->has_relationships()) { $relationships = $relationships ? $relationships : $model->get_relationships(); foreach ($relationships as $key => $value) { if (is_subclass_of($value, 'moojon_base_relationship')) { $relationships[$key] = $model->{$key}; } } $div = div_tag(); foreach ($relationships as $key => $value) { switch ($model->get_relationship_type($key)) { case 'moojon_has_many_relationship': case 'moojon_has_many_to_many_relationship': $div->add_child(h3_tag(title_text($key))); $relationship_model = $model->get_relationship_model($key); $div->add_child(actions_ul(array(new_member_tag($relationship_model)))); $div->add_child('<br /><br /><br />'); $child_column_names = array_key_exists($key, $column_names) ? $column_names[$key] : $relationship_model->get_ui_column_names(array(moojon_primary_key::get_foreign_key($model->get_table()))); $child_attributes = array_key_exists($key, $attributes) ? $attributes[$key] : array(); $child_no_records_message = array_key_exists($key, $no_records_messages) ? $no_records_messages[$key] : array(); $div->add_child(table_for($value, $child_column_names, $child_attributes, $child_no_records_message, $count)); break; } } return $div; } else { return null; } }
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); }