2 namespace wcf\system\user\activity\point;
3 use wcf\data\like\Like;
4 use wcf\data\object\type\ObjectType;
5 use wcf\system\database\util\PreparedStatementConditionBuilder;
9 * Updates events for received likes.
11 * @author Tim Duesterhus
12 * @copyright 2001-2013 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package com.woltlab.wcf
15 * @subpackage system.user.activity.point
16 * @category Community Framework
18 class ReceivedLikesUserActivityPointObjectProcessor extends AbstractUserActivityPointObjectProcessor {
20 * @see wcf\system\user\activity\point\IUserActivityPointObjectProcessor::countRequests();
22 public function countRequests() {
23 $sql = "SELECT COUNT(*)
24 FROM wcf".WCF_N."_like
26 $statement = WCF::getDB()->prepareStatement($sql);
27 $statement->execute(array(Like::LIKE));
29 return ceil($statement->fetchColumn() / $this->limit) + 1;
33 * @see wcf\system\user\activity\point\IUserActivityPointObjectProcessor::updateActivityPointEvents();
35 public function updateActivityPointEvents($request) {
38 $sql = "DELETE FROM wcf".WCF_N."_user_activity_point_event
39 WHERE objectTypeID = ?";
40 $statement = WCF::getDB()->prepareStatement($sql);
41 $statement->execute(array($this->objectTypeID));
45 FROM wcf".WCF_N."_like
48 $statement = WCF::getDB()->prepareStatement($sql, $this->limit, ($this->limit * ($request - 1)));
49 $statement->execute(array(Like::LIKE));
51 while ($row = $statement->fetchArray()) {
52 $likeIDs[] = $row['likeID'];
55 if (empty($likeIDs)) return;
57 $conditionBuilder = new PreparedStatementConditionBuilder();
58 $conditionBuilder->add("objectTypeID = ?", array($this->objectTypeID));
59 $conditionBuilder->add("objectID IN (?)", array($likeIDs));
61 // avoid problems with duplicate keys, as likes may be created in the meantime
62 $sql = "DELETE FROM wcf".WCF_N."_user_activity_point_event
64 $statement = WCF::getDB()->prepareStatement($sql);
65 $statement->execute($conditionBuilder->getParameters());
67 $conditionBuilder = new PreparedStatementConditionBuilder();
68 $conditionBuilder->add("likeID IN (?)", array($likeIDs));
70 // use INSERT ... SELECT as this makes bulk updating easier
71 $sql = "INSERT INTO wcf".WCF_N."_user_activity_point_event
72 (userID, objectTypeID, objectID, additionalData)
73 SELECT objectUserID AS userID,
77 FROM wcf".WCF_N."_like
79 $statement = WCF::getDB()->prepareStatement($sql);
80 $statement->execute(array_merge(array(
83 ), $conditionBuilder->getParameters()));