當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::badges方法代碼示例

本文整理匯總了PHP中RainLab\User\Models\User::badges方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::badges方法的具體用法?PHP User::badges怎麽用?PHP User::badges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在RainLab\User\Models\User的用法示例。


在下文中一共展示了User::badges方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: completeBadge

 /**
  * Complete the step and proceed to complete a badge if it can be completed
  *
  * @param Step $step
  * A step model
  * @param User $user
  * A user model
  */
 private static function completeBadge(Step $step, User $user)
 {
     $badge = $step->badge;
     // Check badge global limit
     if ($badge->maximum_earnings_global > 0 && count($badge->users) > $badge->maximum_earnings_global) {
         return false;
     }
     // Complete step
     try {
         $user->steps()->save($step);
         Event::fire('dma.friends.step.completed', [$step, $user]);
     } catch (Exception $e) {
         throw new Exception(Lang::get('dma.friends::lang.exceptions.stepFailed'));
     }
     // See if the user has completed all steps for a badge
     foreach ($badge->steps as $step) {
         if (!$user->steps->contains($step->id)) {
             //user did not complete a step in badge so we cannot complete the badge
             return;
         }
     }
     try {
         // If loop completes with out returning false the user has completed all steps
         $user->badges()->save($badge);
         $userExtend = new UserExtend($user);
         $userExtend->addPoints($badge->points);
         Event::fire('dma.friends.badge.completed', [$badge, $user]);
         // log an entry to the activity log
         FriendsLog::unlocked(['user' => $user, 'object' => $badge]);
         if ($badge->congratulations_text) {
             $notificationText = $badge->congratulations_text;
         } else {
             $notificationText = Lang::get('dma.friends::lang.badges.completed', ['title' => $badge->title]);
         }
         //Flash::info($notificationText);
         Postman::send('simple', function (NotificationMessage $notification) use($user, $badge, $notificationText) {
             // Set user
             $notification->to($user, $user->name);
             // Send code and activity just in case we want to use in the template
             $notification->addData(['badge' => $badge]);
             $notification->message($notificationText);
         }, ['flash', 'kiosk']);
     } catch (Exception $e) {
         throw new Exception(Lang::get('dma.friends::lang.exceptions.badgeFailed'));
     }
 }
開發者ID:janusnic,項目名稱:OctoberFriends,代碼行數:54,代碼來源:BadgeManager.php


注:本文中的RainLab\User\Models\User::badges方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。