Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / stat / AbstractCommentStatDailyHandler.class.php
CommitLineData
f5f3032e
MS
1<?php
2namespace wcf\system\stat;
3use wcf\system\comment\CommentHandler;
e41e77b8 4use wcf\system\database\util\PreparedStatementConditionBuilder;
f5f3032e
MS
5use wcf\system\exception\SystemException;
6use wcf\system\WCF;
7
8/**
9 * Abstract implementation of a comment stat handler.
10 *
11 * @author Matthias Schmidt
c839bd49 12 * @copyright 2001-2018 WoltLab GmbH
f5f3032e 13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
e71525e4 14 * @package WoltLabSuite\Core\System\Stat
f5f3032e
MS
15 */
16abstract class AbstractCommentStatDailyHandler extends AbstractStatDailyHandler {
17 /**
18 * name of the comment object type
19 * @var string
20 */
21 protected $objectType = '';
22
23 /**
0fcfe5f6 24 * @inheritDoc
f5f3032e
MS
25 */
26 public function getData($date) {
27 $objectTypeID = CommentHandler::getInstance()->getObjectTypeID($this->objectType);
28 if ($objectTypeID === null) {
29 throw new SystemException("Unknown comment object type '".$this->objectType."'");
30 }
31
32 $sql = "SELECT (
33 SELECT COUNT(*)
34 FROM wcf".WCF_N."_comment
35 WHERE objectTypeID = ?
36 AND time BETWEEN ? AND ?
37 ) + (
38 SELECT COUNT(*)
39 FROM wcf".WCF_N."_comment_response comment_response
40 LEFT JOIN wcf".WCF_N."_comment comment
41 ON (comment.commentID = comment_response.commentID)
42 WHERE comment.objectTypeID = ?
43 AND comment_response.time BETWEEN ? AND ?
44 )";
45 $statement = WCF::getDB()->prepareStatement($sql);
058cbd6a 46 $statement->execute([
f5f3032e
MS
47 $objectTypeID,
48 $date,
49 $date + 86399,
50 $objectTypeID,
51 $date,
52 $date + 86399
058cbd6a 53 ]);
49fb0d2d 54 $counter = $statement->fetchSingleColumn();
f5f3032e
MS
55
56 $sql = "SELECT (
57 SELECT COUNT(*)
58 FROM wcf".WCF_N."_comment
59 WHERE objectTypeID = ?
60 AND time < ?
61 ) + (
62 SELECT COUNT(*)
63 FROM wcf".WCF_N."_comment_response comment_response
64 LEFT JOIN wcf".WCF_N."_comment comment
65 ON (comment.commentID = comment_response.commentID)
66 WHERE comment.objectTypeID = ?
67 AND comment_response.time < ?
68 )";
69 $statement = WCF::getDB()->prepareStatement($sql);
058cbd6a 70 $statement->execute([
f5f3032e
MS
71 $objectTypeID,
72 $date + 86400,
73 $objectTypeID,
74 $date + 86400
058cbd6a 75 ]);
49fb0d2d 76 $total = $statement->fetchSingleColumn();
f5f3032e 77
058cbd6a 78 return [
f5f3032e
MS
79 'counter' => $counter,
80 'total' => $total
058cbd6a 81 ];
f5f3032e 82 }
e41e77b8
MS
83
84 /**
85 * @inheritDoc
86 * @since 3.1
87 */
88 protected function addConditions(PreparedStatementConditionBuilder $conditionBuilder) {
89 throw new \BadMethodCallException(__CLASS__ . " does not support addConditions().");
90 }
f5f3032e 91}