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; }
public function isInTopic(Model_Topic $topic) { return $this->topic == $topic->getId(); }
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; }