From: Matthias Schmidt Date: Sat, 19 Apr 2014 18:34:11 +0000 (+0200) Subject: Add pagination for like details X-Git-Tag: 2.1.0_Alpha_1~878 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=32514cd558fea65c43787d25f41eec34b7b76001;p=GitHub%2FWoltLab%2FWCF.git Add pagination for like details --- diff --git a/wcfsetup/install/files/js/WCF.Like.js b/wcfsetup/install/files/js/WCF.Like.js index a87501dee8..9c3cacec31 100644 --- a/wcfsetup/install/files/js/WCF.Like.js +++ b/wcfsetup/install/files/js/WCF.Like.js @@ -42,17 +42,11 @@ WCF.Like = Class.extend({ _isBusy: false, /** - * cached template for like details + * cached grouped user lists for like details * @var object */ _likeDetails: { }, - /** - * dialog overlay for like details - * @var jQuery - */ - _likeDetailsDialog: null, - /** * proxy object * @var WCF.Action.Proxy @@ -61,6 +55,7 @@ WCF.Like = Class.extend({ /** * shows the detailed summary of users who liked the object + * @var boolean */ _showSummary: true, @@ -77,7 +72,6 @@ WCF.Like = Class.extend({ this._enableDislikes = enableDislikes; this._isBusy = false; this._likeDetails = { }; - this._likeDetailsDialog = null; this._showSummary = showSummary; this._allowForOwnContent = allowForOwnContent; @@ -248,30 +242,16 @@ WCF.Like = Class.extend({ var $containerID = (event === null) ? containerID : $(event.currentTarget).data('containerID'); if (this._likeDetails[$containerID] === undefined) { - this._proxy.setOption('data', { - actionName: 'getLikeDetails', - className: 'wcf\\data\\like\\LikeAction', - parameters: { - data: { - containerID: $containerID, - objectID: this._containerData[$containerID].objectID, - objectType: this._containerData[$containerID].objectType - } + this._likeDetails[$containerID] = new WCF.User.List('wcf\\data\\like\\LikeAction', WCF.Language.get('wcf.like.details'), { + data: { + containerID: $containerID, + objectID: this._containerData[$containerID].objectID, + objectType: this._containerData[$containerID].objectType } }); - this._proxy.sendRequest(); - } - else { - if (this._likeDetailsDialog === null) { - this._likeDetailsDialog = $('
' + this._likeDetails[$containerID] + '
').hide().appendTo(document.body); - this._likeDetailsDialog.wcfDialog({ - title: WCF.Language.get('wcf.like.details') - }); - } - else { - this._likeDetailsDialog.html(this._likeDetails[$containerID]).wcfDialog('open'); - } } + + this._likeDetails[$containerID].open(); }, /** @@ -360,11 +340,6 @@ WCF.Like = Class.extend({ this._isBusy = false; break; - - case 'getLikeDetails': - this._likeDetails[$containerID] = data.returnValues.template; - this._showLikeDetails(null, $containerID); - break; } }, diff --git a/wcfsetup/install/files/lib/data/like/LikeAction.class.php b/wcfsetup/install/files/lib/data/like/LikeAction.class.php index 59c929e8f6..0db4cc971c 100644 --- a/wcfsetup/install/files/lib/data/like/LikeAction.class.php +++ b/wcfsetup/install/files/lib/data/like/LikeAction.class.php @@ -1,6 +1,7 @@ validateObjectParameters(); + + $this->readInteger('pageNo'); + } + + /** + * @see \wcf\data\IGroupedUserListAction::getGroupedUserList() + */ + public function getGroupedUserList() { + // fetch number of pages + $sql = "SELECT COUNT(*) + FROM wcf".WCF_N."_like + WHERE objectID = ? + AND objectTypeID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $this->parameters['data']['objectID'], + $this->objectType->objectTypeID + )); + $pageCount = ceil($statement->fetchColumn() / 20); + + $sql = "SELECT userID, likeValue + FROM wcf".WCF_N."_like + WHERE objectID = ? + AND objectTypeID = ? + ORDER BY likeValue DESC, time DESC"; + $statement = WCF::getDB()->prepareStatement($sql, 20, ($this->parameters['pageNo'] - 1) * 20); + $statement->execute(array( + $this->parameters['data']['objectID'], + $this->objectType->objectTypeID + )); + $data = array( + Like::LIKE => array(), + Like::DISLIKE => array() + ); + while ($row = $statement->fetchArray()) { + $data[$row['likeValue']][] = $row['userID']; + } + + $values = array(); + if (!empty($data[Like::LIKE])) { + $values[Like::LIKE] = new GroupedUserList(WCF::getLanguage()->get('wcf.like.details.like')); + $values[Like::LIKE]->addUserIDs($data[Like::LIKE]); + } + if (!empty($data[Like::DISLIKE])) { + $values[Like::DISLIKE] = new GroupedUserList(WCF::getLanguage()->get('wcf.like.details.dislike')); + $values[Like::DISLIKE]->addUserIDs($data[Like::DISLIKE]); + } + + // load user profiles + GroupedUserList::loadUsers(); + + WCF::getTPL()->assign(array( + 'groupedUsers' => $values + )); + + return array( + 'containerID' => $this->parameters['data']['containerID'], + 'pageCount' => $pageCount, + 'template' => WCF::getTPL()->fetch('groupedUserList') + ); + } }