]> git.mxchange.org Git - core.git/commitdiff
Updating/inserting points finished (basicly), flushing needed database updates moved...
authorRoland Häder <roland@mxchange.org>
Sun, 21 Dec 2008 04:08:50 +0000 (04:08 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 21 Dec 2008 04:08:50 +0000 (04:08 +0000)
23 files changed:
.gitattributes
inc/classes/interfaces/database/wrapper/.htaccess [new file with mode: 0644]
inc/classes/interfaces/database/wrapper/class_BookablePointsWrapper.php [new file with mode: 0644]
inc/classes/interfaces/database/wrapper/class_ManageableAccountWrapper.php [new file with mode: 0644]
inc/classes/interfaces/points/.htaccess [new file with mode: 0644]
inc/classes/interfaces/points/class_BookablePoints.php [new file with mode: 0644]
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/criteria/class_BaseCriteria.php [new file with mode: 0644]
inc/classes/main/criteria/class_DataSetCriteria.php [deleted file]
inc/classes/main/criteria/class_SearchCriteria.php [deleted file]
inc/classes/main/criteria/class_UpdateCriteria.php [deleted file]
inc/classes/main/criteria/dataset/.htaccess [new file with mode: 0644]
inc/classes/main/criteria/dataset/class_DataSetCriteria.php [new file with mode: 0644]
inc/classes/main/criteria/search/.htaccess [new file with mode: 0644]
inc/classes/main/criteria/search/class_SearchCriteria.php [new file with mode: 0644]
inc/classes/main/criteria/update/.htaccess [new file with mode: 0644]
inc/classes/main/criteria/update/class_UpdateCriteria.php [new file with mode: 0644]
inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php
inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php
inc/classes/main/points/class_UserPoints.php
inc/classes/main/result/class_DatabaseResult.php
inc/classes/main/user/class_BaseUser.php
inc/classes/main/user/member/class_Member.php

index 4c0aebd55f07dd506389ea849a92920b6573675f..0544e367de833fc5c18e05e1c1120a78b4906ec9 100644 (file)
@@ -152,6 +152,9 @@ inc/classes/interfaces/database/frontend/.htaccess -text
 inc/classes/interfaces/database/frontend/class_DatabaseFrontendInterface.php -text
 inc/classes/interfaces/database/middleware/.htaccess -text
 inc/classes/interfaces/database/middleware/class_DatabaseConnector.php -text
+inc/classes/interfaces/database/wrapper/.htaccess -text
+inc/classes/interfaces/database/wrapper/class_BookablePointsWrapper.php -text
+inc/classes/interfaces/database/wrapper/class_ManageableAccountWrapper.php -text
 inc/classes/interfaces/debug/.htaccess -text
 inc/classes/interfaces/debug/class_Debugger.php -text
 inc/classes/interfaces/discovery/.htaccess -text
@@ -174,6 +177,8 @@ inc/classes/interfaces/login/.htaccess -text
 inc/classes/interfaces/login/class_LoginableUser.php -text
 inc/classes/interfaces/mailer/.htaccess -text
 inc/classes/interfaces/mailer/class_DeliverableMail.php -text
+inc/classes/interfaces/points/.htaccess -text
+inc/classes/interfaces/points/class_BookablePoints.php -text
 inc/classes/interfaces/reader/.htaccess -text
 inc/classes/interfaces/reader/class_ReadableNews.php -text
 inc/classes/interfaces/registration/.htaccess -text
@@ -268,9 +273,13 @@ inc/classes/main/controller/web/class_WebLogoutDoneController.php -text
 inc/classes/main/controller/web/class_WebRegisterController.php -text
 inc/classes/main/controller/web/class_WebStatusController.php -text
 inc/classes/main/criteria/.htaccess -text
-inc/classes/main/criteria/class_DataSetCriteria.php -text
-inc/classes/main/criteria/class_SearchCriteria.php -text
-inc/classes/main/criteria/class_UpdateCriteria.php -text
+inc/classes/main/criteria/class_BaseCriteria.php -text
+inc/classes/main/criteria/dataset/.htaccess -text
+inc/classes/main/criteria/dataset/class_DataSetCriteria.php -text
+inc/classes/main/criteria/search/.htaccess -text
+inc/classes/main/criteria/search/class_SearchCriteria.php -text
+inc/classes/main/criteria/update/.htaccess -text
+inc/classes/main/criteria/update/class_UpdateCriteria.php -text
 inc/classes/main/crypto/.htaccess -text
 inc/classes/main/crypto/class_CryptoHelper.php -text
 inc/classes/main/database/.htaccess -text
diff --git a/inc/classes/interfaces/database/wrapper/.htaccess b/inc/classes/interfaces/database/wrapper/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/interfaces/database/wrapper/class_BookablePointsWrapper.php b/inc/classes/interfaces/database/wrapper/class_BookablePointsWrapper.php
new file mode 100644 (file)
index 0000000..00da33b
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * An interface for wrapper dealing with bookable points
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface BookablePointsWrapper extends FrameworkInterface {
+       /**
+        * Inserts the given points for the given user in the database
+        *
+        * @param       $pointsInstance         An instance of a user class
+        * @return      void
+        */
+       function insertUserPoints (BookablePoints $pointsInstance);
+
+       /**
+        * Updates an user database entry with given result
+        *
+        * @param       $resultInstance         An instance of a Updateable database result
+        * @return      void
+        */
+       function doUpdateByResult (UpdateableResult $resultInstance);
+}
+
+//
+?>
diff --git a/inc/classes/interfaces/database/wrapper/class_ManageableAccountWrapper.php b/inc/classes/interfaces/database/wrapper/class_ManageableAccountWrapper.php
new file mode 100644 (file)
index 0000000..f21abfc
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * An interface for wrapper handling manageable accounts
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface ManageableAccountWrapper extends FrameworkInterface {
+       /**
+        * Handles inserting the registration data from a registration instance into the database
+        *
+        * @param       $registrationInstance   An instance of a registration class
+        * @return      void
+        */
+       function insertRegistrationObject (UserRegister $registrationInstance);
+
+       /**
+        * Updates an user database entry with given result
+        *
+        * @param       $resultInstance         An instance of a Updateable database result
+        * @return      void
+        */
+       function doUpdateByResult (UpdateableResult $resultInstance);
+}
+
+//
+?>
diff --git a/inc/classes/interfaces/points/.htaccess b/inc/classes/interfaces/points/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/interfaces/points/class_BookablePoints.php b/inc/classes/interfaces/points/class_BookablePoints.php
new file mode 100644 (file)
index 0000000..80de5b4
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * An interface for bookable points
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface BookablePoints extends FrameworkInterface {
+       /**
+        * Checks wether the user has the required amount of points left for the specified action
+        *
+        * @param       $action                 The action or configuration entry plus prefix the user wants to perform
+        * @return      $hasRequired    Wether the user has the required points
+        */
+       function ifUserHasRequiredPoints ($action);
+
+       /**
+        * "Books" the given points amount on the current user's account
+        *
+        * @param       $amount         Amount of points we shall book
+        * @return      void
+        */
+       function bookPointsDirectly ($amount);
+
+       /**
+        * Adds registration elements to a given dataset instance
+        *
+        * @param       $criteriaInstance       An instance of a storeable criteria
+        * @return      void
+        */
+       function addElementsToDataSet (StoreableCriteria $criteriaInstance);
+}
+
+//
+?>
index d4eabd793f3564724250b78ec9e669c6f592b56e..d548e58433fc0a62a4a408b792aa234d3eb79a92 100644 (file)
@@ -53,6 +53,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $searchInstance = null;
 
+       /**
+        * Update criteria instance
+        */
+       private $updateInstance = null;
+
        /**
         * The file I/O instance for the template loader
         */
@@ -211,6 +216,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @todo        This is old code. Do we still need this old lost code?
         */
        public function __destruct() {
+               // Flush any updated entries to the database
+               $this->flushPendingUpdates();
+
                // Is this object already destroyed?
                if ($this->__toString() != 'DestructedObject') {
                        // Destroy all informations about this class but keep some text about it alive
@@ -360,6 +368,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->searchInstance;
        }
 
+       /**
+        * Setter for update instance
+        *
+        * @param       $updateInstance         Searchable criteria instance
+        * @return      void
+        */
+       public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
+               $this->updateInstance = $updateInstance;
+       }
+
+       /**
+        * Getter for update instance
+        *
+        * @return      $updateInstance         Updateable criteria instance
+        */
+       public final function getUpdateInstance () {
+               return $this->updateInstance;
+       }
+
        /**
         * Setter for resolver instance
         *
@@ -1071,6 +1098,28 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        public final function getControllerInstance () {
                return $this->controllerInstance;
        }
+
+       /**
+        * Flushs all pending updates to the database layer
+        *
+        * @return      void
+        */
+       public function flushPendingUpdates () {
+               // Get result instance
+               $resultInstance = $this->getResultInstance();
+
+               // Do we have data to update?
+               if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
+                       // Get wrapper class name config entry
+                       $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
+
+                       // Create object instance
+                       $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
+
+                       // Yes, then send the whole result to the database layer
+                       $wrapperInstance->doUpdateByResult($this->getResultInstance());
+               } // END - if
+       }
 }
 
 // [EOF]
