當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。