X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Fpoints%2Fclass_UserPoints.php;h=d38c270e451f99848b746ce29c06e933ff57670f;hb=refs%2Fheads%2Fmaster;hp=0961a489cb81d5dd5710ab91477c43dec50f2f97;hpb=78a010fef84895720e796842208f01dfb619c332;p=core.git diff --git a/framework/main/classes/points/class_UserPoints.php b/framework/main/classes/points/class_UserPoints.php index 0961a489..8f451ce3 100644 --- a/framework/main/classes/points/class_UserPoints.php +++ b/framework/main/classes/points/class_UserPoints.php @@ -1,21 +1,24 @@ * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * @@ -33,6 +36,10 @@ use CoreFramework\Request\Requestable; * along with this program. If not, see . */ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePoints { + // Load traits + use ManageableAccountTrait; + use SearchableResultTrait; + /** * Amount of points */ @@ -43,7 +50,7 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo * * @return void */ - protected function __construct () { + private function __construct () { // Call parent constructor parent::__construct(__CLASS__); } @@ -65,14 +72,14 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Add search criteria - $searchInstance->addCriteria(UserPointsDatabaseWrapper::DB_COLUMN_POINTS_UID, $userInstance->getUserId()); + $searchInstance->addCriteria(UserPointsDatabaseFrontend::DB_COLUMN_POINTS_UID, $userInstance->getUserId()); $searchInstance->setLimit(1); - // Get a wrapper instance - $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('user_points_db_wrapper_class'); + // Get a frontend instance + $frontendInstance = DatabaseFrontendFactory::createFrontendByConfiguredName('user_points_db_frontend_class'); // Get result back - $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); + $resultInstance = $frontendInstance->doSelectByCriteria($searchInstance); // Advance to first entry by default $resultInstance->next(); @@ -90,7 +97,7 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo * @param $amount Amount of points to store * @return void */ - public final function setAmount ($amount) { + public final function setAmount (float $amount) { $this->amount = (float) $amount; } @@ -110,24 +117,24 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo * @return $hasRequired Whether the user has the required points * @todo Finish loading part of points */ - public function ifUserHasRequiredPoints ($action) { + public function ifUserHasRequiredPoints (string $action) { // Default is that everyone is poor... ;-) - $hasRequired = FALSE; + $hasRequired = false; // Get the required points entry - $requiredPoints = $this->getConfigInstance()->getConfigEntry($action . '_action_points'); + $requiredPoints = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($action . '_action_points'); // Rewind always $this->getResultInstance()->rewind(); // Do we have an entry? - if ($this->getResultInstance()->next()) { + if ($this->getResultInstance()->valid()) { // Get the entry $currEntry = $this->getResultInstance()->current(); // Has he enought points? $hasRequired = ($currEntry['points'] >= $requiredPoints); - } // END - if + } // Return the result return $hasRequired; @@ -139,29 +146,29 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo * @param $amount Amount of points we shall book * @return void */ - public function bookPointsDirectly ($amount) { + public function bookPointsDirectly (float $amount) { // Rewind always $this->getResultInstance()->rewind(); // Do we have an entry? - if ($this->getResultInstance()->next()) { + if ($this->getResultInstance()->valid()) { // Get the entry - $entry = $this->getResultInstance()->current(); + $currentEntry = $this->getResultInstance()->current(); // Add the points - $amount += $entry[UserPointsDatabaseWrapper::DB_COLUMN_POINTS]; + $amount += $currentEntry[UserPointsDatabaseFrontend::DB_COLUMN_POINTS]; // Now get another criteria $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class'); // And add our both entries - $updateInstance->addCriteria(UserPointsDatabaseWrapper::DB_COLUMN_POINTS, $amount); + $updateInstance->addCriteria(UserPointsDatabaseFrontend::DB_COLUMN_POINTS, $amount); // Add the search criteria for searching for the right entry $updateInstance->setSearchInstance($searchInstance); - // Set wrapper class name - $updateInstance->setWrapperConfigEntry('user_points_db_wrapper_class'); + // Set frontend class name + $updateInstance->setFrontendConfigEntry('user_points_db_frontend_class'); // Remember the update in database result $this->getResultInstance()->add2UpdateQueue($updateInstance); @@ -170,7 +177,7 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo $this->setAmount($amount); // Create the new entry - $wrapperInstance->insertUserPoints($this); + $frontendInstance->insertUserPoints($this); } } @@ -178,16 +185,15 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo * Adds registration elements to a given dataset instance * * @param $criteriaInstance An instance of a StoreableCriteria class - * @param $requestInstance An instance of a Requestable class * @return void * @todo $requestInstance is currently unused */ - public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) { + public function addElementsToDataSet (StoreableCriteria $criteriaInstance) { // Add user id - $criteriaInstance->addCriteria(UserPointsDatabaseWrapper::DB_COLUMN_POINTS_UID, $this->getUserInstance()->getUserId()); + $criteriaInstance->addCriteria(UserPointsDatabaseFrontend::DB_COLUMN_POINTS_UID, $this->getUserInstance()->getUserId()); // Add amount - $criteriaInstance->addCriteria(UserPointsDatabaseWrapper::DB_COLUMN_POINTS, $this->getAmount()); + $criteriaInstance->addCriteria(UserPointsDatabaseFrontend::DB_COLUMN_POINTS, $this->getAmount()); } }