_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
/**
* shows the detailed summary of users who liked the object
+ * @var boolean
*/
_showSummary: true,
this._enableDislikes = enableDislikes;
this._isBusy = false;
this._likeDetails = { };
- this._likeDetailsDialog = null;
this._showSummary = showSummary;
this._allowForOwnContent = allowForOwnContent;
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 = $('<div>' + this._likeDetails[$containerID] + '</div>').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();
},
/**
this._isBusy = false;
break;
-
- case 'getLikeDetails':
- this._likeDetails[$containerID] = data.returnValues.template;
- this._showLikeDetails(null, $containerID);
- break;
}
},
<?php
namespace wcf\data\like;
use wcf\data\AbstractDatabaseObjectAction;
+use wcf\data\IGroupedUserListAction;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\UserInputException;
use wcf\system\like\LikeHandler;
* @subpackage data.like
* @category Community Framework
*/
-class LikeAction extends AbstractDatabaseObjectAction {
+class LikeAction extends AbstractDatabaseObjectAction implements IGroupedUserListAction {
/**
* @see \wcf\data\AbstractDatabaseObjectAction::$allowGuestAccess
*/
- protected $allowGuestAccess = array('getLikeDetails');
+ protected $allowGuestAccess = array('getGroupedUserList', 'getLikeDetails');
/**
* @see \wcf\data\AbstractDatabaseObjectAction::$className
throw new PermissionDeniedException();
}
}
+
+ /**
+ * @see \wcf\data\IGroupedUserListAction::validateGetGroupedUserList()
+ */
+ public function validateGetGroupedUserList() {
+ $this->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')
+ );
+ }
}