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
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
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
--- /dev/null
+Deny from all
--- /dev/null
+<?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);
+}
+
+//
+?>
--- /dev/null
+<?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);
+}
+
+//
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?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);
+}
+
+//
+?>
*/
private $searchInstance = null;
+ /**
+ * Update criteria instance
+ */
+ private $updateInstance = null;
+
/**
* The file I/O instance for the template loader
*/
* @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
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
*
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]
--- /dev/null
+<?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]
+?>
+++ /dev/null
-<?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]
-?>
+++ /dev/null
-<?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]
-?>
+++ /dev/null
-<?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]
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?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]
+?>
* 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;
$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);
$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);
* 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
*
// 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]
* 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
*
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
*
// 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()) {
// 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]
} // 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);
}
/**
* @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?
// 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);
}
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
// 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]