/** * Delete a post in a thread * * @return void */ public function deletePostAction() { /** * @var $request Zend_Controller_Request_Http */ $request = $this->getRequest(); $pid = intval($request->getParam('pid')); // Get post info $modelPosts = new Forum_Model_DbTable_Post(); $post = $modelPosts->find($pid)->current(); if (!$post) { throw new Zend_Controller_Action_Exception(sprintf("Unable to delete post: Post with ID '%d' not found", $pid), 500); } // Getting thread info $tid = $post['pid']; // TODO get these data from a cache $threadModel = new Forum_Model_DbTable_Thread(); $thread = $threadModel->find($tid)->current(); if (!$thread) { throw new Zend_Controller_Action_Exception(sprintf("Unable to delete post: Parent thread with ID '%d' was not found", $tid), 500); } // Forward to deleteThreadAction if post to delete is the firstpost in the thread if ($thread['firstpost_id'] == $pid) { $this->_forward('delete.thread', null, null, array('tid' => $tid)); } else { // Get forum info $fid = $post['fid']; $forumModel = new Forum_Model_DbTable_Forum(); $forum = $forumModel->find($fid)->current(); if (!$forum) { throw new Zend_Controller_Action_Exception(sprintf("Unable to delete post: Parent forum with ID '%d' was not found", $tid), 500); } // TODO permissions checking (only admin, moderator and owner can delete post // TODO post cannot be delete if thread is closed and user is not moderator that can delete post in the parent forum // TODO post cannot be deleted if post deletion is not allowed in the parent forum // TODO forward to deleteThreadAction if post to delete is the firstpost in the thread OK // TODO Forum posts counter must be updated // TODO Forum lastpost_date, lastposter_username, lastposter_id must be checked and updated if needed // TODO Thread lastpost_date, lastposter_username, lastposter_id must be checked and updated if needed // TODO Thread replies counter must be updated // TODO User(s) posts counter must be updated } }
/** * Deletes a forum and all its threads * * @return void */ public function deleteAction() { /** * @var $request Zend_Controller_Request_Http */ $request = $this->getRequest(); $fid = intval($request->getParam('fid')); $model = new Forum_Model_DbTable_Forum(); $forum = $model->find($fid)->current(); if ($forum) { $forum->delete(); } $this->_redirect($this->urlHelper->url(array(), 'forum_index')); }