本文整理汇总了PHP中RainLab\User\Models\User::activities方法的典型用法代码示例。如果您正苦于以下问题:PHP User::activities方法的具体用法?PHP User::activities怎么用?PHP User::activities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::activities方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canComplete
/**
* Determine if an activity is capable of being completed
*
* @param Activity
* An activity model
*
* @return boolean
* returns true if an activity can be completed by the user
*/
public static function canComplete(Activity $activity, User $user)
{
if (!$activity->isActive()) {
return false;
}
// Check activity lockout
if ($activity->activity_lockout && ($pivot = $user->activities()->where('activity_id', $activity->id)->first())) {
$time = Carbon::now();
$lastTime = $pivot->pivot->created_at;
if ($time->diffInMinutes($lastTime) < $activity->activity_lockout) {
$x = $time->diffInMinutes($lastTime->addMinutes($activity->activity_lockout));
$message = self::convertToHoursMins($x, '%d hours and %02d minutes');
Session::put('activityError', Lang::get('dma.friends::lang.activities.lockout', ['x' => $message]));
return false;
}
}
switch ($activity->time_restriction) {
case Activity::TIME_RESTRICT_NONE:
return true;
case Activity::TIME_RESTRICT_HOURS:
if ($activity->time_restriction_data) {
$now = Carbon::now();
$start = self::convertTime($activity->time_restriction_data['start_time']);
$end = self::convertTime($activity->time_restriction_data['end_time']);
$start_time = Carbon::now();
$start_time->setTime($start['hour'], $start['minutes']);
$end_time = Carbon::now();
$end_time->setTime($end['hour'], $start['minutes']);
$day = date('w');
// Sunday is on the end of the week and date sets sunday as 0
if ($day == 0) {
$day = 7;
}
if ($activity->time_restriction_data['days'][$day] !== false && $now->gte($start_time) && $now->lte($end_time)) {
return true;
} else {
Session::put('activityError', Lang::get('dma.friends::lang.activities.notAvailable'));
}
}
break;
case Activity::TIME_RESTRICT_DAYS:
$now = new DateTime('now');
if ($now >= $activity->date_begin && $now <= $activity->date_end) {
return true;
} else {
Session::put('activityError', Lang::get('dma.friends::lang.activities.notAvailable'));
}
break;
}
return false;
}