Exemplo n.º 1
0
 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;
 }