diff --git a/inc/classes/main/criteria/class_BaseCriteria.php b/inc/classes/main/criteria/class_BaseCriteria.php
new file mode 100644 (file)
index 0000000..d493bb1
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * A general crtieria class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+class BaseCriteria extends BaseFrameworkSystem {
+       /**
+        * Wrapper class name stored in config entry
+        */
+       private $wrapperConfigEntry = "";
+
+       /**
+        * Protected constructor
+        *
+        * @param       $className      Name of the class
+        * @return      void
+        */
+       protected function __construct ($className) {
+               // Call parent constructor
+               parent::__construct($className);
+
+               // Clean up a little
+               $this->removeNumberFormaters();
+               $this->removeSystemArray();
+       }
+
+       /**
+        * Setter for wrapper class name
+        *
+        * @param       $wrapperConfigEntry             Configuration entry which hold the wrapper class' name
+        * @return      void
+        */
+       public final function setWrapperConfigEntry ($wrapperConfigEntry) {
+               $this->wrapperConfigEntry = (string) $wrapperConfigEntry;
+       }
+
+       /**
+        * Getter for wrapper class name
+        *
+        * @return      $wrapperConfigEntry             Configuration entry which hold the wrapper class' name
+        */
+       public final function getWrapperConfigEntry () {
+               return $this->wrapperConfigEntry;
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/criteria/class_DataSetCriteria.php b/inc/classes/main/criteria/class_DataSetCriteria.php
deleted file mode 100644 (file)
index 34715c5..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-<?php
-/**
- * A set of data storeable in databases
- *
- * @see                        DatabaseFrontendInterface - An interface for database frontends (front-end to the application)
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class DataSetCriteria extends BaseFrameworkSystem implements StoreableCriteria {
-       /**
-        * Table name
-        */
-       private $tableName = "";
-
-       /**
-        * Table columns (criteria) to store
-        */
-       private $tableColumns = array();
-
-       /**
-        * Unique key
-        */
-       private $uniqueKey = "";
-
-       /**
-        * Primary key
-        */
-       private $primaryKey = "";
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct() {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
-       }
-
-       /**
-        * Creates an instance of this criteria
-        *
-        * @param       $tableName                      Name of the table
-        * @return      $criteriaInstance       An instance of this criteria
-        */
-       public final static function createDataSetCriteria ($tableName) {
-               // Get a new instance
-               $criteriaInstance = new DataSetCriteria();
-
-               // Set table name
-               $criteriaInstance->setTableName($tableName);
-
-               // Return the instance
-               return $criteriaInstance;
-       }
-
-       /**
-        * Add criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $criteriaValue  Criteria value
-        * @return      void
-        */
-       public function addCriteria ($criteriaKey, $criteriaValue) {
-               $this->tableColumns[(string) $criteriaKey] = $criteriaValue;
-       }
-
-       /**
-        * Add configured criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $configEntry    Configuration entry
-        * @return      void
-        */
-       public function addConfiguredCriteria ($criteriaKey, $configEntry) {
-               // Add configuration entry as criteria
-               $value = $this->getConfigInstance()->readConfig($configEntry);
-               $this->addCriteria($criteriaKey, $value);
-       }
-
-       /**
-        * Setter for table name
-        *
-        * @param       $tableName      Name of the table to set
-        * @return      void
-        */
-       public final function setTableName ($tableName) {
-               $this->tableName = (string) $tableName;
-       }
-
-       /**
-        * Getter for table name
-        *
-        * @return      $tableName      Name of the table to set
-        */
-       public final function getTableName () {
-               return $this->tableName;
-       }
-
-       /**
-        * Setter for unique key
-        *
-        * @param       $uniqueKey      Column to use as unique key
-        * @return      void
-        */
-       public final function setUniqueKey ($uniqueKey) {
-               $this->uniqueKey = (string) $uniqueKey;
-       }
-
-       /**
-        * Getter for unique key
-        *
-        * @return      $uniqueKey      Column to use as unique key
-        */
-       public final function getUniqueKey () {
-               return $this->uniqueKey;
-       }
-
-       /**
-        * Getter for unique key value
-        *
-        * @return      $uniqueValue    Value of the unique key
-        */
-       public final function getUniqueValue () {
-               return $this->tableColumns[$this->getUniqueKey()];
-       }
-
-       /**
-        * Getter for criteria array
-        *
-        * @return      $tableColumns
-        */
-       public final function getCriteriaArray () {
-               return $this->tableColumns;
-       }
-
-       /**
-        * Getter for primary key or unique key if not set
-        *
-        * @return      $primaryKey             Primary key or unique key if not set
-        */
-       public final function getPrimaryKey () {
-               // Get primary key by default
-               $primaryKey = $this->primaryKey;
-
-               if (empty($primaryKey)) {
-                       // Get uniqueKey
-                       $primaryKey = $this->getUniqueKey();
-               } // END - if
-
-               // Return it
-               return $primaryKey;
-       }
-
-       /**
-        * Setter for primary key
-        *
-        * @param       $primaryKey             Primary key to set
-        * @return      void
-        */
-       public final function setPrimaryKey ($primaryKey) {
-               $this->primaryKey = (string) $primaryKey;
-       }
-}
-
-// [EOF]
-?>
diff --git a/inc/classes/main/criteria/class_SearchCriteria.php b/inc/classes/main/criteria/class_SearchCriteria.php
deleted file mode 100644 (file)
index faeb8be..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-<?php
-/**
- * Search criteria for e.g. searching in databases. Do not use this class if
- * you are looking for a ship or company, or what ever. Instead use this class
- * for looking in storages like the database.
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class SearchCriteria extends BaseFrameworkSystem implements LocalSearchCriteria {
-       /**
-        * Criteria to handle
-        */
-       private $searchCriteria = array();
-
-       /**
-        * Limitation for the search
-        */
-       private $limit = 0;
-
-       /**
-        * Skip these entries before using them
-        */
-       private $skip = 0;
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
-       }
-
-       /**
-        * Create an instance of this class
-        *
-        * @return      $criteriaInstance       An instance of this criteria
-        */
-       public final static function createSearchCriteria () {
-               // Get a new instance
-               $criteriaInstance = new SearchCriteria();
-
-               // Return this instance
-               return $criteriaInstance;
-       }
-
-       /**
-        * Add criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $criteriaValue  Criteria value
-        * @return      void
-        */
-       public final function addCriteria ($criteriaKey, $criteriaValue) {
-               $this->searchCriteria[(string)$criteriaKey] = (string)$criteriaValue;
-       }
-
-       /**
-        * Add configured criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $configEntry    Configuration entry
-        * @return      void
-        */
-       public final function addConfiguredCriteria ($criteriaKey, $configEntry) {
-               // Add the configuration entry as a criteria
-               $value = $this->getConfigInstance()->readConfig($configEntry);
-               $this->addCriteria($criteriaKey, $value);
-       }
-
-       /**
-        * Setter for limit
-        *
-        * @param       $limit  Search limit
-        * @return      void
-        * @todo        Find a nice casting here. (int) allows until and including 32766.
-        */
-       public final function setLimit ($limit) {
-               $this->limit = $limit;
-       }
-
-       /**
-        * Getter for limit
-        *
-        * @return      $limit  Search limit
-        */
-       public final function getLimit () {
-               return $this->limit;
-       }
-
-       /**
-        * Setter for skip
-        *
-        * @param       $skip   Search skip
-        * @return      void
-        * @todo        Find a nice casting here. (int) allows until and including 32766.
-        */
-       public final function setSkip ($skip) {
-               $this->skip = $skip;
-       }
-
-       /**
-        * Getter for skip
-        *
-        * @return      $skip   Search skip
-        */
-       public final function getSkip () {
-               return $this->skip;
-       }
-
-       /**
-        * "Getter" for a cache key
-        *
-        * @return      $cacheKey       The key suitable for the cache system
-        */
-       public function getCacheKey () {
-               // Initialize the key
-               $cacheKey = "";
-
-               // Now walk through all criterias
-               foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) {
-                       // Add the value URL encoded to avoid any trouble with special characters
-                       $cacheKey .= sprintf("%s=%s;",
-                               $criteriaKey,
-                               urlencode($criteriaValue)
-                       );
-               }
-
-               // Add limit and skip values
-               $cacheKey .= sprintf("%%limit%%=%s;%%skip%%=%s",
-                       $this->limit,
-                       $this->skip
-               );
-
-               // Return the cache key
-               return $cacheKey;
-       }
-
-       /**
-        * Get criteria element or null if not found
-        *
-        * @param       $criteria       The criteria we want to have
-        * @return      $value          Wether the value of the critera or null
-        */
-       public function getCriteriaElemnent ($criteria) {
-               // Default is not found
-               $value = null;
-
-               // Is the criteria there?
-               if (isset($this->searchCriteria[$criteria])) {
-                       // Then use it
-                       $value = $this->searchCriteria[$criteria];
-               }
-
-               // Return the value
-               return $value;
-       }
-
-       /**
-        * Checks wether given array entry matches
-        *
-        * @param       $entryArray             Array with the entries to find
-        * @return      $matches                Wether the entry matches or not
-        */
-       public function ifEntryMatches (array $entryArray) {
-               // First nothing matches and nothing is counted
-               $matches = false;
-               $counted = 0;
-
-               // Walk through all entries
-               foreach ($entryArray as $key => $entry) {
-                       // Then walk through all search criteria
-                       foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) {
-                               // Is the element found and does it match?
-                               if (($key == $criteriaKey) && ($criteriaValue == $entry)) {
-                                       // Then count this one up
-                                       $counted++;
-                               } // END - if
-                       } // END - foreach
-               } // END - foreach
-
-               // Now check if expected criteria counts match
-               $matches = ($counted == count($this->searchCriteria));
-
-               // Return the result
-               return $matches;
-       }
-}
-
-// [EOF]
-?>
diff --git a/inc/classes/main/criteria/class_UpdateCriteria.php b/inc/classes/main/criteria/class_UpdateCriteria.php
deleted file mode 100644 (file)
index af3f6a5..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * Search criteria for e.g. searching in databases. Do not use this class if
- * you are looking for a ship or company, or what ever. Instead use this class
- * for looking in storages like the database.
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class UpdateCriteria extends BaseFrameworkSystem implements LocalUpdateCriteria {
-       /**
-        * Criteria to handle
-        */
-       private $updateCriteria = array();
-
-       /**
-        * Limitation for the update
-        */
-       private $limit = 0;
-
-       /**
-        * Skip these entries before using them
-        */
-       private $skip = 0;
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
-       }
-
-       /**
-        * Create an instance of this class
-        *
-        * @return      $criteriaInstance       An instance of this criteria
-        */
-       public final static function createUpdateCriteria () {
-               // Get a new instance
-               $criteriaInstance = new UpdateCriteria();
-
-               // Return this instance
-               return $criteriaInstance;
-       }
-
-       /**
-        * Add criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $criteriaValue  Criteria value
-        * @return      void
-        */
-       public function addCriteria ($criteriaKey, $criteriaValue) {
-               $this->updateCriteria[$criteriaKey] = $criteriaValue;
-       }
-
-       /**
-        * Add configured criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $configEntry    Configuration entry
-        * @return      void
-        */
-       public function addConfiguredCriteria ($criteriaKey, $configEntry) {
-               // Add the configuration entry as a criteria
-               $value = $this->getConfigInstance()->readConfig($configEntry);
-               $this->addCriteria($criteriaKey, $value);
-       }
-
-       /**
-        * Getter for update criteria array
-        *
-        * @return      $updateCriteria         Array holding the update criteria
-        */
-       public final function getUpdateCriteria () {
-               return $this->updateCriteria;
-       }
-}
-
-// [EOF]
-?>
diff --git a/inc/classes/main/criteria/dataset/.htaccess b/inc/classes/main/criteria/dataset/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php
new file mode 100644 (file)
index 0000000..f342606
--- /dev/null
@@ -0,0 +1,183 @@
+<?php
+/**
+ * A set of data storeable in databases
+ *
+ * @see                        DatabaseFrontendInterface - An interface for database frontends (front-end to the application)
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class DataSetCriteria extends BaseCriteria implements StoreableCriteria {
+       /**
+        * Table name
+        */
+       private $tableName = "";
+
+       /**
+        * Table columns (criteria) to store
+        */
+       private $tableColumns = array();
+
+       /**
+        * Unique key
+        */
+       private $uniqueKey = "";
+
+       /**
+        * Primary key
+        */
+       private $primaryKey = "";
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct() {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this criteria
+        *
+        * @param       $tableName                      Name of the table
+        * @return      $criteriaInstance       An instance of this criteria
+        */
+       public final static function createDataSetCriteria ($tableName) {
+               // Get a new instance
+               $criteriaInstance = new DataSetCriteria();
+
+               // Set table name
+               $criteriaInstance->setTableName($tableName);
+
+               // Return the instance
+               return $criteriaInstance;
+       }
+
+       /**
+        * Add criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $criteriaValue  Criteria value
+        * @return      void
+        */
+       public function addCriteria ($criteriaKey, $criteriaValue) {
+               $this->tableColumns[(string) $criteriaKey] = $criteriaValue;
+       }
+
+       /**
+        * Add configured criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $configEntry    Configuration entry
+        * @return      void
+        */
+       public function addConfiguredCriteria ($criteriaKey, $configEntry) {
+               // Add configuration entry as criteria
+               $value = $this->getConfigInstance()->readConfig($configEntry);
+               $this->addCriteria($criteriaKey, $value);
+       }
+
+       /**
+        * Setter for table name
+        *
+        * @param       $tableName      Name of the table to set
+        * @return      void
+        */
+       public final function setTableName ($tableName) {
+               $this->tableName = (string) $tableName;
+       }
+
+       /**
+        * Getter for table name
+        *
+        * @return      $tableName      Name of the table to set
+        */
+       public final function getTableName () {
+               return $this->tableName;
+       }
+
+       /**
+        * Setter for unique key
+        *
+        * @param       $uniqueKey      Column to use as unique key
+        * @return      void
+        */
+       public final function setUniqueKey ($uniqueKey) {
+               $this->uniqueKey = (string) $uniqueKey;
+       }
+
+       /**
+        * Getter for unique key
+        *
+        * @return      $uniqueKey      Column to use as unique key
+        */
+       public final function getUniqueKey () {
+               return $this->uniqueKey;
+       }
+
+       /**
+        * Getter for unique key value
+        *
+        * @return      $uniqueValue    Value of the unique key
+        */
+       public final function getUniqueValue () {
+               return $this->tableColumns[$this->getUniqueKey()];
+       }
+
+       /**
+        * Getter for criteria array
+        *
+        * @return      $tableColumns
+        */
+       public final function getCriteriaArray () {
+               return $this->tableColumns;
+       }
+
+       /**
+        * Getter for primary key or unique key if not set
+        *
+        * @return      $primaryKey             Primary key or unique key if not set
+        */
+       public final function getPrimaryKey () {
+               // Get primary key by default
+               $primaryKey = $this->primaryKey;
+
+               if (empty($primaryKey)) {
+                       // Get uniqueKey
+                       $primaryKey = $this->getUniqueKey();
+               } // END - if
+
+               // Return it
+               return $primaryKey;
+       }
+
+       /**
+        * Setter for primary key
+        *
+        * @param       $primaryKey             Primary key to set
+        * @return      void
+        */
+       public final function setPrimaryKey ($primaryKey) {
+               $this->primaryKey = (string) $primaryKey;
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/criteria/search/.htaccess b/inc/classes/main/criteria/search/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/criteria/search/class_SearchCriteria.php b/inc/classes/main/criteria/search/class_SearchCriteria.php
new file mode 100644 (file)
index 0000000..91baad3
--- /dev/null
@@ -0,0 +1,209 @@
+<?php
+/**
+ * Search criteria for e.g. searching in databases. Do not use this class if
+ * you are looking for a ship or company, or what ever. Instead use this class
+ * for looking in storages like the database.
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class SearchCriteria extends BaseCriteria implements LocalSearchCriteria {
+       /**
+        * Criteria to handle
+        */
+       private $searchCriteria = array();
+
+       /**
+        * Limitation for the search
+        */
+       private $limit = 0;
+
+       /**
+        * Skip these entries before using them
+        */
+       private $skip = 0;
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Create an instance of this class
+        *
+        * @return      $criteriaInstance       An instance of this criteria
+        */
+       public final static function createSearchCriteria () {
+               // Get a new instance
+               $criteriaInstance = new SearchCriteria();
+
+               // Return this instance
+               return $criteriaInstance;
+       }
+
+       /**
+        * Add criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $criteriaValue  Criteria value
+        * @return      void
+        */
+       public final function addCriteria ($criteriaKey, $criteriaValue) {
+               $this->searchCriteria[(string)$criteriaKey] = (string)$criteriaValue;
+       }
+
+       /**
+        * Add configured criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $configEntry    Configuration entry
+        * @return      void
+        */
+       public final function addConfiguredCriteria ($criteriaKey, $configEntry) {
+               // Add the configuration entry as a criteria
+               $value = $this->getConfigInstance()->readConfig($configEntry);
+               $this->addCriteria($criteriaKey, $value);
+       }
+
+       /**
+        * Setter for limit
+        *
+        * @param       $limit  Search limit
+        * @return      void
+        * @todo        Find a nice casting here. (int) allows until and including 32766.
+        */
+       public final function setLimit ($limit) {
+               $this->limit = $limit;
+       }
+
+       /**
+        * Getter for limit
+        *
+        * @return      $limit  Search limit
+        */
+       public final function getLimit () {
+               return $this->limit;
+       }
+
+       /**
+        * Setter for skip
+        *
+        * @param       $skip   Search skip
+        * @return      void
+        * @todo        Find a nice casting here. (int) allows until and including 32766.
+        */
+       public final function setSkip ($skip) {
+               $this->skip = $skip;
+       }
+
+       /**
+        * Getter for skip
+        *
+        * @return      $skip   Search skip
+        */
+       public final function getSkip () {
+               return $this->skip;
+       }
+
+       /**
+        * "Getter" for a cache key
+        *
+        * @return      $cacheKey       The key suitable for the cache system
+        */
+       public function getCacheKey () {
+               // Initialize the key
+               $cacheKey = "";
+
+               // Now walk through all criterias
+               foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) {
+                       // Add the value URL encoded to avoid any trouble with special characters
+                       $cacheKey .= sprintf("%s=%s;",
+                               $criteriaKey,
+                               urlencode($criteriaValue)
+                       );
+               }
+
+               // Add limit and skip values
+               $cacheKey .= sprintf("%%limit%%=%s;%%skip%%=%s",
+                       $this->limit,
+                       $this->skip
+               );
+
+               // Return the cache key
+               return $cacheKey;
+       }
+
+       /**
+        * Get criteria element or null if not found
+        *
+        * @param       $criteria       The criteria we want to have
+        * @return      $value          Wether the value of the critera or null
+        */
+       public function getCriteriaElemnent ($criteria) {
+               // Default is not found
+               $value = null;
+
+               // Is the criteria there?
+               if (isset($this->searchCriteria[$criteria])) {
+                       // Then use it
+                       $value = $this->searchCriteria[$criteria];
+               }
+
+               // Return the value
+               return $value;
+       }
+
+       /**
+        * Checks wether given array entry matches
+        *
+        * @param       $entryArray             Array with the entries to find
+        * @return      $matches                Wether the entry matches or not
+        */
+       public function ifEntryMatches (array $entryArray) {
+               // First nothing matches and nothing is counted
+               $matches = false;
+               $counted = 0;
+
+               // Walk through all entries
+               foreach ($entryArray as $key => $entry) {
+                       // Then walk through all search criteria
+                       foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) {
+                               // Is the element found and does it match?
+                               if (($key == $criteriaKey) && ($criteriaValue == $entry)) {
+                                       // Then count this one up
+                                       $counted++;
+                               } // END - if
+                       } // END - foreach
+               } // END - foreach
+
+               // Now check if expected criteria counts match
+               $matches = ($counted == count($this->searchCriteria));
+
+               // Return the result
+               return $matches;
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/criteria/update/.htaccess b/inc/classes/main/criteria/update/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/criteria/update/class_UpdateCriteria.php b/inc/classes/main/criteria/update/class_UpdateCriteria.php
new file mode 100644 (file)
index 0000000..9508c45
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Search criteria for e.g. searching in databases. Do not use this class if
+ * you are looking for a ship or company, or what ever. Instead use this class
+ * for looking in storages like the database.
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class UpdateCriteria extends BaseCriteria implements LocalUpdateCriteria {
+       /**
+        * Criteria to handle
+        */
+       private $updateCriteria = array();
+
+       /**
+        * Limitation for the update
+        */
+       private $limit = 0;
+
+       /**
+        * Skip these entries before using them
+        */
+       private $skip = 0;
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Create an instance of this class
+        *
+        * @return      $criteriaInstance       An instance of this criteria
+        */
+       public final static function createUpdateCriteria () {
+               // Get a new instance
+               $criteriaInstance = new UpdateCriteria();
+
+               // Return this instance
+               return $criteriaInstance;
+       }
+
+       /**
+        * Add criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $criteriaValue  Criteria value
+        * @return      void
+        */
+       public function addCriteria ($criteriaKey, $criteriaValue) {
+               $this->updateCriteria[$criteriaKey] = $criteriaValue;
+       }
+
+       /**
+        * Add configured criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $configEntry    Configuration entry
+        * @return      void
+        */
+       public function addConfiguredCriteria ($criteriaKey, $configEntry) {
+               // Add the configuration entry as a criteria
+               $value = $this->getConfigInstance()->readConfig($configEntry);
+               $this->addCriteria($criteriaKey, $value);
+       }
+
+       /**
+        * Getter for update criteria array
+        *
+        * @return      $updateCriteria         Array holding the update criteria
+        */
+       public final function getUpdateCriteria () {
+               return $this->updateCriteria;
+       }
+}
+
+// [EOF]
+?>
index 503fbadb02089e2e2f0007fec6b077d5e406135a..3d1cd78c6c2441458271b48288d411af9d322214 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class UserDatabaseWrapper extends BaseDatabaseWrapper {
+class UserDatabaseWrapper extends BaseDatabaseWrapper implements ManageableAccountWrapper {
        // Constants for exceptions
        const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x180;
 
@@ -81,7 +81,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
                $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER));
 
                // Set the primary key
-               $dataSetInstance->setUniqueKey('username');
+               $dataSetInstance->setUniqueKey(self::DB_COLUMN_USERNAME);
 
                // Add registration elements to the dataset
                $registrationInstance->addElementsToDataSet($dataSetInstance);
@@ -107,7 +107,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
                $dataSetInstance->setSearchInstance($resultInstance->getSearchInstance());
 
                // Set the primary key
-               $dataSetInstance->setUniqueKey('username');
+               $dataSetInstance->setUniqueKey(self::DB_COLUMN_USERNAME);
 
                // "Update" this request with the database
                $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
index 0a8af18ed5b338316b5c9868bd3bc088e8339f31..54beb6e3ace86984655b78776c1ef4b58f7f24f0 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class UserPointsDatabaseWrapper extends BaseDatabaseWrapper {
-       // Constants for database table names
+class UserPointsDatabaseWrapper extends BaseDatabaseWrapper implements BookablePointsWrapper {
+       /**
+        * Constants for database table names
+        */
        const DB_TABLE_USER_POINTS = "user_points";
 
+       /**
+        * Name of the user->points column
+        */
+       const DB_COLUMN_POINTS_UID = "points_uid";
+
+       /**
+        * Name of the points column
+        */
+       const DB_COLUMN_POINTS = "points";
+
        /**
         * Protected constructor
         *
@@ -50,6 +62,49 @@ class UserPointsDatabaseWrapper extends BaseDatabaseWrapper {
                // Return the instance
                return $wrapperInstance;
        }
+
+       /**
+        * Inserts the given points for the given user in the database
+        *
+        * @param       $pointsInstance         An instance of a user class
+        * @return      void
+        */
+       public function insertUserPoints (BookablePoints $pointsInstance) {
+               // Generate a data set for the request
+               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER_POINTS));
+
+               // Set the primary key
+               $dataSetInstance->setUniqueKey(self::DB_COLUMN_POINTS_UID);
+
+               // Add registration elements to the dataset
+               $pointsInstance->addElementsToDataSet($dataSetInstance);
+
+               // "Insert" this request instance completely into the database
+               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+       }
+
+       /**
+        * Updates an user database entry with given result
+        *
+        * @param       $resultInstance         An instance of a Updateable database result
+        * @return      void
+        */
+       public function doUpdateByResult (UpdateableResult $resultInstance) {
+               // Generate a data set object
+               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER_POINTS));
+
+               // Add all update criteria to the database set
+               $resultInstance->addElementsToDataSet($dataSetInstance);
+
+               // Add seach criteria
+               $dataSetInstance->setSearchInstance($resultInstance->getUpdateInstance()->getSearchInstance());
+
+               // Set the primary key
+               $dataSetInstance->setUniqueKey(self::DB_COLUMN_POINTS_UID);
+
+               // "Update" this request with the database
+               $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
+       }
 }
 
 // [EOF]
