From 32514cd558fea65c43787d25f41eec34b7b76001 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 19 Apr 2014 20:34:11 +0200 Subject: [PATCH] Add pagination for like details --- wcfsetup/install/files/js/WCF.Like.js | 43 +++-------- .../files/lib/data/like/LikeAction.class.php | 72 ++++++++++++++++++- 2 files changed, 79 insertions(+), 36 deletions(-) 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') + ); + } } -- 2.20.1