Add AbstractCommentListBoxController
authorMatthias Schmidt <gravatronics@live.com>
Sun, 4 Sep 2016 13:21:10 +0000 (15:21 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 4 Sep 2016 13:21:10 +0000 (15:21 +0200)
com.woltlab.wcf/templates/boxSidebarCommentList.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/system/box/AbstractCommentListBoxController.class.php [new file with mode: 0644]

diff --git a/com.woltlab.wcf/templates/boxSidebarCommentList.tpl b/com.woltlab.wcf/templates/boxSidebarCommentList.tpl
new file mode 100644 (file)
index 0000000..ab27408
--- /dev/null
@@ -0,0 +1,12 @@
+<ul class="sidebarItemList">
+       {foreach from=$boxCommentList item=boxComment}
+               <li>
+                       <div class="sidebarItemTitle">
+                               <h3><a href="{$boxComment->getLink()}">{$boxComment->title}</a></h3>
+                       </div>
+                       
+                       <p><small>{@$boxComment->message|newlineToBreak}</small></p>
+                       <p><small><a href="{link controller='User' object=$boxComment->getUserProfile()}{/link}" class="userLink" data-user-id="{@$boxComment->userID}">{$boxComment->username}</a> - {@$boxComment->time|time}</small></p>
+               </li>
+       {/foreach}
+</ul>
diff --git a/wcfsetup/install/files/lib/system/box/AbstractCommentListBoxController.class.php b/wcfsetup/install/files/lib/system/box/AbstractCommentListBoxController.class.php
new file mode 100644 (file)
index 0000000..676a99c
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+namespace wcf\system\box;
+use wcf\data\comment\ViewableCommentList;
+use wcf\data\object\type\ObjectType;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\exception\InvalidObjectTypeException;
+use wcf\system\WCF;
+
+/**
+ * Abstract box controller implementation for a list of comments for a certain type of objects.
+ *
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Box
+ * @since      3.0
+ */
+abstract class AbstractCommentListBoxController extends AbstractDatabaseObjectListBoxController {
+       /**
+        * @inheritDoc
+        */
+       public $defaultLimit = 5;
+       
+       /**
+        * name of the commentable object type the listed comments belong to
+        * @var string
+        */
+       protected $objectTypeName = '';
+       
+       /**
+        * commentable object type the listed comments belong to
+        * @var ObjectType
+        */
+       public $objectType;
+       
+       /**
+        * @inheritDoc
+        */
+       protected $sortFieldLanguageItemPrefix = 'wcf.comment.sortField';
+       
+       /**
+        * @inheritDoc
+        */
+       protected static $supportedPositions = [
+               'sidebarLeft',
+               'sidebarRight'
+       ];
+       
+       /**
+        * @inheritDoc
+        */
+       public $validSortFields = ['time'];
+       
+       /**
+        * @inheritDoc
+        */
+       public function __construct() {
+               $this->objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.comment.commentableContent', $this->objectTypeName);
+               if ($this->objectType === null) {
+                       throw new InvalidObjectTypeException($this->objectTypeName, 'com.woltlab.wcf.comment.commentableContent');
+               }
+               
+               if (!empty($this->validSortFields) && MODULE_LIKE) {
+                       $this->validSortFields[] = 'cumulativeLikes';
+               }
+               
+               parent::__construct();
+       }
+       
+       /**
+        * Applies object type-specific filters to the comments.
+        * 
+        * @param       ViewableCommentList     $commentList
+        */
+       abstract protected function applyObjectTypeFilters(ViewableCommentList $commentList);
+       
+       /**
+        * @inheritDoc
+        */
+       protected function getObjectList() {
+               $commentList = new ViewableCommentList();
+               $commentList->getConditionBuilder()->add('comment.objectTypeID = ?', [$this->objectType->objectTypeID]);
+               
+               $this->applyObjectTypeFilters($commentList);
+               
+               return $commentList;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       protected function getTemplate() {
+               return WCF::getTPL()->fetch('boxSidebarCommentList', 'wcf', [
+                       'boxCommentList' => $this->objectList,
+                       'boxSortField' => $this->sortField
+               ]);
+       }
+}