Ejemplo n.º 1
0
 static function AddRelated($relation, &$objects = array())
 {
     // set defaults
     switch ($relation) {
         case 'attached':
         case 'children':
         case 'parent':
             break;
         default:
             $relation = 'attached';
             break;
     }
     $get_related = "get_{$relation}";
     $find_related = "find_{$relation}";
     // get related
     foreach ($objects as $key => $object) {
         foreach ($object->{$get_related} as $related_name => $related_params) {
             AppModel::RelationNameParams($related_name, $related_params);
             // d($find_related.': '.$related_name.' '.print_r($related_params, true));
             $model = Globe::Init($related_name, 'model');
             $strForeignKey = array_get($related_params, 'foreignKey', null);
             // TODO hook in 'where' from behavior:
             $strWhere = null;
             $array = $relation == 'parent' ? array($related_name, $strForeignKey) : array($related_name, $strWhere, $model->order_by, 10000, 0, $strForeignKey);
             $objects[$key]->{$related_name} = call_user_func_array(array($object, $find_related), $array);
         }
     }
     return $objects;
 }
Ejemplo n.º 2
0
function smarty_function_admin_relations($params = array(), &$smarty)
{
    require_once $smarty->_get_plugin_filepath('function', 'admin_link');
    $relations = array('parent' => 'edit ', 'children' => 'add/edit ');
    $object = null;
    $wrap = false;
    $links = array();
    $output = '';
    foreach ($params as $_key => $_value) {
        ${$_key} = $_value;
    }
    if (empty($object)) {
        $smarty->trigger_error("admin_relations: missing 'object' parameter", E_USER_NOTICE);
        return;
    }
    // cycle relations
    foreach ($relations as $relation_name => $relation_prefix) {
        // cycle object's 'get_' variables
        $i = 0;
        foreach ($object->{'get_' . $relation_name} as $model_name => $model_params) {
            AppModel::RelationNameParams($model_name, $model_params);
            // get controller
            $controller = Globe::Init($model_name, 'controller');
            // TODO replace by ::singleton, find others
            // action & text
            switch ($relation_name) {
                case 'parent':
                    $action = ($model = object_get($object, $model_name)) ? 'edit' . DS . $model->id : null;
                    $text = ucwords(AppInflector::titleize($model_name));
                    $image = 'page_white_edit';
                    break;
                case 'children':
                    $prefix = $i == 0 ? '' : AppInflector::tableize(get_class($object)) . '_id=';
                    $action = '?filter=' . $prefix . $object->id;
                    $text = ucwords(AppInflector::pluralize(AppInflector::titleize($model_name)));
                    $image = 'magnifier';
                    break;
                default:
                    $action = '';
                    $text = AppInflector::titleize($model_name);
                    $image = 'magnifier';
                    break;
            }
            // build link
            $links[] = smarty_function_admin_link(array('controller' => AppInflector::fileize(get_class($controller), 'controller'), 'action' => $action, 'text' => "<span>{$relation_prefix}{$text}</span>" . ' <img src="/assets/images/admin/silk/' . $image . '.png" width="16" height="16">'), $smarty);
            $i++;
        }
    }
    foreach ($links as $link) {
        $output .= "<li>{$link}</li>\n";
    }
    if ($wrap) {
        $output = '<ul class="relations">' . $output . '</ul>';
    }
    return $output;
}
Ejemplo n.º 3
0
require_once ENDO_ROOT . 'configure.php';
require_once ENDO_ROOT . INCLUDES_DIR . 'initialize.php';
require_once APP_ROOT . INCLUDES_DIR . 'initialize.php';
// Sessions
session_start();
// --------------------------------------------------
// URL
// --------------------------------------------------
Url::Parse(array_get($_REQUEST, 'url'));
// --------------------------------------------------
// Controller
// --------------------------------------------------
$Controller = Globe::Init(Url::$data['controller'], 'controller');
if (get_class($Controller) == 'stdClass') {
    Error::Set("Create Controller '" . Url::$data['controllerName'] . "'!", 'fatal');
    $Controller = Globe::Init('missing', 'controller');
}
// --------------------------------------------------
// Action
// --------------------------------------------------
// go through filters
$Controller->call_beforeFilter();
$Controller->call(Url::$data['action'], Url::$data['params'], Url::$data['type']);
$Controller->call_beforeRender();
if (!Error::IsFatal()) {
    $Controller->render();
}
$Controller->call_afterRender();
$Controller->call_afterFilter();
// --------------------------------------------------
// Debug