当前位置: 首页>>代码示例>>PHP>>正文


PHP User::activities方法代码示例

本文整理汇总了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;
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:60,代码来源:ActivityTypeBase.php


注:本文中的RainLab\User\Models\User::activities方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。