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