Example #1
0
 /**
  * Delete post
  * and delete all reply as well
  */
 public function ajaxDeleteReply($postId = null)
 {
     $djax = new Disjax();
     $my = JFactory::getUser();
     if (empty($postId)) {
         $options = new stdClass();
         $options->title = JText::_('COM_EASYDISCUSS_ERROR_DELETE_REPLY_TITLE');
         $options->content = JText::_('COM_EASYDISCUSS_MISSING_POST_ID');
         $buttons = array();
         $button = new stdClass();
         $button->title = JText::_('COM_EASYDISCUSS_OK');
         $button->action = 'disjax.closedlg();';
         $button->className = 'btn-primary';
         $buttons[] = $button;
         $options->buttons = $buttons;
         $djax->dialog($options);
         $djax->send();
         return;
     }
     // bind the table
     $postTable = DiscussHelper::getTable('Post');
     $postTable->load($postId);
     $isMine = DiscussHelper::isMine($postTable->user_id);
     $isAdmin = DiscussHelper::isSiteAdmin();
     if (!$isMine && !$isAdmin) {
         $options = new stdClass();
         $options->title = JText::_('COM_EASYDISCUSS_ERROR_DELETE_REPLY_TITLE');
         $options->content = JText::_('COM_EASYDISCUSS_NO_PERMISSION_TO_DELETE');
         $buttons = array();
         $button = new stdClass();
         $button->title = JText::_('COM_EASYDISCUSS_OK');
         $button->action = 'disjax.closedlg();';
         $button->className = 'btn-primary';
         $buttons[] = $button;
         $options->buttons = $buttons;
         $djax->dialog($options);
         $djax->send();
         return;
     }
     //chekc if the parent being locked. if yes, do not allow delete.
     $parentId = $postTable->parent_id;
     $parentTable = DiscussHelper::getTable('Post');
     $parentTable->load($parentId);
     if ($parentTable->islock) {
         $options = new stdClass();
         $options->title = JText::_('COM_EASYDISCUSS_ERROR_DELETE_REPLY_TITLE');
         $options->content = JText::_('COM_EASYDISCUSS_MAIN_POST_BEING_LOCKED');
         $buttons = array();
         $button = new stdClass();
         $button->title = JText::_('COM_EASYDISCUSS_OK');
         $button->action = 'disjax.closedlg();';
         $button->className = 'btn-primary';
         $buttons[] = $button;
         $options->buttons = $buttons;
         $djax->dialog($options);
         $djax->send();
         return;
     }
     // @trigger: onBeforeDelete
     DiscussEventsHelper::importPlugin('content');
     DiscussEventsHelper::onContentBeforeDelete('reply', $postTable);
     if (!$postTable->delete()) {
         $options = new stdClass();
         $options->title = JText::_('COM_EASYDISCUSS_ERROR_DELETE_REPLY_TITLE');
         $options->content = JText::_('COM_EASYDISCUSS_ERROR_DELETE_REPLY');
         $buttons = array();
         $button = new stdClass();
         $button->title = JText::_('COM_EASYDISCUSS_OK');
         $button->action = 'disjax.closedlg();';
         $button->className = 'btn-primary';
         $buttons[] = $button;
         $options->buttons = $buttons;
         $djax->dialog($options);
         $djax->send();
         return;
     } else {
         // @trigger: onAfterDelete
         DiscussEventsHelper::onContentAfterDelete('reply', $postTable);
         // @rule: Process AUP integrations
         DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_DELETE_REPLY, $postTable->user_id, $parentTable->title);
         DiscussHelper::getHelper('Points')->assign('easydiscuss.remove.reply', $my->id);
         $djax->script('EasyDiscuss.$("#dc_reply_' . +$postId . '").fadeOut(\'500\');');
         $djax->script('EasyDiscuss.$("#dc_reply_' . +$postId . '").remove();');
         $options = new stdClass();
         $options->title = JText::_('COM_EASYDISCUSS_SUCCESS_DELETE_REPLY_TITLE');
         $options->content = JText::_('COM_EASYDISCUSS_SUCCESS_DELETE_REPLY');
         $buttons = array();
         $button = new stdClass();
         $button->title = JText::_('COM_EASYDISCUSS_OK');
         $button->action = 'disjax.closedlg();';
         $button->className = 'btn-primary';
         $buttons[] = $button;
         $options->buttons = $buttons;
         $djax->dialog($options);
         $djax->send();
     }
     $djax->send();
     return;
 }
