]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/user/class_BaseUser.php
Continued:
[core.git] / framework / main / classes / user / class_BaseUser.php
index c7144f9f9a960d98359f082e1591b82930ad3d84..1a2da22ed2f91654659e391d0cd594eace12d347 100644 (file)
@@ -1,19 +1,23 @@
 <?php
 // Own namespace
-namespace CoreFramework\User;
+namespace Org\Mxchange\CoreFramework\User;
 
 // Import framework stuff
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Object\BaseFrameworkSystem;
-use CoreFramework\Request\Requestable;
-use CoreFramework\Result\Search\SearchableResult;
+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\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 - 2020 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -30,7 +34,10 @@ use CoreFramework\Result\Search\SearchableResult;
  * 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;
@@ -58,7 +65,7 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
         * @param       $className      Name of the class
         * @return      void
         */
-       protected function __construct ($className) {
+       protected function __construct (string $className) {
                // Call parent constructor
                parent::__construct($className);
        }
@@ -128,25 +135,25 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
         */
        public function ifUsernameExists () {
                // By default the username does not exist
-               $exists = FALSE;
+               $exists = false;
 
                // 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);
@@ -158,7 +165,7 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
                // Search for it
                if ($this->getResultInstance()->next()) {
                        // Entry found
-                       $exists = TRUE;
+                       $exists = true;
                } // END - if
 
                // Return the status
@@ -172,25 +179,25 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
         */
        public function ifEmailAddressExists () {
                // By default the email does not exist
-               $exists = FALSE;
+               $exists = false;
 
                // 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);
@@ -202,7 +209,7 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
                // Search for it
                if ($this->getResultInstance()->next()) {
                        // Entry found
-                       $exists = TRUE;
+                       $exists = true;
 
                        // Is the username set?
                        if ($this->getUserName() == '') {
@@ -227,25 +234,25 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
         */
        public function ifPasswordHashMatches (Requestable $requestInstance) {
                // By default nothing matches... ;)
-               $matches = FALSE;
+               $matches = false;
 
                // 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);
@@ -296,11 +303,11 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
         * @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);
@@ -317,12 +324,12 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
         * @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
@@ -334,8 +341,8 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
                // 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);
@@ -348,7 +355,7 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
         */
        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;
@@ -361,7 +368,7 @@ class BaseUser extends BaseFrameworkSystem implements Updateable {
         */
        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;