AvatarModel::deleteAvatar PHP Метод

deleteAvatar() публичный статический Метод

Delete a user's avatar
public static deleteAvatar ( integer $userId ) : boolean
$userId integer
Результат boolean success
    public static function deleteAvatar($userId)
    {
        if (!ctype_digit($userId)) {
            Session::add("feedback_negative", Text::get("FEEDBACK_AVATAR_IMAGE_DELETE_FAILED"));
            return false;
        }
        // try to delete image, but still go on regardless of file deletion result
        self::deleteAvatarImageFile($userId);
        $database = DatabaseFactory::getFactory()->getConnection();
        $sth = $database->prepare("UPDATE users SET user_has_avatar = 0 WHERE user_id = :user_id LIMIT 1");
        $sth->bindValue(":user_id", (int) $userId, PDO::PARAM_INT);
        $sth->execute();
        if ($sth->rowCount() == 1) {
            Session::set('user_avatar_file', self::getPublicUserAvatarFilePathByUserId($userId));
            Session::add("feedback_positive", Text::get("FEEDBACK_AVATAR_IMAGE_DELETE_SUCCESSFUL"));
            return true;
        } else {
            Session::add("feedback_negative", Text::get("FEEDBACK_AVATAR_IMAGE_DELETE_FAILED"));
            return false;
        }
    }

Usage Example

Пример #1
0
 /**
  * Delete the current user's avatar
  * Auth::checkAuthentication() makes sure that only logged in users can use this action and see this page
  */
 public function deleteAvatar_action()
 {
     Auth::checkAuthentication();
     AvatarModel::deleteAvatar(Session::get("user_id"));
     Redirect::to('login/editAvatar');
 }
All Usage Examples Of AvatarModel::deleteAvatar