UserRoleModel::changeUserRole PHP Méthode

changeUserRole() public static méthode

Upgrades / downgrades the user's account. Currently it's just the field user_account_type in the database that can be 1 or 2 (maybe "basic" or "premium"). Put some more complex stuff in here, maybe a pay-process or whatever you like.
public static changeUserRole ( $type ) : boolean
$type
Résultat boolean
    public static function changeUserRole($type)
    {
        if (!$type) {
            return false;
        }
        // save new role to database
        if (self::saveRoleToDatabase($type)) {
            Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_TYPE_CHANGE_SUCCESSFUL'));
            return true;
        } else {
            Session::add('feedback_negative', Text::get('FEEDBACK_ACCOUNT_TYPE_CHANGE_FAILED'));
            return false;
        }
    }

Usage Example

 /**
  * Perform the account-type changing
  * Auth::checkAuthentication() makes sure that only logged in users can use this action
  * POST-request
  */
 public function changeUserRole_action()
 {
     Auth::checkAuthentication();
     if (Request::post('user_account_upgrade')) {
         // "2" is quick & dirty account type 2, something like "premium user" maybe. you got the idea :)
         UserRoleModel::changeUserRole(2);
     }
     if (Request::post('user_account_downgrade')) {
         // "1" is quick & dirty account type 1, something like "basic user" maybe.
         UserRoleModel::changeUserRole(1);
     }
     Redirect::to('login/changeUserRole');
 }