Added separate tracking of disabled responses
authorAlexander Ebert <ebert@woltlab.com>
Wed, 8 Mar 2017 15:45:22 +0000 (16:45 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 8 Mar 2017 15:45:22 +0000 (16:45 +0100)
See #2219

com.woltlab.wcf/templates/commentList.tpl
wcfsetup/install/files/lib/data/comment/Comment.class.php
wcfsetup/install/files/lib/data/comment/CommentAction.class.php
wcfsetup/install/files/lib/data/comment/CommentEditor.class.php
wcfsetup/install/files/lib/data/comment/StructuredCommentList.class.php
wcfsetup/setup/db/install.sql

index 0b60da80d4d420fd1f393e1daf48f5a6c2aef634..9b4e6d19b50dd3ad2bc6c14723fddf28af0da85c 100644 (file)
@@ -54,7 +54,7 @@
                                </div>
                                
                                {if $comment|count}
-                                       <ul data-responses="{@$comment->responses}" class="containerList commentResponseList">
+                                       <ul data-responses="{if $commentCanModerate}{@$comment->unfilteredResponses}{else}{@$comment->responses}{/if}" class="containerList commentResponseList">
                                                {include file='commentResponseList' responseList=$comment}
                                        </ul>
                                {/if}
index 8a80c84ddf03cefa5f9dae2c4085dd8bd195d848..e10e212ad8b534b6bf25e540c5ed134937ac57ea 100644 (file)
@@ -24,6 +24,8 @@ use wcf\util\StringUtil;
  * @property-read      string          $message                comment message
  * @property-read      integer         $responses              number of responses on the comment
  * @property-read      string          $responseIDs            serialized array with the ids of the five latest comment responses
+ * @property-read      integer         $unfilteredResponses    number of all responses on the comment, including disabled ones
+ * @property-read      string          $unfilteredResponseIDs  serialized array with the ids of the five latest comment responses, including disabled ones
  * @property-read       integer         $enableHtml             is 1 if HTML will rendered in the comment, otherwise 0
  * @property-read      integer         $isDisabled             is 1 if the comment is disabled, otherwise 0
  */
@@ -48,6 +50,24 @@ class Comment extends DatabaseObject implements IMessage {
                return $responseIDs;
        }
        
+       /**
+        * Returns a list of unfiltered response ids, including those that are still disabled.
+        *
+        * @return      integer[]
+        */
+       public function getUnfilteredResponseIDs() {
+               if ($this->unfilteredResponseIDs === null || $this->unfilteredResponseIDs == '') {
+                       return [];
+               }
+               
+               $responseIDs = @unserialize($this->unfilteredResponseIDs);
+               if ($responseIDs === false) {
+                       return [];
+               }
+               
+               return $responseIDs;
+       } 
+       
        /**
         * @inheritDoc
         */
index 58914f7c2ca031c0f52f437cdef0a3c2c179af72..73f0a306f0bffcd5ad8c36999f2ee6b240d71cd3 100644 (file)
@@ -449,17 +449,17 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                $this->createdResponse->setComment($this->comment);
                
                // update response data
-               $responseIDs = $this->comment->getResponseIDs();
-               if (count($responseIDs) < 5) {
-                       $responseIDs[] = $this->createdResponse->responseID;
+               $unfilteredResponseIDs = $this->comment->getUnfilteredResponseIDs();
+               if (count($unfilteredResponseIDs) < 5) {
+                       $unfilteredResponseIDs[] = $this->createdResponse->responseID;
                }
-               $responses = $this->comment->responses + 1;
+               $unfilteredResponses = $this->comment->unfilteredResponses + 1;
                
                // update comment
                $commentEditor = new CommentEditor($this->comment);
                $commentEditor->update([
-                       'responseIDs' => serialize($responseIDs),
-                       'responses' => $responses
+                       'unfilteredResponseIDs' => serialize($unfilteredResponseIDs),
+                       'unfilteredResponses' => $unfilteredResponses
                ]);
                
                if (!$this->createdResponse->isDisabled) {
@@ -483,10 +483,15 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                        }
                }
                
+               $responses = $this->comment->responses;
+               if ($this->commentProcessor->canModerate($this->parameters['data']['objectTypeID'], $this->parameters['data']['objectID'])) {
+                       $responses = $this->comment->unfilteredResponses;
+               }
+               
                return [
                        'commentID' => $this->comment->commentID,
                        'template' => $this->renderResponse($this->createdResponse),
-                       'responses' => $responses
+                       'responses' => $responses + 1
                ];
        }
        
