public function commentflagsAction() { // Get all POST-parameters $posts = $this->_request->getPost(); // Get models for the job $flagmodel = new Default_Model_CommentFlags(); $commentmodel = new Default_Model_Comments(); $contentmodel = new Default_Model_Content(); if ($posts) { // Remove comment text ("Comment removed"-text) if ($posts['rm'] == "comment") { foreach ($posts as $key => $post) { if ($key != "rm" && $key != "selectall") { // Flags from comment_flags_cfl $cmf_ids = $flagmodel->getFlagsByCommentId($key); foreach ($cmf_ids as $cmf_id) { $flagmodel->removeFlag($cmf_id); } // Text from comments_cmt $commentmodel->removeCommentText($key); } } } // Remove flags if ($posts['rm'] == "flag") { foreach ($posts as $key => $post) { if ($key != "rm" && $key != "selectall") { // Flags from comment_flags_cfl $cmf_ids = $flagmodel->getFlagsByCommentId($key); foreach ($cmf_ids as $cmf_id) { $flagmodel->removeFlag($cmf_id); } } } } } $flagItems = $flagmodel->getAllFlags(); // Awesome algorithm for counting how many flags each flagged comment has $tmpCount = array(); foreach ($flagItems as $flagItem) { $tmpCount[$flagItem['id_comment_cmf']]++; } arsort($tmpCount); $data = array(); $count = 0; // Loop and re-arrange our variables foreach ($tmpCount as $cmt_id => $cmt_count) { $comment = $commentmodel->getById($cmt_id); $comment = $comment['Data']['body_cmt']; $content_id = $commentmodel->getContentIdsByCommentId($cmt_id); $content_id = $content_id[0]['id_cnt_cmt']; $content_url = $this->_urlHelper->url(array('controller' => 'view', 'action' => $content_id, 'language' => $this->view->language), 'lang_default', true); $data[$count]['cnt_id'] = $content_id; $data[$count]['cnt_title'] = $contentmodel->getContentHeaderByContentId($content_id); $data[$count]['cnt_url'] = $content_url; $data[$count]['cmt_id'] = $cmt_id; $data[$count]['cmt_body'] = $comment; $data[$count]['cmt_count'] = $cmt_count; $count++; } // Go! $this->view->comments = $data; }
/** * removeAction - Remove specified comment by content owner or comment owner * * @author Mikko Korpinen */ public function removeAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { // Get requests $params = $this->getRequest()->getParams(); $cmtid = $params['cmtid']; $cntid = $params['cntid']; $usrid = $auth->getIdentity()->user_id; $cntHasUsrModel = new Default_Model_ContentHasUser(); $user_is_content_owner = $cntHasUsrModel->contentHasOwner($usrid, $cntid); $commentmodel = new Default_Model_Comments(); $user_is_comment_owner = $commentmodel->userIsOwner($usrid, $cmtid); if ($user_is_content_owner || $user_is_comment_owner) { $flagmodel = new Default_Model_CommentFlags(); $flags = $flagmodel->getFlagsByCommentId($cmtid); $commentExists = $commentmodel->commentExists($cmtid); if ($commentExists) { if (count($flags) > 0) { $flagmodel->removeFlagsByCommentId($cmtid); } $commentmodel->removeCommentText($cmtid); } } $redirectUrl = $this->_urlHelper->url(array('content_id' => $cntid, 'language' => $this->view->language), 'content_shortview', true); $this->_redirector->gotoUrl($redirectUrl); } else { $redirectUrl = $this->_urlHelper->url(array('language' => $this->view->language), 'index', true); $this->_redirector->gotoUrl($redirectUrl); } }