X-Git-Url: https://git.mxchange.org/?p=hub.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fpoints%2Fclass_UserPoints.php;fp=inc%2Fclasses%2Fmain%2Fpoints%2Fclass_UserPoints.php;h=6a9d88f172e03ff9b98df8b7c989b9833cc22264;hp=0000000000000000000000000000000000000000;hb=c59dccf46c5d0e3b7f2687370b2b15023b1ecdfe;hpb=e2767d5148436d0c90ed66ed9290416353ae6e60 diff --git a/inc/classes/main/points/class_UserPoints.php b/inc/classes/main/points/class_UserPoints.php new file mode 100644 index 000000000..6a9d88f17 --- /dev/null +++ b/inc/classes/main/points/class_UserPoints.php @@ -0,0 +1,92 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class UserPoints extends BaseFrameworkSystem implements Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this points class + * + * @param $userInstance An instance of a user class + * @return $pointsInstance An instance of this class + */ + public final static function createUserPoints (ManageableAccount $userInstance) { + // Get a new instance + $pointsInstance = new UserPoints(); + + // Set user instance + $pointsInstance->setUserInstance($userInstance); + + // Return instance + return $pointsInstance; + } + + /** + * Checks wether the user has the required amount of points left for the specified action + * + * @param $action The action or configuration entry plus prefix the user wants to perform + * @return $hasRequired Wether the user has the required points + */ + public function ifUserHasRequiredPoints ($action) { + // Default is that everyone is poor... ;-) + $hasRequired = false; + + // Get the required points entry + $requiredPoints = $this->getConfigInstance()->readConfig($action . '_action_points'); + + // Get a wrapper instance + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_points_db_wrapper_class'); + + // Now get a search criteria and set the user's name as criteria + $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + $criteriaInstance->addCriteria('points_uid', $this->getUserInstance()->getUserName()); + $criteriaInstance->setLimit(1); + + // Get result back + $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance); + + // Do we have an entry? + if ($resultInstance->next()) { + // Load points here - TODO! + $this->partialStub("Load points here for comparison."); + } // END - if + + // Return the result + return $hasRequired; + } +} + +// [EOF] +?>