@@ -510,6 +515,13 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                foreach ($this->parameters['responses'] as $response) {
                        $comment = $response->getComment();
                        
+                       // update response count
+                       $commentEditor = new CommentEditor($comment);
+                       $commentEditor->updateCounters(['responses' => 1]);
+                       
+                       // do not prepend the response id as the approved response can appear anywhere
+                       $commentEditor->updateResponseIDs();
+                       
                        // update counter
                        $this->commentProcessor->updateCounter($comment->objectID, 1);
                        
index aba06a138e54eab90baa00bcb4ba9b394a931c39..98571a8637ae9eaa7dd1f68c680920ae042aa8ee 100644 (file)
@@ -28,11 +28,27 @@ class CommentEditor extends DatabaseObjectEditor {
                $sql = "SELECT          responseID
                        FROM            wcf".WCF_N."_comment_response
                        WHERE           commentID = ?
+                                       AND isDisabled = ?
                        ORDER BY        time ASC, responseID ASC";
                $statement = WCF::getDB()->prepareStatement($sql, 5);
-               $statement->execute([$this->commentID]);
+               $statement->execute([$this->commentID, 0]);
                $responseIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
                
                $this->update(['responseIDs' => serialize($responseIDs)]);
        }
+       
+       /**
+        * Updates response ids, including disabled ones.
+        */
+       public function updateUnfilteredResponseIDs() {
+               $sql = "SELECT          responseID
+                       FROM            wcf".WCF_N."_comment_response
+                       WHERE           commentID = ?
+                       ORDER BY        time ASC, responseID ASC";
+               $statement = WCF::getDB()->prepareStatement($sql, 5);
+               $statement->execute([$this->commentID]);
+               $responseIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
+               
+               $this->update(['unfilteredResponseIDs' => serialize($responseIDs)]);
+       }
 }
index f40515479b5878f183c87f3d616c8ee13ed371e8..d1a5036237581104b1717a85d65dfaf97f43baaa 100644 (file)
@@ -126,9 +126,19 @@ class StructuredCommentList extends CommentList {
                }
                
                // fetch last responses
-               if ( !empty($responseIDs)) {
+               if (!empty($responseIDs)) {
                        $responseList = new CommentResponseList();
-                       $responseList->setObjectIDs(array_keys($responseIDs));
+                       
+                       if ($this->commentManager->canModerate($this->objectTypeID, $this->objectID)) {
+                               $responseList->setObjectIDs(array_keys($responseIDs));
+                       }
+                       else {
+                               $responseList->getConditionBuilder()->add('comment_response.responseID IN (?)', [array_keys($responseIDs)]);
+                               
+                               if (WCF::getUser()->userID) $responseList->getConditionBuilder()->add('(comment_response.isDisabled = 0 OR comment_response.userID = ?)', [WCF::getUser()->userID]);
+                               else $responseList->getConditionBuilder()->add('comment_response.isDisabled = 0');
+                       }
+                       
                        $responseList->readObjects();
                        
                        foreach ($responseList as $response) {
index 65bef88bd74ef1e1ad663b595432bfbcb2b9b68c..500ebd39b733e4751fd607d84e04b18dc9344f72 100644 (file)
@@ -379,6 +379,8 @@ CREATE TABLE wcf1_comment (
        message TEXT NOT NULL,
        responses MEDIUMINT(7) NOT NULL DEFAULT '0',
        responseIDs VARCHAR(255) NOT NULL DEFAULT '',
+       unfilteredResponses MEDIUMINT(7) NOT NULL DEFAULT '0',
+       unfilteredResponseIDs VARCHAR(255) NOT NULL DEFAULT '',
        enableHtml TINYINT(1) NOT NULL DEFAULT 0,
        isDisabled TINYINT(1) NOT NULL DEFAULT 0,