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;
6 use wcf\system\user\activity\point\IUserActivityPointObjectProcessor;
10 * Updates events for received likes.
12 * @author Tim Duesterhus
13 * @copyright 2001-2013 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf.like
16 * @subpackage system.user.activity.point
17 * @category Community Framework
19 class ReceivedLikesUserActivityPointObjectProcessor implements IUserActivityPointObjectProcessor {
21 public $objectType = null;
24 * Creates a new instance of ReceivedLikesUserActivityPointObjectProcessor.
26 * @param wcf\data\object\type\ObjectType $objectType
28 public function __construct(ObjectType $objectType) {
29 $this->objectType = $objectType;
33 * @see wcf\system\user\activity\point\IUserActivityPointObject::countRequests();
35 public function countRequests() {
36 $sql = "SELECT COUNT(*) AS count
37 FROM wcf".WCF_N."_like
39 $statement = WCF::getDB()->prepareStatement($sql);
40 $statement->execute(array(Like::LIKE));
41 $row = $statement->fetchArray();
43 return ceil($row['count'] / $this->limit) + 1;
47 * @see wcf\system\user\activity\point\IUserActivityPointObject::updateActivityPointEvents();
49 public function updateActivityPointEvents($request) {
52 $sql = "DELETE FROM wcf".WCF_N."_user_activity_point_event
53 WHERE objectTypeID = ?";
54 $statement = WCF::getDB()->prepareStatement($sql);
55 $statement->execute(array($this->objectType->objectTypeID));
59 FROM wcf".WCF_N."_like
62 $statement = WCF::getDB()->prepareStatement($sql, $this->limit, ($this->limit * ($request - 1)));
63 $statement->execute(array(Like::LIKE));
65 while ($row = $statement->fetchArray()) {
66 $likeIDs[] = $row['likeID'];
69 if (empty($likeIDs)) return;
71 $conditionBuilder = new PreparedStatementConditionBuilder();
72 $conditionBuilder->add("objectTypeID = ?", array($this->objectType->objectTypeID));
73 $conditionBuilder->add("objectID IN (?)", array($likeIDs));
75 // avoid problems with duplicate keys, as likes may be created in the meantime
76 $sql = "DELETE FROM wcf".WCF_N."_user_activity_point_event
78 $statement = WCF::getDB()->prepareStatement($sql);
79 $statement->execute($conditionBuilder->getParameters());
81 $conditionBuilder = new PreparedStatementConditionBuilder();
82 $conditionBuilder->add("likeID IN (?)", array($likeIDs));
83 // use INSERT … SELECT as this makes bulk updating easier
84 $sql = "INSERT INTO wcf".WCF_N."_user_activity_point_event
85 (userID, objectTypeID, objectID, additionalData)
86 SELECT objectUserID AS userID,
90 FROM wcf".WCF_N."_like
92 $statement = WCF::getDB()->prepareStatement($sql);
93 $statement->execute(array_merge(array($this->objectType->objectTypeID, serialize(array())), $conditionBuilder->getParameters()));