3 namespace CoreFramework\Database\Wrapper\Points;
5 // Import framework stuff
6 use CoreFramework\Registry\Registerable;
9 * A database wrapper for user points classes
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class UserPointsDatabaseWrapper extends BaseDatabaseWrapper implements BookablePointsWrapper, Registerable {
32 * Constants for database table names
34 const DB_TABLE_USER_POINTS = 'user_points';
37 * Name of the user->points column
39 const DB_COLUMN_POINTS_UID = 'points_uid';
42 * Name of the points column
44 const DB_COLUMN_POINTS = 'points';
47 * Protected constructor
51 protected function __construct () {
52 // Call parent constructor
53 parent::__construct(__CLASS__);
57 * Creates an instance of this database wrapper by a provided user class
59 * @return $wrapperInstance An instance of the created wrapper class
61 public static final function createUserPointsDatabaseWrapper () {
63 $wrapperInstance = new UserPointsDatabaseWrapper();
65 // Set (primary!) table name
66 $wrapperInstance->setTableName(self::DB_TABLE_USER_POINTS);
68 // Return the instance
69 return $wrapperInstance;
73 * Inserts the given points for the given user in the database
75 * @param $pointsInstance An instance of a user class
78 public function insertUserPoints (BookablePoints $pointsInstance) {
79 // Generate a data set for the request
80 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER_POINTS));
82 // Set the primary key
83 $dataSetInstance->setUniqueKey(self::DB_COLUMN_POINTS_UID);
85 // Add registration elements to the dataset
86 $pointsInstance->addElementsToDataSet($dataSetInstance, NULL);
88 // "Insert" this request instance completely into the database
89 $this->queryInsertDataSet($dataSetInstance);
93 * Updates an user database entry with given result
95 * @param $resultInstance An instance of a Updateable database result
98 public function doUpdateByResult (UpdateableResult $resultInstance) {
99 // Generate a data set object
100 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER_POINTS));
102 // Add all update criteria to the database set
103 $resultInstance->addElementsToDataSet($dataSetInstance, NULL);
105 // Add seach criteria
106 $dataSetInstance->setSearchInstance($resultInstance->getUpdateInstance()->getSearchInstance());
108 // Set the primary key
109 $dataSetInstance->setUniqueKey(self::DB_COLUMN_POINTS_UID);
111 // "Update" this request with the database
112 $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);