Esempio n. 1
0
File: Topic.php Progetto: kstep/pnut
 public function actionReorder($params)
 {
     $view = $this->ajaxView();
     $view->state = 'failed';
     if ($params['id'] && $params['targid']) {
         $otopic = new Model_Topic($this->getStorage(), $params['id']);
         $ttopic = new Model_Topic($this->getStorage(), $params['targid']);
         $view->id = $otopic->getId();
         $view->target_id = $ttopic->getId();
         $view->parent_id = $otopic->parent;
         if ($otopic->isLoaded() && $ttopic->isLoaded()) {
             $this->canPerform($otopic, 'edit');
             $view->state = 'reordered';
             $view->place = $params['place'];
             switch ($params['place']) {
                 case 'before':
                     $method = 'insertBefore';
                     break;
                 case 'after':
                     $method = 'insertAfter';
                     break;
                 default:
                     if ($otopic->isBefore($ttopic)) {
                         $method = 'insertAfter';
                         $view->place = 'after';
                     } else {
                         $method = 'insertBefore';
                         $view->place = 'before';
                     }
             }
             try {
                 $otopic->{$method}($ttopic);
             } catch (Exception $e) {
                 $view->state = 'failed';
                 $view->error = $e->getMessage();
             }
         } else {
             $view->error = 'Topic(s) not found.';
         }
     } else {
         $view->error = 'Topic IDs are not set.';
     }
     return $view;
 }
Esempio n. 2
0
 public function isInTopic(Model_Topic $topic)
 {
     return $this->topic == $topic->getId();
 }
Esempio n. 3
0
 public function actionMove($params)
 {
     $view = $this->ajaxView('article');
     $view->state = "failed";
     if ($params["id"] && $params["targid"]) {
         $article = new Model_Article($this->getStorage(), $params["id"]);
         $topic = new Model_Topic($this->getStorage(), $params["targid"]);
         $view->id = $article->getId();
         $view->topic_id = $topic->getId();
         if ($view->id && $view->topic_id) {
             if ($article->topic != $topic->getId()) {
                 $this->canPerform($article, "edit");
                 $this->canPerform($topic, "edit");
                 $view->state = "moved";
                 $article->topic = $topic->getId();
                 try {
                     $article->save();
                 } catch (Exception $e) {
                     $view->state = "failed";
                     $view->error = $e->getMessage();
                 }
             } else {
                 $view->state = "notmoved";
             }
         } else {
             $view->error = "Article or topic not found.";
         }
     } else {
         $view->error = "Article or topic ID is not set.";
     }
     return $view;
 }