3 namespace CoreFramework\Database\Wrapper\Points;
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7 use CoreFramework\Registry\Registerable;
10 * A database wrapper for user points classes
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15 * @license GNU GPL 3.0 or any newer version
16 * @link http://www.shipsimu.org
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class UserPointsDatabaseWrapper extends BaseDatabaseWrapper implements BookablePointsWrapper, Registerable {
33 * Constants for database table names
35 const DB_TABLE_USER_POINTS = 'user_points';
38 * Name of the user->points column
40 const DB_COLUMN_POINTS_UID = 'points_uid';
43 * Name of the points column
45 const DB_COLUMN_POINTS = 'points';
48 * Protected constructor
52 protected function __construct () {
53 // Call parent constructor
54 parent::__construct(__CLASS__);
58 * Creates an instance of this database wrapper by a provided user class
60 * @return $wrapperInstance An instance of the created wrapper class
62 public static final function createUserPointsDatabaseWrapper () {
64 $wrapperInstance = new UserPointsDatabaseWrapper();
66 // Set (primary!) table name
67 $wrapperInstance->setTableName(self::DB_TABLE_USER_POINTS);
69 // Return the instance
70 return $wrapperInstance;
74 * Inserts the given points for the given user in the database
76 * @param $pointsInstance An instance of a user class
79 public function insertUserPoints (BookablePoints $pointsInstance) {
80 // Generate a data set for the request
81 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER_POINTS));
83 // Set the primary key
84 $dataSetInstance->setUniqueKey(self::DB_COLUMN_POINTS_UID);
86 // Add registration elements to the dataset
87 $pointsInstance->addElementsToDataSet($dataSetInstance, NULL);
89 // "Insert" this request instance completely into the database
90 $this->queryInsertDataSet($dataSetInstance);
94 * Updates an user database entry with given result
96 * @param $resultInstance An instance of a Updateable database result
99 public function doUpdateByResult (UpdateableResult $resultInstance) {
100 // Generate a data set object
101 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER_POINTS));
103 // Add all update criteria to the database set
104 $resultInstance->addElementsToDataSet($dataSetInstance, NULL);
106 // Add seach criteria
107 $dataSetInstance->setSearchInstance($resultInstance->getUpdateInstance()->getSearchInstance());
109 // Set the primary key
110 $dataSetInstance->setUniqueKey(self::DB_COLUMN_POINTS_UID);
112 // "Update" this request with the database
113 $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);