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


PHP Activity::completed方法代码示例

本文整理汇总了PHP中app\Activity::completed方法的典型用法代码示例。如果您正苦于以下问题:PHP Activity::completed方法的具体用法?PHP Activity::completed怎么用?PHP Activity::completed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Activity的用法示例。


在下文中一共展示了Activity::completed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: graphInformation

 /**
  * Retrieves statistics of user activity for past months for user dashboard.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return  JSON  array with each month's hours and total hours and rank
  */
 public function graphInformation(Request $request)
 {
     if ($request->get('token') != null) {
         $authenticatedUser = JWTAuth::setToken($request->get('token'))->authenticate();
         $id = $authenticatedUser->volunteer_id;
         $volunteer = Volunteer::findOrFail($id);
         // four months
         $activitiesWithinFrame = Activity::completed()->subMonth(3)->lists('activities.activity_id');
         $fourMonthsUserList = Task::whereIn('activity_id', $activitiesWithinFrame)->where('volunteer_id', $id)->where('status', 'completed')->lists('activity_id');
         if ($fourMonthsUserList->isEmpty()) {
             $fourMonthsAgo = 0;
         } else {
             $fourMonthsAgo = Activity::whereIn('activity_id', $fourMonthsUserList)->sum('expected_duration_minutes');
             $fourMonthsAgo = floor($fourMonthsAgo / 60);
         }
         // three months
         $activitiesWithinFrame = Activity::completed()->subMonth(2)->lists('activities.activity_id');
         $threeMonthsUserList = Task::whereIn('activity_id', $activitiesWithinFrame)->where('volunteer_id', $id)->where('status', 'completed')->lists('activity_id');
         if ($threeMonthsUserList->isEmpty()) {
             $threeMonthsAgo = 0;
         } else {
             $threeMonthsAgo = Activity::whereIn('activity_id', $threeMonthsUserList)->sum('expected_duration_minutes');
             $threeMonthsAgo = floor($threeMonthsAgo / 60);
         }
         // two months
         $activitiesWithinFrame = Activity::completed()->subMonth(1)->lists('activities.activity_id');
         $twoMonthsUserList = Task::whereIn('activity_id', $activitiesWithinFrame)->where('volunteer_id', $id)->where('status', 'completed')->lists('activity_id');
         if ($twoMonthsUserList->isEmpty()) {
             $twoMonthsAgo = 0;
         } else {
             $twoMonthsAgo = Activity::whereIn('activity_id', $twoMonthsUserList)->sum('expected_duration_minutes');
             $twoMonthsAgo = floor($twoMonthsAgo / 60);
         }
         // one months
         $activitiesWithinFrame = Activity::completed()->subMonth(0)->lists('activities.activity_id');
         $oneMonthsUserList = Task::whereIn('activity_id', $activitiesWithinFrame)->where('volunteer_id', $id)->where('status', 'completed')->lists('activity_id');
         if ($oneMonthsUserList->isEmpty()) {
             $oneMonthAgo = 0;
         } else {
             $oneMonthAgo = Activity::whereIn('activity_id', $oneMonthsUserList)->sum('expected_duration_minutes');
             $oneMonthAgo = floor($oneMonthAgo / 60);
         }
         $rankid = Volunteer::where('volunteer_id', $id)->value('rank_id');
         $rank = Rank::findOrFail($rankid)->name;
         $totalHours = $volunteer->minutes_volunteered;
         $totalHours = floor($totalHours / 60);
         return response()->json(compact('fourMonthsAgo', 'threeMonthsAgo', 'twoMonthsAgo', 'oneMonthAgo', 'rank', 'totalHours'));
     } else {
         $status = ["Missing parameter"];
         return response()->json(compact('status'));
     }
 }
开发者ID:jonnylow,项目名称:CrowdSourcingApplicationWeb,代码行数:58,代码来源:VolunteerController.php


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