Example #1
0
 function ajaxReadmoreReplies($limitstart = null, $sorting = null, $type = 'questions', $parentId = null, $filter = null, $category = null)
 {
     $ajax = new Disjax();
     $model = $this->getModel('Posts');
     $limitstart = (int) $limitstart;
     $mainframe = JFactory::getApplication();
     $config = DiscussHelper::getConfig();
     $posts = $model->getReplies($parentId, $sorting, $limitstart);
     $pagination = $model->getPagination($parentId, $sorting);
     $my = JFactory::getUser();
     $posts = DiscussHelper::formatPost($posts);
     $parent = DiscussHelper::getTable('Post');
     $parent->load($parentId);
     //check all the 'can' or 'canot' here.
     $acl = DiscussHelper::getHelper('ACL');
     $isMainLocked = $parent->islock ? true : false;
     $canDelete = false;
     $canTag = false;
     $canReply = $acl->allowed('add_reply', '0');
     if ($config->get('main_allowdelete', 2) == 2) {
         $canDelete = $isSiteAdmin ? true : false;
     } else {
         if ($config->get('main_allowdelete', 2) == 1) {
             $canDelete = $acl->allowed('delete_reply', '0');
         }
     }
     $category = DiscussHelper::getTable('Category');
     $category->load($category);
     $posts = DiscussHelper::formatReplies($posts, $category);
     $template = new DiscussThemes();
     $template->set('replies', $posts);
     $template->set('config', $config);
     $template->set('canReply', $canReply);
     $template->set('canDelete', $canDelete);
     $template->set('isMainLocked', $isMainLocked);
     //$template->set( 'isMine'		, false );
     //$template->set( 'isAdmin'		, false );
     $template->set('isMine', DiscussHelper::isMine($parent->user_id));
     $template->set('isAdmin', DiscussHelper::isSiteAdmin());
     $html = $template->fetch('reply.item.php');
     $nextLimit = $limitstart + DiscussHelper::getListLimit();
     if ($nextLimit >= $pagination->total) {
         $ajax->remove('dc_pagination a');
     }
     $ajax->value('pagination-start', $nextLimit);
     $ajax->script('EasyDiscuss.$("#dc_response").children().children( ":last").addClass( "separator" );');
     $ajax->append('dc_response tbody', $html);
     $ajax->send();
 }
Example #2
0
    /**
     * Mark's a discussion as resolve.
     *
     * @since   3.0
     * @access  public
     *
     */
    public function resolve($id = null)
    {
        $ajax = new Disjax();
        $config = DiscussHelper::getConfig();
        if (!$id) {
            $ajax->assign('dc_main_notifications', JText::_('COM_EASYDISCUSS_SYSTEM_INVALID_ID'));
            $ajax->script('EasyDiscuss.$( "#dc_main_notifications" ).addClass( "alert alert-error" );');
            $ajax->send();
            return;
        }
        $post = DiscussHelper::getTable('Post');
        $post->load($id);
        $isMine = DiscussHelper::isMine($post->user_id);
        $isAdmin = DiscussHelper::isSiteAdmin();
        $isModerator = DiscussHelper::getHelper('Moderator')->isModerator($post->category_id);
        if (!$isMine && !$isAdmin) {
            if (!$isModerator) {
                $ajax->assign('dc_main_notifications', JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'));
                $ajax->script('EasyDiscuss.$( "#dc_main_notifications" ).addClass( "alert alert-error" );');
                $ajax->send();
                return;
            }
        }
        $post->isresolve = DISCUSS_ENTRY_RESOLVED;
        // When post is resolve state, other post status must remove
        $post->post_status = DISCUSS_POST_STATUS_OFF;
        if (!$post->store()) {
            $ajax->assign('dc_main_notifications', $post->getError());
            $ajax->script('EasyDiscuss.$( "#dc_main_notifications" ).addClass( "alert alert-error" );');
            $ajax->send();
            return;
        }
        $my = JFactory::getUser();
        // @rule: Badges only applicable when they resolve their own post.
        if ($post->get('user_id') == $my->id) {
            // Add logging for user.
            DiscussHelper::getHelper('History')->log('easydiscuss.resolved.discussion', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_RESOLVED_OWN_DISCUSSION', $post->title), $post->id);
            DiscussHelper::getHelper('Badges')->assign('easydiscuss.resolved.discussion', $my->id);
            DiscussHelper::getHelper('Points')->assign('easydiscuss.resolved.discussion', $my->id);
            // Assign badge for EasySocial
            DiscussHelper::getHelper('EasySocial')->assignBadge('resolve.reply', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_RESOLVED_OWN_DISCUSSION', $post->title));
        }
        // @rule: Add notifications for the thread starter
        $my = JFactory::getUser();
        if ($post->get('user_id') != $my->id && $config->get('main_notifications_resolved')) {
            $notification = DiscussHelper::getTable('Notifications');
            $notification->bind(array('title' => JText::sprintf('COM_EASYDISCUSS_RESOLVED_DISCUSSION_NOTIFICATION_TITLE', $post->title), 'cid' => $post->get('id'), 'type' => DISCUSS_NOTIFICATIONS_RESOLVED, 'target' => $post->get('user_id'), 'author' => $my->id, 'permalink' => 'index.php?option=com_easydiscuss&view=post&id=' . $post->get('id')));
            $notification->store();
        }
        // Add resolved button to the view.
        ob_start();
        ?>
        <a id="post_unresolve_link" href="javascript:void(0);" onclick="discuss.post.unresolve('<?php 
        echo $postId;
        ?>
');EasyDiscuss.$(this).parents('.discuss-status').hide();" class="resolved-button float-r">
            <?php 
        echo JText::_('COM_EASYDISCUSS_RESOLVED');
        ?>
        </a>
        <?php 
        $contents = ob_get_contents();
        ob_end_clean();
        $ajax->append('discuss-status', $contents);
        $ajax->assign('dc_main_notifications', JText::_('COM_EASYDISCUSS_ENTRY_RESOLVED'));
        $ajax->script('EasyDiscuss.$( "#dc_main_notifications" ).addClass( "alert alert-success" );');
        // Add Status
        $ajax->script('EasyDiscuss.$(".discussQuestion").addClass("is-resolved");');
        // For flatt theme
        $ajax->script('EasyDiscuss.$( ".discuss-action-bar" ).addClass("is-resolved");');
        // Remove other status
        $ajax->script('EasyDiscuss.$( ".postStatus" ).removeClass("label-post_status-on-hold");');
        $ajax->script('EasyDiscuss.$( ".postStatus").removeClass("label-post_status-accepted");');
        $ajax->script('EasyDiscuss.$( ".postStatus").removeClass("label-post_status-working-on");');
        $ajax->script('EasyDiscuss.$( ".postStatus").removeClass("label-post_status-reject");');
        $ajax->script('EasyDiscuss.$( ".postStatus").html("");');
        $ajax->send();
        return;
    }