index e7b636f4fa51244a8d73bbcc14061d41d6ae4dea..1dd62ec81b89a4acbe4398c953239221b162de20 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class UserPoints extends BaseFrameworkSystem implements Registerable {
+class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePoints {
+       /**
+        * Amount of points
+        */
+       private $amount = 0;
+
        /**
         * Protected constructor
         *
@@ -53,6 +58,25 @@ class UserPoints extends BaseFrameworkSystem implements Registerable {
                return $pointsInstance;
        }
 
+       /**
+        * Setter for amount
+        *
+        * @param       $amount         Amount of points to store
+        * @return      void
+        */
+       public final function setAmount ($amount) {
+               $this->amount = (float) $amount;
+       }
+
+       /**
+        * Getter for amount
+        *
+        * @return      $amount         Amount of points to store
+        */
+       public final function getAmount () {
+               return $this->amount;
+       }
+
        /**
         * Checks wether the user has the required amount of points left for the specified action
         *
@@ -67,16 +91,16 @@ class UserPoints extends BaseFrameworkSystem implements Registerable {
                // Get the required points entry
                $requiredPoints = $this->getConfigInstance()->readConfig($action . '_action_points');
 
+               // Now get a search criteria and set the user's name as criteria
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               $searchInstance->addCriteria(UserPointsDatabaseWrapper::DB_COLUMN_POINTS_UID, $this->getUserInstance()->getUserId());
+               $searchInstance->setLimit(1);
+
                // Get a wrapper instance
                $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_points_db_wrapper_class');
 
-               // Now get a search criteria and set the user's name as criteria
-               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-               $criteriaInstance->addCriteria("points_uid", $this->getUserInstance()->getUserName());
-               $criteriaInstance->setLimit(1);
-
                // Get result back
-               $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+               $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
 
                // Do we have an entry?
                if ($resultInstance->next()) {
@@ -87,6 +111,75 @@ class UserPoints extends BaseFrameworkSystem implements Registerable {
                // Return the result
                return $hasRequired;
        }
+
+       /**
+        * "Books" the given points amount on the current user's account
+        *
+        * @param       $amount         Amount of points we shall book
+        * @return      void
+        */
+       function bookPointsDirectly ($amount) {
+               // Get a critieria instance
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Add search criteria
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               $searchInstance->addCriteria(UserPointsDatabaseWrapper::DB_COLUMN_POINTS_UID, $this->getUserInstance()->getUserId());
+               $searchInstance->setLimit(1);
+
+               // Get a wrapper instance
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_points_db_wrapper_class');
+
+               // Get result back
+               $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
+
+               // Do we have an entry?
+               if ($resultInstance->next()) {
+                       // Get the entry
+                       $entry = $resultInstance->current();
+
+                       // Add the points
+                       $amount += $entry[UserPointsDatabaseWrapper::DB_COLUMN_POINTS];
+
+                       // Now get another criteria
+                       $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
+
+                       // And add our both entries
+                       $updateInstance->addCriteria(UserPointsDatabaseWrapper::DB_COLUMN_POINTS, $amount);
+
+                       // Add the search criteria for searching for the right entry
+                       $updateInstance->setSearchInstance($searchInstance);
+
+                       // Set wrapper class name
+                       $updateInstance->setWrapperConfigEntry('user_points_db_wrapper_class');
+
+                       // Remember the update in database result
+                       $resultInstance->add2UpdateQueue($updateInstance);
+
+                       // Set it
+                       $this->setResultInstance($resultInstance);
+               } else {
+                       // Set the amount in class
+                       $this->setAmount($amount);
+
+                       // Create the new entry
+                       $wrapperInstance->insertUserPoints($this);
+               }
+       }
+
+       /**
+        * Adds registration elements to a given dataset instance
+        *
+        * @param       $criteriaInstance       An instance of a storeable criteria
+        * @return      void
+        */
+       public function addElementsToDataSet (StoreableCriteria $criteriaInstance) {
+               // Add user id
+               $criteriaInstance->addCriteria(UserPointsDatabaseWrapper::DB_COLUMN_POINTS_UID, $this->getUserInstance()->getUserId());
+
+               // Add amount
+               $criteriaInstance->addCriteria(UserPointsDatabaseWrapper::DB_COLUMN_POINTS, $this->getAmount());
+       }
 }
 
 // [EOF]
index 94fe3b5deff55a2f96fac4aaba5bde59197b32a0..4909b3499cee969df60847b0cd599c348a6ff39b 100644 (file)
@@ -265,17 +265,17 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                        } // END - if
                } // END - while
 
