public function login() { $bp = BusinessPlan::orderBy('created', 'desc')->first()->id; $link = "businessplan/"; $link .= strval($bp); if (Auth::guest()) { return view('auth/login'); } else { return redirect($link); } }
public function index(Request $request) { if ($request->bp) { $currentBp = BusinessPlan::find($request->bp); } else { $currentBp = BusinessPlan::where('start', '<=', Carbon::now())->where('end', '>=', Carbon::now())->first(); if (!$currentBp) { $currentBp = BusinessPlan::all()->last(); } } $sorted = Goat::where('bid', $currentBp->id)->where('type', 'G')->orderBy('goal_type')->orderBy('description')->get(); $bp = Goat::where('bid', $currentBp->id)->where('type', '<>', 'G')->orderByRaw("FIELD(type, 'O', 'A', 'T')")->orderBy('description', 'desc')->get(); foreach ($bp as $goat) { if ($goat->type === 'G') { $sorted->push($goat); continue; } for ($i = 0, $len = $sorted->count(); $i < $len; $i++) { if ($sorted[$i]->id == $goat->parent_id) { // Hacky fix since when you splice $goat into $sorted, // it converts the $goat into an array instead of // keeping it as a Model object... $sorted->splice($i + 1, 0, "temp"); $sorted->put($i + 1, $goat); break; } } } $leadOf = array(); if (Auth::user()) { foreach (Auth::user()->leadOf as $dept) { array_push($leadOf, $dept->id); } } $collaboratorGoals = array(); foreach ($leadOf as $dept_id) { foreach (Department::find($dept_id)->collaboratorOn as $goat) { array_push($collaboratorGoals, $goat->id); } } return view('view_plan')->with(['bp' => $sorted, 'users' => User::orderBy('first_name')->get(), 'depts' => Department::orderBy('name')->get(), 'leadOf' => $leadOf, 'plans' => BusinessPlan::orderBy('id', 'desc')->get(), 'query' => $request, 'bp_id' => $currentBp->id, 'is_bplead' => Auth::user() && Auth::user()->is_bplead, 'collaboratorGoals' => $collaboratorGoals]); }