/** * delete topic and replies * * @return int|void */ public function destroy() { $condition = array('topic_id' => $this->tid); Model_Reply::delete($condition); parent::destroy(); }
public function action_view() { $user_id = $this->request->param('id'); if (empty($user_id)) { throw new Exception("User ID Must not be empty!"); } $user = new Model_User(); $view = View::factory('profile/view'); $topic = new Model_Topic(); $reply = new Model_Reply(); $view->replies = $reply->get_replies_by_user_id($user_id); $view->topics = $topic->get_topics_by_user_id($user_id); $view->user = $user->where('id', '=', $user_id)->find(); $this->template->content = $view->render(); }
public function action_new() { $this->check_login(); /* @var Model_User $cu */ $cu = $this->get_current_user(); if ($cu->submit < 1) { throw new Exception_Page(__('common.submit_before_topic')); } if ($this->request->is_post()) { $topic = new Model_Topic(); $topic->title = $this->get_post('title'); $topic->author_id = $cu->user_id; $topic->cid = intval($this->get_post('cid')); $topic->pid = intval($this->get_post('pid')); $topic->save(); $reply = new Model_Reply(); $reply->topic_id = $topic->tid; $reply->content = $this->get_raw_post('content'); $reply->author_id = $cu->user_id; $reply->save(); $this->redirect("/discuss/topic/{$topic->tid}"); } $this->view = 'discuss/edit'; $this->template_data['title'] = __('discuss.edit.new_topic'); }
public function action_edit_reply() { if (Auth::instance()->logged_in()) { $reply_id = $this->request->param('id'); $reply = new Model_Reply(); $view = View::factory('topic/edit_reply'); $view->replies = $reply->get_reply($reply_id); $this->template->content = $view->render(); if ($this->request->method() === Request::POST) { if (!Security::check($this->request->param('id2'))) { throw new Exception("Bad token!"); } $content = $this->request->post('content'); $topic_id = $this->request->post('topic_id'); //Topic id for last param from redirect. if (empty($content)) { throw new Exception("Content of your reply must not be empty!"); } $reply = new Model_Reply(); $reply_id = $this->request->param('id'); $update_reply = $reply->update($content, $reply_id); if (!$update_reply) { throw new Exception("Reply will not be updated"); } $this->redirect('topic/view/' . $topic_id); } } }