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