本文整理汇总了PHP中RainLab\User\Models\User::steps方法的典型用法代码示例。如果您正苦于以下问题:PHP User::steps方法的具体用法?PHP User::steps怎么用?PHP User::steps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::steps方法的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'));
}
}