-               // Set affected rows
-               $this->setAffectedRows($foundEntries);
-
                // If no entry is found/updated throw an exception
                if ($foundEntries == 0) {
                        // Throw an exception here
                        throw new ResultUpdateException($this, self::EXCEPTION_RESULT_UPDATE_FAILED);
                } // END - if
 
-               // Set search instance
-               $this->setSearchInstance($searchInstance);
+               // Set affected rows
+               $this->setAffectedRows($foundEntries);
+
+               // Set update instance
+               $this->setUpdateInstance($criteriaInstance);
        }
 
        /**
index b00a0730f4cfe6b1d4da5cc1057e25730e8f87bf..ee8a1594821c6bd87172834d27117dda184cba5e 100644 (file)
@@ -307,6 +307,7 @@ class BaseUser extends BaseFrameworkSystem {
         * @param       $fieldValue             New value to store
         * @return      void
         * @throws      DatabaseUpdateSupportException  If this class does not support database updates
+        * @todo        Try to make this method more generic so we can move it in BaseFrameworkSystem
         */
        public function updateDatabaseField ($fieldName, $fieldValue) {
                // Is updating database fields allowed by interface?
@@ -325,12 +326,15 @@ class BaseUser extends BaseFrameworkSystem {
                // Now get another criteria
                $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
 
-               // And add our both entries
+               // Add criteria entry which we shall update
                $updateInstance->addCriteria($fieldName, $fieldValue);
 
                // Add the search criteria for searching for the right entry
                $updateInstance->setSearchInstance($searchInstance);
 
+               // Set wrapper class name
+               $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
+
                // Remember the update in database result
                $this->getResultInstance()->add2UpdateQueue($updateInstance);
        }
index b67ad88b9274bbc1f2ebc48759a49ab2ac47663f..f5bf2e8889f4968d8d5792d7da6ff6913fa7f518 100644 (file)
@@ -32,19 +32,6 @@ class Member extends BaseUser implements ManageableMember, Registerable, Updatea
                parent::__construct(__CLASS__);
        }
 
-       /**
-        * Destructor to always flush updates
-        *
-        * @return      void
-        */
-       public function __destruct () {
-               // Flush any updated entries to the database
-               $this->flushPendingUpdates();
-
-               // Call parent destructor
-               parent::__destruct();
-       }
-
        /**
         * Creates an instance of this user class by a provided username. This
         * factory method will check if username is already taken and if not so it
@@ -150,25 +137,12 @@ class Member extends BaseUser implements ManageableMember, Registerable, Updatea
                // Add the search criteria for searching for the right entry
                $updateInstance->setSearchInstance($searchInstance);
 
+               // Set wrapper class name
+               $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
+
                // Remember the update in database result
                $this->getResultInstance()->add2UpdateQueue($updateInstance);
        }
-
-       /**
-        * Flushs all pending updates to the database layer
-        *
-        * @return      void
-        */
-       public function flushPendingUpdates () {
-               // Do we have data to update?
-               if ($this->getResultInstance()->ifDataNeedsFlush()) {
-                       // Get a database wrapper
-                       $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
-
-                       // Yes, then send the whole result to the database layer
-                       $wrapperInstance->doUpdateByResult($this->getResultInstance());
-               } // END - if
-       }
 }
 
 // [EOF]