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 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
17 * @license GNU GPL 3.0 or any newer version
18 * @link http://www.shipsimu.org
20 * This program is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 class UserPointsDatabaseWrapper extends BaseDatabaseWrapper implements BookablePointsWrapper, Registerable {
35 * Constants for database table names
37 const DB_TABLE_USER_POINTS = 'user_points';
40 * Name of the user->points column
42 const DB_COLUMN_POINTS_UID = 'points_uid';
45 * Name of the points column
47 const DB_COLUMN_POINTS = 'points';
50 * Protected constructor
54 protected function __construct () {
55 // Call parent constructor
56 parent::__construct(__CLASS__);
60 * Creates an instance of this database wrapper by a provided user class
62 * @return $wrapperInstance An instance of the created wrapper class
64 public static final function createUserPointsDatabaseWrapper () {
66 $wrapperInstance = new UserPointsDatabaseWrapper();
68 // Set (primary!) table name
69 $wrapperInstance->setTableName(self::DB_TABLE_USER_POINTS);
71 // Return the instance
72 return $wrapperInstance;
76 * Inserts the given points for the given user in the database
78 * @param $pointsInstance An instance of a user class
81 public function insertUserPoints (BookablePoints $pointsInstance) {
82 // Generate a data set for the request
83 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER_POINTS));
85 // Set the primary key
86 $dataSetInstance->setUniqueKey(self::DB_COLUMN_POINTS_UID);
88 // Add registration elements to the dataset
89 $pointsInstance->addElementsToDataSet($dataSetInstance);
91 // "Insert" this request instance completely into the database
92 $this->queryInsertDataSet($dataSetInstance);
96 * Updates an user database entry with given result
98 * @param $resultInstance An instance of a Updateable database result
101 public function doUpdateByResult (UpdateableResult $resultInstance) {
102 // Generate a data set object
103 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER_POINTS));
105 // Add all update criteria to the database set
106 $resultInstance->addElementsToDataSet($dataSetInstance);
108 // Add seach criteria
109 $dataSetInstance->setSearchInstance($resultInstance->getUpdateInstance()->getSearchInstance());
111 // Set the primary key
112 $dataSetInstance->setUniqueKey(self::DB_COLUMN_POINTS_UID);
114 // "Update" this request with the database
115 $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);