예제 #1
0
    die;
    // todo more gracefull : do not display relation iframe iframe in edit when editing new record
}
$relation = new relation();
/*********** handle actions **********/
if ($url->get('action') == 'relate') {
    //echo 'I must relate';
    $target = $url->getObject('target_');
    $relation->relate($source, $target);
}
if ($url->get('action') == 'unrelate') {
    //echo 'I must relate';
    $target = $url->getObject('target_');
    $relation->unrelate($source, $target);
}
$relations = $relation->getRelations($source);
if ($relations) {
    foreach ($relations as $relation_object) {
        $relation_object->load();
        $item['title'] = te_short($relation_object->getTitle(), 50);
        $item['icon'] = $relation_object->getIcon();
        $url->set('action', 'unrelate');
        $url->addObject($relation_object, 'target_');
        $item['remove_url'] = $url->render();
        $out['relation']['data'][] = $item;
    }
}
$url = new url();
$url->set('mode', 'relation');
$out['browse_url'] = $url->render('browser.php');
debug($out, 'OUT');
<?php

require_once '../thinkedit.init.php';
require_once ROOT . '/class/relation.class.php';
$articles = $thinkedit->newRecord('article');
$authors = $thinkedit->newRecord('author');
// get first article
$article = $articles->findFirst();
// get first author
$author = $authors->findFirst();
$relation = new relation();
debug($article);
debug($author);
$relation->relate($article, $author);
//$relation->unRelate($article, $author);
$relations = $relation->getRelations($article);
foreach ($relations as $related_item) {
    $related_item->load();
    echo $related_item->getTitle();
}
echo $total_queries;