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