3c99a2a7ca142ececf989f2c64d8b64dc7855f59
[GitHub/WoltLab/WCF.git] /
1 <?php
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\WCF;
7
8 /**
9 * Updates events for received likes.
10 *
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
17 */
18 class ReceivedLikesUserActivityPointObjectProcessor extends AbstractUserActivityPointObjectProcessor {
19 /**
20 * @see wcf\system\user\activity\point\IUserActivityPointObjectProcessor::countRequests();
21 */
22 public function countRequests() {
23 $sql = "SELECT COUNT(*)
24 FROM wcf".WCF_N."_like
25 WHERE likeValue = ?";
26 $statement = WCF::getDB()->prepareStatement($sql);
27 $statement->execute(array(Like::LIKE));
28
29 return ceil($statement->fetchColumn() / $this->limit) + 1;
30 }
31
32 /**
33 * @see wcf\system\user\activity\point\IUserActivityPointObjectProcessor::updateActivityPointEvents();
34 */
35 public function updateActivityPointEvents($request) {
36 if ($request == 0) {
37 // first 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));
42 }
43 else {
44 $sql = "SELECT likeID
45 FROM wcf".WCF_N."_like
46 WHERE likeValue = ?
47 ORDER BY likeID ASC";
48 $statement = WCF::getDB()->prepareStatement($sql, $this->limit, ($this->limit * ($request - 1)));
49 $statement->execute(array(Like::LIKE));
50 $likeIDs = array();
51 while ($row = $statement->fetchArray()) {
52 $likeIDs[] = $row['likeID'];
53 }
54
55 if (empty($likeIDs)) return;
56
57 $conditionBuilder = new PreparedStatementConditionBuilder();
58 $conditionBuilder->add("objectTypeID = ?", array($this->objectTypeID));
59 $conditionBuilder->add("objectID IN (?)", array($likeIDs));
60
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
63 ".$conditionBuilder;
64 $statement = WCF::getDB()->prepareStatement($sql);
65 $statement->execute($conditionBuilder->getParameters());
66
67 $conditionBuilder = new PreparedStatementConditionBuilder();
68 $conditionBuilder->add("likeID IN (?)", array($likeIDs));
69
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,
74 ?,
75 likeID AS objectID,
76 ?
77 FROM wcf".WCF_N."_like
78 ".$conditionBuilder;
79 $statement = WCF::getDB()->prepareStatement($sql);
80 $statement->execute(array_merge(array(
81 $this->objectTypeID,
82 serialize(array())
83 ), $conditionBuilder->getParameters()));
84 }
85 }
86 }