namespace Org\Mxchange\CoreFramework\User;
// Import framework stuff
-use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseWrapper;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseFrontend;
use Org\Mxchange\CoreFramework\Database\Updateable;
-use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
use Org\Mxchange\CoreFramework\Request\Requestable;
use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
+use Org\Mxchange\CoreFramework\Traits\Result\Search\SearchableResultTrait;
/**
* A general user class
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class BaseUser extends BaseFrameworkSystem implements Updateable {
+abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
+ // Load traits
+ use SearchableResultTrait;
+
// Exception constances
const EXCEPTION_USERNAME_NOT_FOUND = 0x150;
const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x151;
* @param $className Name of the class
* @return void
*/
- protected function __construct ($className) {
+ protected function __construct (string $className) {
// Call parent constructor
parent::__construct($className);
}
* @param $userName The username to set
* @return void
*/
- public final function setUserName ($userName) {
- $this->userName = (string) $userName;
+ public final function setUserName (string $userName) {
+ $this->userName = $userName;
}
/**
* @return void
* @todo Find a way of casting here. "(int)" might destroy the user id > 32766
*/
- public final function setUserId ($userId) {
+ public final function setUserId (int $userId) {
$this->userId = $userId;
}
* @param $email The email to set
* @return void
*/
- protected final function setEmail ($email) {
- $this->email = (string) $email;
+ protected final function setEmail (string $email) {
+ $this->email = $email;
}
/**
// Is a previous result there?
if (!$this->getResultInstance() instanceof SearchableResult) {
- // Get a UserDatabaseWrapper instance
- $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+ // Get a UserDatabaseFrontend instance
+ $frontendInstance = ObjectFactory::createObjectByConfiguredName('user_db_frontend_class');
// Create a search criteria
$criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
// Add the username as a criteria and set limit to one entry
- $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+ $criteriaInstance->addCriteria(UserDatabaseFrontend::DB_COLUMN_USERNAME, $this->getUserName());
$criteriaInstance->setLimit(1);
// Get a search result
- $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $resultInstance = $frontendInstance->doSelectByCriteria($criteriaInstance);
// Set the index "solver"
- $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
+ $resultInstance->solveResultIndex(UserDatabaseFrontend::DB_COLUMN_USERID, $frontendInstance, array($this, 'setUserId'));
// And finally set it
$this->setResultInstance($resultInstance);
- } // END - if
+ }
// Rewind it
$this->getResultInstance()->rewind();
// Search for it
- if ($this->getResultInstance()->next()) {
+ if ($this->getResultInstance()->valid()) {
// Entry found
$exists = true;
- } // END - if
+ }
// Return the status
return $exists;
// Is a previous result there?
if (!$this->getResultInstance() instanceof SearchableResult) {
- // Get a UserDatabaseWrapper instance
- $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+ // Get a UserDatabaseFrontend instance
+ $frontendInstance = ObjectFactory::createObjectByConfiguredName('user_db_frontend_class');
// Create a search criteria
$criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
// Add the username as a criteria and set limit to one entry
- $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_EMAIL, $this->getEmail());
+ $criteriaInstance->addCriteria(UserDatabaseFrontend::DB_COLUMN_EMAIL, $this->getEmail());
$criteriaInstance->setLimit(1);
// Get a search result
- $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $resultInstance = $frontendInstance->doSelectByCriteria($criteriaInstance);
// Set the index "solver"
- $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
+ $resultInstance->solveResultIndex(UserDatabaseFrontend::DB_COLUMN_USERID, $frontendInstance, array($this, 'setUserId'));
// And finally set it
$this->setResultInstance($resultInstance);
- } // END - if
+ }
// Rewind it
$this->getResultInstance()->rewind();
// Search for it
- if ($this->getResultInstance()->next()) {
+ if ($this->getResultInstance()->valid()) {
// Entry found
$exists = true;
// Set the username
$this->setUserName($currEntry['username']);
- } // END - if
- } // END - if
+ }
+ }
// Return the status
return $exists;
// Is a previous result there?
if ((!$this->getResultInstance() instanceof SearchableResult) || ($this->getResultInstance()->count() == 0)) {
- // Get a UserDatabaseWrapper instance
- $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+ // Get a UserDatabaseFrontend instance
+ $frontendInstance = ObjectFactory::createObjectByConfiguredName('user_db_frontend_class');
// Create a search criteria
$criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
// Add the username as a criteria and set limit to one entry
- $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+ $criteriaInstance->addCriteria(UserDatabaseFrontend::DB_COLUMN_USERNAME, $this->getUserName());
$criteriaInstance->setLimit(1);
// Get a search result
- $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $resultInstance = $frontendInstance->doSelectByCriteria($criteriaInstance);
// Set the index "solver"
- $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
+ $resultInstance->solveResultIndex(UserDatabaseFrontend::DB_COLUMN_USERID, $frontendInstance, array($this, 'setUserId'));
// And finally set it
$this->setResultInstance($resultInstance);
- } // END - if
+ }
// Rewind it and advance to first entry
$this->getResultInstance()->rewind();
// So does the hashes match?
//* DEBUG: */ echo $requestInstance->getRequestElement('pass_hash') . '<br />' . $this->getResultInstance()->getFoundValue() . '<br />';
$matches = ($requestInstance->getRequestElement('pass_hash') === $this->getResultInstance()->getFoundValue());
- } // END - if
+ }
// Return the status
return $matches;
if (isset($entry['pass_hash'])) {
// Get it
$passHash = $entry['pass_hash'];
- } // END - if
+ }
// And return the hash
return $passHash;
* @return $primaryValue Value of the primary key based on database type
*/
public final function getPrimaryKey () {
- // Get a user database wrapper
- $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+ // Get a user database frontend
+ $frontendInstance = ObjectFactory::createObjectByConfiguredName('user_db_frontend_class');
- // Get the primary key back from the wrapper
- $primaryKey = $wrapperInstance->getPrimaryKeyValue();
+ // Get the primary key back from the frontend
+ $primaryKey = $frontendInstance->getPrimaryKeyValue();
// Get that field
$primaryValue = $this->getField($primaryKey);
* @return void
* @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
*/
- public function updateDatabaseField ($fieldName, $fieldValue) {
+ public function updateDatabaseField (string $fieldName, $fieldValue) {
// Get a critieria instance
$searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
// Add search criteria
- $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+ $searchInstance->addCriteria(UserDatabaseFrontend::DB_COLUMN_USERNAME, $this->getUserName());
$searchInstance->setLimit(1);
// Now get another criteria
// Add the search criteria for searching for the right entry
$updateInstance->setSearchInstance($searchInstance);
- // Set wrapper class name
- $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
+ // Set frontend class name
+ $updateInstance->setFrontendConfigEntry('user_db_frontend_class');
// Remember the update in database result
$this->getResultInstance()->add2UpdateQueue($updateInstance);
*/
public function isConfirmed () {
// Determine it
- $isConfirmed = ($this->getField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS) == $this->getConfigInstance()->getConfigEntry('user_status_confirmed'));
+ $isConfirmed = ($this->getField(UserDatabaseFrontend::DB_COLUMN_USER_STATUS) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('user_status_confirmed'));
// Return it
return $isConfirmed;
*/
public function isGuest () {
// Determine it
- $isGuest = ($this->getField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS) == $this->getConfigInstance()->getConfigEntry('user_status_guest'));
+ $isGuest = ($this->getField(UserDatabaseFrontend::DB_COLUMN_USER_STATUS) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('user_status_guest'));
// Return it
return $isGuest;