Ejemplo n.º 1
0
 public function flagAction()
 {
     // Set an empty layout for view
     $this->_helper->layout()->setLayout('empty');
     // Get requests
     $params = $this->getRequest()->getParams();
     $flaggedId = $params['flaggedid'];
     // Models for the job
     $auth = Zend_Auth::getInstance()->getIdentity();
     $userId = $auth->user_id;
     $flagmodel = new Default_Model_CommentFlags();
     $flagExists = $flagmodel->flagExists($flaggedId, $userId);
     $commentmodel = new Default_Model_Comments();
     $commentExists = $commentmodel->commentExists($flaggedId);
     if ($commentExists == true) {
         if ($flagExists == true) {
             $success = 0;
         } elseif ($flagExists == false) {
             $success = 1;
             $flagmodel->addFlag($flaggedId, $userId);
         }
     } elseif ($commentExists == false) {
         $success = 0;
     }
     $this->view->success = $success;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /**
  *   removeContent
  *   Removes specified content from the database and all related stuff
  *
  *   @param int id_cnt The id of content to be removed
  *   @return boolean array $contentRemoveChecker
  *   @author Mikko Korpinen
  */
 public function removeContentAndDepending($id_cnt = 0)
 {
     $contentRemoveChecker = array('removeContentFromCampaign' => true, 'removeContentFromContent' => true, 'removeContentFromFutureinfoClasses' => true, 'removeContentFromIndustries' => true, 'removeContentFromInnovationTypes' => true, 'removeContentFromRelatedCompanies' => true, 'removeContentRelatedCompanies' => true, 'removeContentFromTags' => true, 'removeContentTags' => true, 'removeContentFromUser' => true, 'removeContentViews' => true, 'removeContentFlags' => true, 'removeContentCommentFlags' => true, 'removeContentRatings' => true, 'removeContentFiles' => true, 'removeUserFromFavorites' => true, 'removeContent' => true, 'removeContentComments' => true);
     // cnt_has_cmp
     $cmpHasCnt = new Default_Model_CampaignHasContent();
     if (!$cmpHasCnt->removeContentCampaignLinks($id_cnt)) {
         $contentRemoveChecker['removeContentFromCampaign'] = false;
     }
     // cnt_has_cnt
     $cntHasCnt = new Default_Model_ContentHasContent();
     if (!$cntHasCnt->removeContentFromContents($id_cnt)) {
         $contentRemoveChecker['removeContentFromContent'] = false;
     }
     // cnt_has_fic
     /* not used
                 $cntHasFic = new Default_Model_ContentHasFutureinfoClasses();
                 if (!$cntHasFic->removeFutureinfoClassesFromContent($id_cnt))
                     $contentRemoveChecker['removeContentFromFutureinfoClasses'] = false;
     			*/
     // cnt_has_grp
     // Not used?
     // cnt_has_ind
     /* not used
        $cntHasInd = new Default_Model_ContentHasIndustries();
        if (!$cntHasInd->removeIndustriesFromContent($id_cnt))
            $contentRemoveChecker['removeContentFromIndustries'] = false;
        */
     // cnt_has_ivt
     /* not used
        $cntHasIvt = new Default_Model_ContentHasInnovationTypes();
        if (!$cntHasIvt->removeInnovationTypesFromContent($id_cnt))
            $contentRemoveChecker['removeContentFromInnovationTypes'] = false;
        */
     // related_companies_rec and cnt_has_rec
     $cntHasRec = new Default_Model_ContentHasRelatedCompany();
     $recs = $cntHasRec->getContentRelComps($id_cnt);
     $rec = new Default_Model_RelatedCompanies();
     foreach ($recs as $id_rec) {
         if (!$cntHasRec->checkIfOtherContentHasRelComp($id_rec['id_rec'], $id_cnt)) {
             if (!$rec->removeRelComp($id_rec['id_rec'])) {
                 $contentRemoveChecker['removeRelatedCompanies'] = false;
             }
         }
     }
     if (!$cntHasRec->removeContentRelComps($id_cnt)) {
         $contentRemoveChecker['removeContentFromRelatedCompanies'] = false;
     }
     // tags_tag and cnt_has_tag
     $cntHasTag = new Default_Model_ContentHasTag();
     $tags = $cntHasTag->getContentTags($id_cnt);
     $tag = new Default_Model_Tags();
     foreach ($tags as $id_tag) {
         if (!$cntHasTag->checkIfOtherContentHasTag($id_tag['id_tag'], $id_cnt)) {
             if (!$tag->removeTag($id_tag['id_tag'])) {
                 $contentRemoveChecker['removeTags'] = false;
             }
         }
     }
     if (!$cntHasTag->removeContentTags($id_cnt)) {
         $contentRemoveChecker['removeContentFromTags'] = false;
     }
     // cnt_has_usr
     $cntHasUsr = new Default_Model_ContentHasUser();
     if (!$cntHasUsr->removeUserFromContent($id_cnt)) {
         $contentRemoveChecker['removeContentFromUser'] = false;
     }
     // cnt_publish_times_pbt
     // Not used?
     // cnt_views_vws
     $cntWiewsVws = new Default_Model_ContentViews();
     if (!$cntWiewsVws->removeContentViews($id_cnt)) {
         $contentRemoveChecker['removeContentViews'] = false;
     }
     // Flags from content_flags_cfl
     $contentflagmodel = new Default_Model_ContentFlags();
     $cnfl_ids = $contentflagmodel->getFlagsByContentId($id_cnt);
     if (is_array($cnfl_ids)) {
         foreach ($cnfl_ids as $cfl_id) {
             if (!$contentflagmodel->removeFlag($cfl_id)) {
                 $contentRemoveChecker['removeContentFlags'] = false;
             }
         }
     }
     // Flags from comment_flags_cfl
     $commentflagmodel = new Default_Model_CommentFlags();
     $cmfl_ids = $commentflagmodel->getFlagsByContentId($id_cnt);
     if (is_array($cmfl_ids)) {
         foreach ($cmfl_ids as $cfl_id) {
             if (!$commentflagmodel->removeFlag($cfl_id)) {
                 $contentRemoveChecker['removeContentCommentFlags'] = false;
             }
         }
     }
     // content_ratings_crt
     $contentRatingRct = new Default_Model_ContentRatings();
     if (!$contentRatingRct->removeContentRatings($id_cnt)) {
         $contentRemoveChecker['removeContentRatings'] = false;
     }
     // files_fil
     $files = new Default_Model_Files();
     if (!$files->removeFiles($id_cnt, "content")) {
         $contentRemoveChecker['removeContentFiles'] = false;
     }
     // links_lnk
     // Not used?
     // usr_has_fvr
     $usrHasFvr = new Default_Model_UserHasFavourites();
     if (!$usrHasFvr->removeAllContentFromFavouritesByContentId($id_cnt)) {
         $contentRemoveChecker['removeUserFromFavorites'] = false;
     }
     // contents_cnt
     $contentmodel = new Default_Model_Content();
     if (!$contentmodel->removeContent($id_cnt)) {
         $contentRemoveChecker['removeContent'] = false;
     }
     // coments_cmt
     $commentmodel = new Default_Model_Comments();
     if (!$commentmodel->removeAllContentComments($id_cnt)) {
         $contentRemoveChecker['removeContentComments'] = false;
     }
     return $contentRemoveChecker;
 }
Ejemplo n.º 4
0
 /**
  * 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);
     }
 }