Added generic update counters method
authorMarcel Werk <burntime@woltlab.com>
Fri, 14 Oct 2011 19:32:00 +0000 (21:32 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 14 Oct 2011 19:32:00 +0000 (21:32 +0200)
wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php
wcfsetup/install/files/lib/data/IEditableObject.class.php

index 51de7706602f0c9d1c41b8b24f9aeecc5b985cfd..453d3741e80ada5a39e096ee4e4e89ec365348d3 100644 (file)
@@ -69,6 +69,28 @@ abstract class DatabaseObjectEditor extends DatabaseObjectDecorator implements I
                $statement->execute($statementParameters);
        }
        
+       /**
+        * @see wcf\data\IEditableObject::updateCounters()
+        */
+       public function updateCounters(array $counters = array()) {
+               if (!count($counters)) return;
+               
+               $updateSQL = '';
+               $statementParameters = array();
+               foreach ($counters as $key => $value) {
+                       if (!empty($updateSQL)) $updateSQL .= ', ';
+                       $updateSQL .= $key . ' = ' . $key . ' + ?';
+                       $statementParameters[] = $value;
+               }
+               $statementParameters[] = $this->__get(static::getDatabaseTableIndexName());
+               
+               $sql = "UPDATE  ".static::getDatabaseTableName()."
+                       SET     ".$updateSQL."
+                       WHERE   ".static::getDatabaseTableIndexName()." = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute($statementParameters);
+       }
+       
        /**
         * @see wcf\data\IEditableObject::delete()
         */
index cdc126c94bb57e0eedcf5e3e5cf29e57b9791d38..47c13c7d07282ecaf0d1b06e004786f79e46ea57 100644 (file)
@@ -27,6 +27,13 @@ interface IEditableObject extends IStorableObject {
         */
        public function update(array $parameters = array());
        
+       /**
+        * Updates the counters of this object.
+        * 
+        * @param       array           $counters
+        */
+       public function updateCounters(array $counters = array());
+       
        /**
         * Deletes this object.
         */