本文整理汇总了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'));
}
}