public function emailMakePrimary($mIdEmail, $iUserId = null)
    {
        //  Fetch email
        $oDb = Factory::service('Database');
        $oDb->select('id,user_id,email');

        if (is_numeric($mIdEmail)) {
            $oDb->where('id', $mIdEmail);
        } else {
            $oDb->where('email', $mIdEmail);
        }

        if (!is_null($iUserId)) {
            $oDb->where('user_id', $iUserId);
        }

        $oEmail = $oDb->get($this->tableEmail)->row();

        if (empty($oEmail)) {
            return false;
        }

        //  Update
        $oDb->trans_begin();
        try {
            $oDb->set('is_primary', false);
            $oDb->where('user_id', $oEmail->user_id);
            $oDb->update($this->tableEmail);

            $oDb->set('is_primary', true);
            $oDb->where('id', $oEmail->id);
            $oDb->update($this->tableEmail);

            $this->unsetCacheUser($oEmail->user_id);

            //  Update the activeUser
            if ($oEmail->user_id == $this->activeUser('id')) {

                $oDate                         = Factory::factory('DateTime');
                $this->activeUser->last_update = $oDate->format('Y-m-d H:i:s');

                //  @todo: update the rest of the activeUser
            }

            $oDb->trans_commit();
            return true;

        } catch (\Exception $e) {
            $this->setError('Failed to set primary email. ' . $e->getMessage());
            $oDb->trans_rollback();
            return false;
        }

    }
public function emailMakePrimary($mIdEmail, $iUserId = null)
    {
        //  Fetch email
        $oDb = Factory::service('Database');
        $oDb->select('id,user_id,email');

        if (is_numeric($mIdEmail)) {
            $oDb->where('id', $mIdEmail);
        } else {
            $oDb->where('email', $mIdEmail);
        }

        if (!is_null($iUserId)) {
            $oDb->where('user_id', $iUserId);
        }

        $oEmail = $oDb->get($this->tableEmail)->row();

        if (empty($oEmail)) {
            return false;
        }

        //  Update
        $oDb->trans_begin();
        try {
            $oDb->set('is_primary', false);
            $oDb->where('user_id', $oEmail->user_id);
            $oDb->update($this->tableEmail);

            $oDb->set('is_primary', true);
            $oDb->where('id', $oEmail->id);
            $oDb->update($this->tableEmail);

            $this->unsetCacheUser($oEmail->user_id);

            //  Update the activeUser
            if ($oEmail->user_id == $this->activeUser('id')) {

                $oDate                         = Factory::factory('DateTime');
                $this->activeUser->last_update = $oDate->format('Y-m-d H:i:s');

                //  @todo: update the rest of the activeUser
            }

            $oDb->trans_commit();
            return true;

        } catch (\Exception $e) {
            $this->setError('Failed to set primary email. ' . $e->getMessage());
            $oDb->trans_rollback();
            return false;
        }

    }
public function emailMakePrimary ( $ mIdEmail , $ iUserId = null ) { //  Fetch email $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> select ( 'id,user_id,email' ) ; if ( is_numeric ( $ mIdEmail ) ) { $ oDb -> where ( 'id' , $ mIdEmail ) ; } else { $ oDb -> where ( 'email' , $ mIdEmail ) ; } if ( ! is_null ( $ iUserId ) ) { $ oDb -> where ( 'user_id' , $ iUserId ) ; } $ oEmail = $ oDb -> get ( $ this -> tableEmail ) -> row ( ) ; if ( empty ( $ oEmail ) ) { return false ; } //  Update $ oDb -> trans_begin ( ) ; try { $ oDb -> set ( 'is_primary' , false ) ; $ oDb -> where ( 'user_id' , $ oEmail -> user_id ) ; $ oDb -> update ( $ this -> tableEmail ) ; $ oDb -> set ( 'is_primary' , true ) ; $ oDb -> where ( 'id' , $ oEmail -> id ) ; $ oDb -> update ( $ this -> tableEmail ) ; $ this -> unsetCacheUser ( $ oEmail -> user_id ) ; //  Update the activeUser if ( $ oEmail -> user_id == $ this -> activeUser ( 'id' ) ) { $ oDate = Factory :: factory ( 'DateTime' ) ; $ this -> activeUser -> last_update = $ oDate -> format ( 'Y-m-d H:i:s' ) ; //  @todo: update the rest of the activeUser } $ oDb -> trans_commit ( ) ; return true ; } catch ( \ Exception $ e ) { $ this -> setError ( 'Failed to set primary email. ' . $ e -> getMessage ( ) ) ; $ oDb -> trans_rollback ( ) ; return false ; } }
Sets an email address as the primary email address for that user.

@param mixed   $mIdEmail The numeric  ID of the email address, or the email address itself
@param integer $iUserId  Specify the user ID which this should apply to

@return boolean
Sets an email address as the primary email address for that user .