Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / stat / AbstractStatDailyHandler.class.php
1 <?php
2 namespace wcf\system\stat;
3 use wcf\system\WCF;
4
5 /**
6 * Abstract implementation of a stat handler.
7 *
8 * @author Marcel Werk
9 * @copyright 2001-2014 WoltLab GmbH
10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11 * @package com.woltlab.wcf
12 * @subpackage system.stat
13 * @category Community Framework
14 */
15 abstract class AbstractStatDailyHandler implements IStatDailyHandler {
16 /**
17 * Counts the number of rows for a single day.
18 *
19 * @param integer $date
20 * @param string $tableName
21 * @param string $dateColumnName
22 * @return integer
23 */
24 protected function getCounter($date, $tableName, $dateColumnName) {
25 $sql = "SELECT COUNT(*) AS count
26 FROM " . $tableName . "
27 WHERE " . $dateColumnName . " BETWEEN ? AND ?";
28 $statement = WCF::getDB()->prepareStatement($sql);
29 $statement->execute(array($date, $date + 86399));
30 return $statement->fetchColumn();
31 }
32
33 /**
34 * Counts the total number of rows.
35 *
36 * @param integer $date
37 * @param string $tableName
38 * @param string $dateColumnName
39 * @return integer
40 */
41 protected function getTotal($date, $tableName, $dateColumnName) {
42 $sql = "SELECT COUNT(*) AS count
43 FROM " . $tableName . "
44 WHERE " . $dateColumnName . " < ?";
45 $statement = WCF::getDB()->prepareStatement($sql);
46 $statement->execute(array($date + 86400));
47 return $statement->fetchColumn();
48 }
49
50 /**
51 * @see \wcf\system\stat\IStatDailyHandler::getFormattedCounter()
52 */
53 public function getFormattedCounter($counter) {
54 return $counter;
55 }
56 }