Example #2
0
 /**
  * Delete current post given the post id.
  * It will also delete all childs related to this entry.
  */
 public function delete()
 {
     JRequest::checkToken('request') or jexit('Invalid Token');
     $my = JFactory::getUser();
     $id = JRequest::getInt('id');
     $mainframe = JFactory::getApplication();
     $url = JRequest::getVar('url', '');
     $reply = DiscussHelper::getTable('Post');
     $reply->load($id);
     if (!$id) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_ENTRY_DELETE_MISSING_ID'), DISCUSS_QUEUE_ERROR);
         $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false));
         return;
     }
     $post = DiscussHelper::getTable('Post');
     $post->load($id);
     $acl = DiscussHelper::getHelper('ACL');
     $type = $post->parent_id ? 'reply' : 'question';
     $isMine = DiscussHelper::isMine($post->user_id);
     $isAdmin = DiscussHelper::isSiteAdmin();
     // @rule: Redirect to the parent's page
     if ($type == 'reply') {
         $url = DiscussRouter::_('index.php?option=com_easydiscuss&view=post&id=' . $post->parent_id, false);
     } else {
         $url = DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false);
     }
     $category = DiscussHelper::getTable('Category');
     $category->load($post->category_id);
     $access = $post->getAccess($category);
     if (!$access->canDelete()) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_ENTRY_DELETE_NO_PERMISSION'), DISCUSS_QUEUE_ERROR);
         $mainframe->redirect($url);
         return;
     }
     if ($post->islock && !$isAdmin) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_ENTRY_DELETE_LOCKED'), DISCUSS_QUEUE_ERROR);
         $mainframe->redirect($url);
         return;
     }
     // Delete all notification associated with this post
     $notificationModel = DiscussHelper::getModel('Notification');
     $notificationModel->deleteNotifications($id);
     // @trigger: onBeforeDelete
     DiscussEventsHelper::importPlugin('content');
     DiscussEventsHelper::onContentBeforeDelete('post', $post);
     if (!$post->delete()) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_ENTRY_DELETE_ERROR'), DISCUSS_QUEUE_ERROR);
         $mainframe->redirect($url);
         return;
     }
     DiscussHelper::getHelper('Points')->assign('easydiscuss.remove.discussion', $post->user_id);
     // @trigger: onAfterDelete
     DiscussEventsHelper::onContentAfterDelete('post', $post);
     // @rule: Process AUP integrations
     if (empty($post->parent_id)) {
         DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_DELETE_DISCUSSION, $post->user_id, $post->title);
     } else {
         DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_DELETE_REPLY, $post->user_id, $post->title);
     }
     if ($type == 'question') {
         $model = $this->getModel('Posts');
         $model->deleteAllReplies($id);
         // Delete custom fields
         $ruleModel = DiscussHelper::getModel('CustomFields');
         $ruleModel->deleteCustomFieldsValue($this->id, 'post');
         // Delete all favourite
         $favModel = DiscussHelper::getModel('Favourites');
         $favModel->deleteAllFavourites($id);
         $url = DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false);
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_ENTRY_DELETED'), DISCUSS_QUEUE_SUCCESS);
     } else {
         //this is a reply delete. now we check if this reply get accepted previously or not.
         // if yes, then upload the parent post to unresolved.
         $answerRemoved = false;
         if ($post->answered) {
             $parent = DiscussHelper::getTable('Post');
             $parent->load($post->parent_id);
             $parent->isresolve = DISCUSS_ENTRY_UNRESOLVED;
             $parent->store();
             $answerRemoved = true;
         }
         $ruleModel = DiscussHelper::getModel('CustomFields');
         $ruleModel->deleteCustomFieldsValue($this->id, 'post');
         $msgText = $answerRemoved ? JText::_('COM_EASYDISCUSS_REPLY_DELETED_AND_UNRESOLVED') : JText::_('COM_EASYDISCUSS_REPLY_DELETED');
         DiscussHelper::setMessageQueue($msgText, DISCUSS_QUEUE_SUCCESS);
     }
     $mainframe->redirect($url);
     return;
 }