use wcf\data\like\LikeList;
use wcf\data\like\object\ILikeObject;
use wcf\data\like\object\LikeObject;
-use wcf\data\like\object\LikeObjectEditor;
+use wcf\data\like\object\LikeObjectAction;
use wcf\data\like\Like;
-use wcf\data\like\LikeEditor;
use wcf\data\like\object\LikeObjectList;
use wcf\data\object\type\ObjectType;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\reaction\object\IReactionObject;
+use wcf\data\reaction\ReactionAction;
use wcf\data\reaction\type\ReactionType;
use wcf\data\reaction\type\ReactionTypeCache;
use wcf\data\user\User;
/**
* Cache for likeable objects sorted by objectType.
- * @var ILikeObject[][]
+ * @var ILikeObject[][]
*/
private $likeableObjectsCache = [];
}
/**
- * Returns the JSON encoded JavaScript variable for the template.
- *
+ * Returns the JSON encoded JavaScript variable for the template.
+ *
* @return string
*/
public function getReactionsJSVariable() {
$reactions = ReactionTypeCache::getInstance()->getReactionTypes();
- $returnValues = [];
+ $returnValues = [];
foreach ($reactions as $reaction) {
$returnValues[$reaction->reactionTypeID] = [
- 'title' => $reaction->getTitle(),
- 'renderedIcon' => $reaction->renderIcon(),
- 'iconPath' => $reaction->getIconPath(),
- 'showOrder' => $reaction->showOrder,
- 'reactionTypeID' => $reaction->reactionTypeID,
+ 'title' => $reaction->getTitle(),
+ 'renderedIcon' => $reaction->renderIcon(),
+ 'iconPath' => $reaction->getIconPath(),
+ 'showOrder' => $reaction->showOrder,
+ 'reactionTypeID' => $reaction->reactionTypeID,
'isAssignable' => $reaction->isAssignable,
];
}
}
/**
- * Returns all enabled reaction types.
- *
+ * Returns all enabled reaction types.
+ *
* @return ReactionType[]
*/
public function getReactionTypes() {
}
/**
- * Returns a reaction type by id.
- *
+ * Returns a reaction type by id.
+ *
* @param integer $reactionID
* @return ReactionType|null
*/
}
/**
- * Builds the data attributes for the object container.
- *
+ * Builds the data attributes for the object container.
+ *
* @param string $objectTypeName
* @param integer $objectID
* @return string
}
/**
- * Cache likeable objects.
- *
+ * Cache likeable objects.
+ *
* @param string $objectTypeName
* @param integer[] $objectIDs
*/
}
foreach ($objects as $object) {
- $this->likeableObjectsCache[$objectTypeName][$object->getObjectID()] = $object;
+ $this->likeableObjectsCache[$objectTypeName][$object->getObjectID()] = $object;
}
}
/**
- * Get an likeable object from the internal cache.
- *
+ * Get an likeable object from the internal cache.
+ *
* @param string $objectTypeName
* @param integer $objectID
* @return ILikeObject
if (WCF::getUser()->userID) {
$sql = "SELECT like_object.*,
- COALESCE(like_table.reactionTypeID, 0) AS reactionTypeID,
+ COALESCE(like_table.reactionTypeID, 0) AS reactionTypeID,
COALESCE(like_table.likeValue, 0) AS liked
FROM wcf".WCF_N."_like_object like_object
LEFT JOIN wcf".WCF_N."_like like_table
}
/**
- * Add a reaction to an object.
- *
+ * Add a reaction to an object.
+ *
* @param ILikeObject $likeable
* @param User $user
* @param integer $reactionTypeID
if (!$like->likeID) {
// save like
- $like = LikeEditor::create([
+ $returnValues = (new ReactionAction([], 'create', ['data' => [
'objectID' => $likeable->getObjectID(),
'objectTypeID' => $likeable->getObjectType()->objectTypeID,
'objectUserID' => $likeable->getUserID() ?: null,
'userID' => $user->userID,
'time' => $time,
- 'likeValue' => 1,
+ 'likeValue' => 1,
'reactionTypeID' => $reactionTypeID
- ]);
+ ]]))->executeAction();
+
+ $like = $returnValues['returnValues'];
if ($likeable->getUserID()) {
UserActivityPointHandler::getInstance()->fireEvent('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $like->likeID, $likeable->getUserID());
}
}
else {
- $likeEditor = new LikeEditor($like);
- $likeEditor->update([
+ (new ReactionAction([$like], 'update', ['data' => [
'time' => $time,
'likeValue' => 1,
'reactionTypeID' => $reactionTypeID
- ]);
+ ]]))->executeAction();
if ($likeable->getUserID()) {
UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', [$likeable->getUserID() => 1]);
// This interface should help to determine whether the plugin has been adapted to the API 5.2.
// If a LikeableObject does not implement this interface, no notification will be sent, because
- // we assume, that the plugin has not been adapted to the new API.
+ // we assume, that the plugin has not been adapted to the new API.
if ($likeable instanceof IReactionObject) {
$likeable->sendNotification($like);
}
WCF::getDB()->commitTransaction();
return [
- 'cachedReactions' => $likeObjectData['cachedReactions'],
- 'reactionTypeID' => $reactionTypeID,
+ 'cachedReactions' => $likeObjectData['cachedReactions'],
+ 'reactionTypeID' => $reactionTypeID,
'like' => $like,
'likeObject' => $likeObjectData['likeObject'],
'cumulativeLikes' => $likeObjectData['cumulativeLikes']
}
return [
- 'cachedReactions' => [],
- ];
+ 'cachedReactions' => [],
+ ];
}
/**
- * Creates or updates a LikeObject for an likable object.
- *
+ * Creates or updates a LikeObject for an likable object.
+ *
* @param ILikeObject $likeable
* @param LikeObject $likeObject
* @param Like $like
];
// update data
- $likeObjectEditor = new LikeObjectEditor($likeObject);
- $likeObjectEditor->update($updateData);
+ (new LikeObjectAction([$likeObject], 'update', ['data' => $updateData]))->executeAction();
}
else {
$cumulativeLikes = 1;
];
// create cache
- $likeObject = LikeObjectEditor::create([
+ $likeObjectActionReturnValues = (new LikeObjectAction([], 'create', ['data' => [
'objectTypeID' => $likeable->getObjectType()->objectTypeID,
'objectID' => $likeable->getObjectID(),
'objectUserID' => $likeable->getUserID() ?: null,
'dislikes' => 0,
'cumulativeLikes' => $cumulativeLikes,
'cachedReactions' => serialize($cachedReactions),
- ]);
+ ]]))->executeAction();
+ $likeObject = $likeObjectActionReturnValues['returnValues'];
}
return [
- 'cumulativeLikes' => $cumulativeLikes,
- 'cachedReactions' => $cachedReactions,
+ 'cumulativeLikes' => $cumulativeLikes,
+ 'cachedReactions' => $cachedReactions,
'likeObject' => $likeObject,
- ];
+ ];
}
/**
- * Updates the like counter for a user.
+ * Updates the like counter for a user.
*
* @param ILikeObject $likeable
* @param LikeObject $likeObject
}
/**
- * Reverts a reaction for an object.
- *
+ * Reverts a reaction for an object.
+ *
* @param Like $like
* @param ILikeObject $likeable
* @param LikeObject $likeObject
// update owner's like counter
$this->updateUsersLikeCounter($likeable, $likeObject, $like, null);
- $likeEditor = new LikeEditor($like);
- $likeEditor->delete();
+ (new ReactionAction([$like], 'delete'))->executeAction();
if ($likeable->getUserID()) {
UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', [$likeable->getUserID() => 1]);
];
// update data
- $likeObjectEditor = new LikeObjectEditor($likeObject);
- $likeObjectEditor->update($updateData);
+ (new LikeObjectAction([$likeObject], 'update', ['data' => $updateData]))->executeAction();
}
return [
'cumulativeLikes' => $cumulativeLikes,
- 'cachedReactions' => $cachedReactions,
+ 'cachedReactions' => $cachedReactions,
'likeObject' => $likeObject
];
}
UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $likeData);
// delete likes
- LikeEditor::deleteAll(array_keys($likeData));
+ (new ReactionAction(array_keys($likeData), 'delete'))->executeAction();
}
// delete like objects
if (!empty($likeObjectIDs)) {
- LikeObjectEditor::deleteAll($likeObjectIDs);
+ (new LikeObjectAction([$likeObjectIDs], 'delete'))->executeAction();
}
// delete activity events
/**
* Returns the first available reaction type.
- *
+ *
* @return ReactionType|null
*/
public function getFirstReactionType() {
/**
* Returns the first available reaction type's id.
- *
+ *
* @return int|null
*/
public function getFirstReactionTypeID() {
}
/**
- * Removes deleted reactions from the reaction counter for the like object table.
- *
+ * Removes deleted reactions from the reaction counter for the like object table.
+ *
* @param array $cachedReactions
* @return array
*/