/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); $userIDs = array(); $likeGroups = array(); foreach ($this->objects as &$like) { $userIDs[] = $like->userID; $like = new ViewableLike($like); if (!isset($likeGroups[$like->objectTypeID])) { $objectType = ObjectTypeCache::getInstance()->getObjectType($like->objectTypeID); $likeGroups[$like->objectTypeID] = array('provider' => $objectType->getProcessor(), 'objects' => array()); } $likeGroups[$like->objectTypeID]['objects'][] = $like; } unset($like); // set user profiles if (!empty($userIDs)) { $userIDs = array_unique($userIDs); $users = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $like) { $like->setUserProfile($users[$like->userID]); } } // parse like foreach ($likeGroups as $likeData) { if ($likeData['provider'] instanceof IViewableLikeProvider) { $likeData['provider']->prepare($likeData['objects']); } } // validate permissions foreach ($this->objects as $index => $like) { if (!$like->isAccessible()) { unset($this->objects[$index]); } } $this->indexToObject = array_keys($this->objects); }
/** * Removes all likes for given objects. * * @param string $objectType * @param array<integer> $objectIDs * @param array<string> $notificationObjectTypes */ public function removeLikes($objectType, array $objectIDs, array $notificationObjectTypes = array()) { $objectTypeObj = $this->getObjectType($objectType); // get like objects $likeObjectList = new LikeObjectList(); $likeObjectList->getConditionBuilder()->add('like_object.objectTypeID = ?', array($objectTypeObj->objectTypeID)); $likeObjectList->getConditionBuilder()->add('like_object.objectID IN (?)', array($objectIDs)); $likeObjectList->readObjects(); $likeObjects = $likeObjectList->getObjects(); $likeObjectIDs = $likeObjectList->getObjectIDs(); // reduce count of received users $users = array(); foreach ($likeObjects as $likeObject) { if ($likeObject->likes) { if (!isset($users[$likeObject->objectUserID])) { $users[$likeObject->objectUserID] = 0; } $users[$likeObject->objectUserID] += $likeObject->likes; } } foreach ($users as $userID => $receivedLikes) { $userEditor = new UserEditor(new User(null, array('userID' => $userID))); $userEditor->updateCounters(array('likesReceived' => $receivedLikes * -1)); } // get like ids $likeList = new LikeList(); $likeList->getConditionBuilder()->add('like_table.objectTypeID = ?', array($objectTypeObj->objectTypeID)); $likeList->getConditionBuilder()->add('like_table.objectID IN (?)', array($objectIDs)); $likeList->readObjects(); if (count($likeList)) { $likeData = array(); foreach ($likeList as $like) { $likeData[$like->likeID] = $like->userID; } // delete like notifications if (!empty($notificationObjectTypes)) { foreach ($notificationObjectTypes as $notificationObjectType) { UserNotificationHandler::getInstance()->removeNotifications($notificationObjectType, $likeList->getObjectIDs()); } } else { if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType . '.notification')) { UserNotificationHandler::getInstance()->removeNotifications($objectType . '.notification', $likeList->getObjectIDs()); } } // revoke activity points UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $likeData); // delete likes LikeEditor::deleteAll(array_keys($likeData)); } // delete like objects if (!empty($likeObjectIDs)) { LikeObjectEditor::deleteAll($likeObjectIDs); } // delete activity events if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.recentActivityEvent')) { UserActivityEventHandler::getInstance()->removeEvents($objectTypeObj->objectType . '.recentActivityEvent', $objectIDs); } }