本文整理汇总了PHP中app\Activity::groupBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Activity::groupBy方法的具体用法?PHP Activity::groupBy怎么用?PHP Activity::groupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Activity
的用法示例。
在下文中一共展示了Activity::groupBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: retrieveFilter
/**
* Retrieves the filters for activity search.
*
* @param \Illuminate\Http\Request $request
* @return JSON array of filtered search with activity IDs
*/
public function retrieveFilter(Request $request)
{
if ($request->get('filter') == null) {
$status = ["Missing parameter"];
return response()->json(compact('status'));
} else {
$filter = $request->get('filter');
if ($filter == 'start') {
if ($request->get('token') != null) {
$authenticatedUser = JWTAuth::setToken($request->get('token'))->authenticate();
$id = $authenticatedUser->volunteer_id;
$limit = $request->get('limit');
$approvedActivities = Activity::with('tasks')->whereHas('tasks', function ($query) {
$query->where('approval', 'like', 'approved');
})->lists('activity_id');
$appliedActivities = Task::Where('volunteer_id', '=', $id)->where(function ($query) {
$query->where('approval', '=', 'rejected')->orWhere('approval', '=', 'pending');
})->lists('activity_id');
$notApproved = Task::where('approval', '=', 'approved')->distinct()->lists('activity_id');
$activityList = Activity::whereNotIn('activity_id', $notApproved)->groupBy('location_from_id')->lists('location_from_id');
$toReturn = [];
foreach ($activityList as $location) {
$locationName = Centre::findOrFail($location)->name;
$locationList = Activity::where('datetime_start', '>', Carbon::now())->whereNotIn('activity_id', $approvedActivities)->whereNotIn('activity_id', $appliedActivities)->whereNotIn('activity_id', $notApproved)->where('location_from_id', $location)->distinct()->lists('activity_id');
if (!$locationList->isEmpty()) {
array_push($toReturn, ["location_from" => $locationName, "activity_ids" => implode(",", $locationList->toArray())]);
}
}
return response()->json($toReturn);
} else {
$notApproved = Task::where('approval', '=', 'approved')->distinct()->lists('activity_id');
$activityList = Activity::whereNotIn('activity_id', $notApproved)->groupBy('location_from_id')->lists('location_from_id');
$toReturn = [];
foreach ($activityList as $location) {
$locationName = Centre::findOrFail($location)->name;
$locationList = Activity::where('datetime_start', '>', Carbon::now())->whereNotIn('activity_id', $notApproved)->where('location_from_id', $location)->distinct()->lists('activity_id');
if (!$locationList->isEmpty()) {
array_push($toReturn, ["location_from" => $locationName, "activity_ids" => implode(",", $locationList->toArray())]);
}
}
return response()->json($toReturn);
}
} elseif ($filter == 'end') {
if ($request->get('token') != null) {
$authenticatedUser = JWTAuth::setToken($request->get('token'))->authenticate();
$id = $authenticatedUser->volunteer_id;
$limit = $request->get('limit');
$approvedActivities = Activity::with('tasks')->whereHas('tasks', function ($query) {
$query->where('approval', 'like', 'approved');
})->lists('activity_id');
$appliedActivities = Task::Where('volunteer_id', '=', $id)->where(function ($query) {
$query->where('approval', '=', 'rejected')->orWhere('approval', '=', 'pending');
})->lists('activity_id');
$notApproved = Task::where('approval', '=', 'approved')->distinct()->lists('activity_id');
$notcompleted = Task::where('status', '=', 'completed')->distinct()->lists('activity_id');
$activityList = Activity::groupBy('location_to_id')->lists('location_to_id');
$toReturn = [];
$locationNameString = "";
$locationIdString = "";
foreach ($activityList as $location) {
$locationName = Centre::findOrFail($location)->name;
//echo $location;
$notApproved = Task::where('approval', '=', 'approved')->distinct()->lists('activity_id');
$locationList = Activity::where('datetime_start', '>', Carbon::now())->whereNotIn('activity_id', $approvedActivities)->whereNotIn('activity_id', $appliedActivities)->where('location_to_id', $location)->whereNotIn('activity_id', $notApproved)->distinct()->lists('activity_id');
//$stringToTitle = 'location_to';
$stringToList = $locationName . ' ' . $locationList;
//$locationNameString = $locationNameString . ',' . $locationName;
//$locationIdString = $locationIdString . ',' . $locationList;
//$toReturn = array();
if (!$locationList->isEmpty()) {
array_push($toReturn, ["location_to" => $locationName, "activity_ids" => implode(",", $locationList->toArray())]);
}
}
return response()->json($toReturn);
} else {
$notApproved = Task::where('approval', '=', 'approved')->distinct()->lists('activity_id');
$notcompleted = Task::where('status', '=', 'completed')->distinct()->lists('activity_id');
$activityList = Activity::groupBy('location_to_id')->lists('location_to_id');
$toReturn = [];
$locationNameString = "";
$locationIdString = "";
foreach ($activityList as $location) {
$locationName = Centre::findOrFail($location)->name;
//echo $location;
$notApproved = Task::where('approval', '=', 'approved')->distinct()->lists('activity_id');
$locationList = Activity::where('datetime_start', '>', Carbon::now())->where('location_to_id', $location)->whereNotIn('activity_id', $notApproved)->distinct()->lists('activity_id');
//$stringToTitle = 'location_to';
$stringToList = $locationName . ' ' . $locationList;
//$locationNameString = $locationNameString . ',' . $locationName;
//$locationIdString = $locationIdString . ',' . $locationList;
//$toReturn = array();
if (!$locationList->isEmpty()) {
array_push($toReturn, ["location_to" => $locationName, "activity_ids" => implode(",", $locationList->toArray())]);
}
//.........这里部分代码省略.........