Add `AbstractStatDailyHandler::addConditions()`
authorMatthias Schmidt <gravatronics@live.com>
Sat, 5 Aug 2017 15:23:12 +0000 (17:23 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 5 Aug 2017 15:23:12 +0000 (17:23 +0200)
Close #2365

wcfsetup/install/files/lib/system/stat/AbstractStatDailyHandler.class.php

index f9590710d0bb20da73a9c236e8e430a102ec0a5f..7581ea66a299836742a35806cfdd6285c9e30e40 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\stat;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\WCF;
 
 /**
@@ -20,11 +21,17 @@ abstract class AbstractStatDailyHandler implements IStatDailyHandler {
         * @return      integer
         */
        protected function getCounter($date, $tableName, $dateColumnName) {
+               $conditionBuilder = new PreparedStatementConditionBuilder();
+               $conditionBuilder->add($dateColumnName . ' BETWEEN ? AND ?', [$date, $date + 86399]);
+               
+               $this->addConditions($conditionBuilder);
+               
                $sql = "SELECT  COUNT(*)
                        FROM    " . $tableName . "
-                       WHERE   " . $dateColumnName . " BETWEEN ? AND ?";
+                       " . $conditionBuilder;
                $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute([$date, $date + 86399]);
+               $statement->execute($conditionBuilder->getParameters());
+               
                return $statement->fetchColumn();
        }
        
@@ -37,11 +44,17 @@ abstract class AbstractStatDailyHandler implements IStatDailyHandler {
         * @return      integer
         */
        protected function getTotal($date, $tableName, $dateColumnName) {
+               $conditionBuilder = new PreparedStatementConditionBuilder();
+               $conditionBuilder->add($dateColumnName . ' < ?', [$date + 86399]);
+               
+               $this->addConditions($conditionBuilder);
+               
                $sql = "SELECT  COUNT(*)
                        FROM    " . $tableName . "
-                       WHERE   " . $dateColumnName . " < ?";
+                       " . $conditionBuilder;
                $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute([$date + 86400]);
+               $statement->execute($conditionBuilder->getParameters());
+               
                return $statement->fetchColumn();
        }
        
@@ -51,4 +64,14 @@ abstract class AbstractStatDailyHandler implements IStatDailyHandler {
        public function getFormattedCounter($counter) {
                return $counter;
        }
+       
+       /**
+        * Adds additional conditions to the given condition builder.
+        * 
+        * @param       PreparedStatementConditionBuilder       $conditionBuilder
+        * @since       3.1
+        */
+       protected function addConditions(PreparedStatementConditionBuilder $conditionBuilder) {
+               // does nothing
+       }
 }