+++ /dev/null
-<nav class="tabMenu">
- <ul>
- {foreach from=$reactions item=reaction}
- <li data-reaction-type-id="{$reaction->reactionTypeID}"{if $reactionTypeID == $reaction->reactionTypeID} class="active ui-state-active"{/if}><a>{@$reaction->renderIcon()} {$reaction->getTitle()}</a></li>
- {/foreach}
- </ul>
-</nav>
-
-{if !$reactionUserList|empty}
- <ol class="containerList jsGroupedUserList section">
- {foreach from=$reactionUserList item=reaction}
- {assign var=user value=$reaction->getUserProfile()}
- {include file='userListItem'}
- {/foreach}
- </ol>
-
- <div class="paginationBottom jsPagination"></div>
-{else}
- <p class="info">{lang}wcf.reactions.summary.noReactions{/lang}</p>
-{/if}
-
-<script data-relocate="true">
- $(function() {
- WCF.Language.addObject({
- 'wcf.user.button.follow': '{lang}wcf.user.button.follow{/lang}',
- 'wcf.user.button.ignore': '{lang}wcf.user.button.ignore{/lang}',
- 'wcf.user.button.unfollow': '{lang}wcf.user.button.unfollow{/lang}',
- 'wcf.user.button.unignore': '{lang}wcf.user.button.unignore{/lang}'
- });
-
- new WCF.User.Action.Follow($('.jsGroupedUserList > li'));
- new WCF.User.Action.Ignore($('.jsGroupedUserList > li'));
- });
-</script>
\ No newline at end of file
}
this._containers = new Dictionary();
- this._details = new ObjectMap();
this._objectType = objectType;
- this._cache = new Dictionary();
this._options = Core.extend({
// selectors
}
},
- /**
- * Invalidates the cache for the object with the given objectId.
- *
- * @param {int} objectId
- */
- invalidateCache: function(objectId) {
- this._cache.delete(objectId);
- },
-
/**
* Update the count buttons with the given data.
*
if (triggerChange) {
DomChangeListener.trigger();
}
-
- this.invalidateCache(objectId);
},
/**
* @param {int} objectId
*/
_initReactionCountButton: function(element, objectId) {
- element.addEventListener(WCF_CLICK_EVENT, this._showReactionOverlay.bind(this, elData(element, 'reaction-type-id'), objectId));
+ element.addEventListener(WCF_CLICK_EVENT, this._showReactionOverlay.bind(this, objectId));
},
/**
- * Shows the reaction overly for a specific object and reaction type.
+ * Shows the reaction overly for a specific object.
*
- * @param {int} reactionTypeId
* @param {int} objectId
*/
- _showReactionOverlay: function(reactionTypeId, objectId) {
+ _showReactionOverlay: function(objectId) {
this._currentObjectId = objectId;
- this._currentPageNo = 1;
- this._currentReactionTypeId = reactionTypeId;
- this._showPage();
+ this._showOverlay();
},
/**
*
* @param {int} pageNo
*/
- _showPage: function(pageNo) {
- if (pageNo !== undefined) {
- this._currentPageNo = pageNo;
- }
+ _showOverlay: function() {
+ this._options.parameters.data.containerID = this._objectType + '-' + this._currentObjectId;
+ this._options.parameters.data.objectID = this._currentObjectId;
+ this._options.parameters.data.objectType = this._objectType;
- if (this._cache.has(this._currentObjectId) && this._cache.get(this._currentObjectId).has(this._currentReactionTypeId)) {
- // validate pageNo
- if (this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount') !== 0 && (this._currentPageNo < 1 || this._currentPageNo > this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount'))) {
- throw new RangeError("pageNo must be between 1 and " + this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount') + " (" + this._currentPageNo + " given).");
- }
- }
- else {
- // init objectId cache
- if (!this._cache.has(this._currentObjectId)) {
- this._cache.set(this._currentObjectId, new Dictionary());
- }
-
- // init reaction type id cache for objectId
- this._cache.get(this._currentObjectId).set(this._currentReactionTypeId, new Dictionary());
- }
-
- if (this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).has(this._currentPageNo)) {
- var dialog = UiDialog.open(this, this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get(this._currentPageNo));
- UiDialog.setTitle('userReactionOverlay-' + this._objectType, this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('title'));
-
- if (this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount') > 1) {
- var element = elBySel('.jsPagination', dialog.content);
- if (element !== null) {
- new UiPagination(element, {
- activePage: this._currentPageNo,
- maxPage: this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount'),
- callbackSwitch: this._showPage.bind(this)
- });
- }
- }
-
- // init tab menu
- var tabMenu = elBySel('.tabMenu ul', dialog.content);
- var elements = elBySelAll('li', tabMenu);
- for (var i = 0, length = elements.length; i < length; i++) {
- elements[i].addEventListener(WCF_CLICK_EVENT, this._showReactionOverlay.bind(this, elData(elements[i], 'reaction-type-id'), this._currentObjectId));
- }
- }
- else {
- this._options.parameters.pageNo = this._currentPageNo;
- this._options.parameters.reactionTypeID = this._currentReactionTypeId;
- this._options.parameters.data.containerID = this._currentReactionTypeId;
- this._options.parameters.data.objectID = this._currentObjectId;
- this._options.parameters.data.objectType = this._objectType;
-
- Ajax.api(this, {
- parameters: this._options.parameters
- });
- }
+ Ajax.api(this, {
+ parameters: this._options.parameters
+ });
},
_ajaxSuccess: function(data) {
- if (data.returnValues.pageCount !== undefined) {
- this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).set('pageCount', ~~data.returnValues.pageCount);
- }
-
- this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).set(this._currentPageNo, data.returnValues.template);
- this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).set('title', data.returnValues.title);
- this._showPage();
+ UiDialog.open(this, data.returnValues.template);
+ UiDialog.setTitle('userReactionOverlay-' + this._objectType, data.returnValues.title);
},
_ajaxSetup: function() {
use wcf\system\exception\UserInputException;
use wcf\system\reaction\ReactionHandler;
use wcf\system\user\activity\point\UserActivityPointHandler;
+use wcf\system\user\GroupedUserList;
use wcf\system\WCF;
/**
if (!WCF::getSession()->getPermission('user.like.canViewLike')) {
throw new PermissionDeniedException();
}
-
- $this->readInteger('reactionTypeID');
- $this->readInteger('pageNo');
-
- $this->reactionType = ReactionTypeCache::getInstance()->getReactionTypeByID($this->parameters['reactionTypeID']);
-
- if ($this->reactionType === null) {
- throw new IllegalLinkException();
- }
}
/**
$likeList = new ViewableLikeList();
$likeList->getConditionBuilder()->add('objectID = ?', [$this->parameters['data']['objectID']]);
$likeList->getConditionBuilder()->add('objectTypeID = ?', [$this->objectType->objectTypeID]);
- $likeList->getConditionBuilder()->add('reactionTypeID = ?', [$this->reactionType->reactionTypeID]);
- $likeList->sqlLimit = 25;
- $likeList->sqlOffset = ($this->parameters['pageNo'] - 1) * 10;
$likeList->sqlOrderBy = 'time DESC';
- $pageCount = ceil($likeList->countObjects() / 10);
$likeList->readObjects();
- WCF::getTPL()->assign([
- 'reactionUserList' => $likeList->getObjects(),
- 'reactions' => ReactionTypeCache::getInstance()->getEnabledReactionTypes(),
- 'reactionTypeID' => $this->reactionType->reactionTypeID
- ]);
+ $data = [];
+ foreach ($likeList as $item) {
+ if ($item->getReactionType()->isDisabled) continue;
+
+ // we cast the reactionTypeID to a string, so that we can sort the array
+ if (!isset($data[(string)$item->getReactionType()->reactionTypeID])) {
+ $data[(string)$item->getReactionType()->reactionTypeID] = new GroupedUserList($item->getReactionType()->getTitle());
+ }
+
+ $data[(string)$item->getReactionType()->reactionTypeID]->addUserIDs([$item->userID]);
+ }
+
+ GroupedUserList::loadUsers();
+
+ uksort($data, function ($a, $b) {
+ $sortOrderA = ReactionTypeCache::getInstance()->getReactionTypeByID($a)->showOrder;
+ $sortOrderB = ReactionTypeCache::getInstance()->getReactionTypeByID($b)->showOrder;
+
+ return ($sortOrderA < $sortOrderB) ? -1 : 1;
+
+ });
return [
- 'reactionTypeID' => $this->reactionType->reactionTypeID,
- 'pageNo' => $this->parameters['pageNo'],
- 'pageCount' => $pageCount,
- 'template' => WCF::getTPL()->fetch('reactionTabbedUserList'),
+ 'template' => WCF::getTPL()->fetch('groupedUserList', 'wcf', ['groupedUsers' => $data]),
'title' => WCF::getLanguage()->get('wcf.reactions.summary.title')
];
}