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