本文整理匯總了PHP中app\Activity::whereIn方法的典型用法代碼示例。如果您正苦於以下問題:PHP Activity::whereIn方法的具體用法?PHP Activity::whereIn怎麽用?PHP Activity::whereIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Activity
的用法示例。
在下文中一共展示了Activity::whereIn方法的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'));
}
}