/** * 列出教学计划 * @author FuRongxin * @date 2016-02-04 * @version 2.0 * @return JSON 教学计划列表 */ public function listing() { $plans = Plan::with(['platform' => function ($query) { $query->select('dm', 'mc'); }])->with(['property' => function ($query) { $query->select('dm', 'mc'); }])->with(['course' => function ($query) { $query->select('kch', 'kcmc', 'kcywmc'); }])->with(['mode' => function ($query) { $query->select('dm', 'mc'); }])->with(['college' => function ($query) { $query->select('dw', 'mc'); }])->whereNj(Auth::user()->profile->nj)->whereZy(Auth::user()->profile->zy)->whereZsjj(Auth::user()->profile->zsjj)->orderBy('kch', 'asc'); return Datatables::of($plans)->addColumn('zxs', '{{ $llxs + $syxs }}')->make(true); }
/** * 列出选课情况交叉比较信息 * @author FuRongxin * @date 2016-05-13 * @version 2.1 * @return \Illuminate\Http\Response 选课交叉比较信息 */ public function match() { $credits = []; $plan_total = 0; $selected_total = 0; $score_total = 0; // 获取教学计划学分 $plans = Plan::with(['course' => function ($query) { $query->select('kch', 'kcmc', 'kcywmc'); }])->whereNj(Auth::user()->profile->nj)->whereZy(Auth::user()->profile->zy)->whereZsjj(Auth::user()->profile->zsjj)->orderBy('kch', 'asc')->get(); foreach ($plans as $plan) { $credits[$plan->kch] = ['kch' => $plan->kch, 'kcmc' => $plan->course->kcmc, 'plan_credit' => $plan->zxf, 'selected_credit' => 0, 'score_credit' => 0]; $plan_total += $plan->zxf; } // 获取选课学分 $selects = Selcourse::with(['course' => function ($query) { $query->select('kch', 'kcmc', 'kcywmc'); }])->whereXh(Auth::user()->xh)->orderBy('kch', 'asc')->get(); foreach ($selects as $select) { if (array_key_exists($select->kch, $credits)) { $credits[$select->kch]['selected_credit'] = $select->xf; } else { $credits[$select->kch] = ['kch' => $select->kch, 'kcmc' => $select->course->kcmc, 'plan_credit' => 0, 'selected_credit' => $select->xf, 'score_credit' => 0]; } $selected_total += $select->xf; } // 获取成绩学分 $scores = Score::with(['course' => function ($query) { $query->select('kch', 'kcmc', 'kcywmc'); }])->whereXh(Auth::user()->xh)->orderBy('kch', 'asc')->get(); foreach ($scores as $score) { if (array_key_exists($score->kch, $credits)) { $credits[$score->kch]['score_credit'] = $score->xf; } else { $credits[$select->kch] = ['kch' => $score->kch, 'kcmc' => $score->course->kcmc, 'plan_credit' => 0, 'selected_credit' => 0, 'score_credit' => $score->xf]; } $score_total += $score->xf; } $title = '选课学分交叉对比表'; return view('course.match', compact('title', 'credits', 'plan_total', 'selected_total', 'score_total')); }
/** * Remove a resource from a plan * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function destroy(Request $request, $plan_id, $res_id) { // check access rights if (!Auth::user()->ownsPlan($plan_id)) { return redirect('home')->with('error', 'You are unauthorized for this request.'); } // get current plan $plan = Plan::with('resources')->find($plan_id); // see if this was a submit with a new team member request if ($plan) { // check if res is actually attached to plan if ($plan->resources()->where('id', $res_id)) { // now we can remove the resource from the Plan $plan->resources()->detach($res_id, ['comment' => $request->has('comment') ? $request->get('comment') : '']); $status = 'Resource removed from the plan.'; return \Redirect::route('resource.index', ['plan_id' => $plan_id])->with(['status' => $status]); } $status = 'Resource was now attached to this plan!'; return \Redirect::route('resource.index', ['plan_id' => $plan_id])->with(['status' => $status]); } $error = 'Wrong plan id!'; return \Redirect::back()->with(['error' => $error]); }
/** * Display single items of a plan with options to move to the next or previous item on this plan * * This is used for the presentation views (lyrics, chords, sheetmusic or leader) * * @param int $id item id * @param string $present (optional) chords (default), sheetmusic or present (for overhead presentations) or leader for the Leader's Event Script * * @return \Illuminate\Http\Response */ public function show($id, $present = null) { $item = Item::find($id); if ($item) { $events = []; // is this the Announcements Slide? if ($item->key == 'announcements') { $today = new Carbon($item->plan->date); $oneWeek = $today->addDays(7); // get ALL future events incl today $events = Plan::with(['type', 'leader', 'teacher'])->whereDate('date', '>', $item->plan->date->subDay())->whereDate('date', '<', $oneWeek)->where('id', '!=', $item->plan_id)->orderBy('date', 'asc')->get(); } // default presentation type is to show chords if (!$present) { $present = 'chords'; } return view('cspot.' . $present, ['item' => $item, 'events' => $events, 'versionsEnum' => json_decode(env('BIBLE_VERSIONS')), 'items' => $item->plan->items->sortBy('seq_no')->all(), 'type' => $present, 'bibleTexts' => getBibleTexts($item->comment)]); } flashError('Error! Item with ID "' . $id . '" was not found! (F:show)'); return \Redirect::route('home'); }
/** * Edit a single team member of a plan * * @return \Illuminate\Http\Response */ public function edit($plan_id, $id) { // get current plan $plan = Plan::with('teams')->find($plan_id); // check access rights if (!Auth::user()->ownsPlan($plan_id)) { return redirect('home')->with('error', 'You are unauthorized for this request.'); } // get list of users $users = User::where('name', '<>', 'n/a')->orderBy('first_name')->get(); // get the resource handle $team = Team::find($id); if ($team) { return view('cspot.team', ['team' => $team, 'plan' => $plan, 'users' => $users, 'userRoles' => json_encode(getUsersRolesAndInstruments())]); } $error = 'Wrong team member id!'; return \Redirect::back()->with(['error' => $error]); }
/** * PLAN DETAILS form * * @param int $id * @param int $new_item_id indicates a newly inserted item * @return \Illuminate\Http\Response */ public function edit($id) { // find a single plan by ID $plan = Plan::with(['items' => function ($query) { $query->withTrashed()->orderBy('seq_no'); }])->find($id); if ($plan) { // get list of service types $types = Type::get(); // get list of users $users = User::orderBy('first_name')->get(); // get list of trashed items (if any) $trashedItemsCount = Item::onlyTrashed()->where('plan_id', $id)->count(); // check if a new item was just now inserted (used for highlighing in the view) $newest_item_id = 0; if (session()->has('newest_item_id')) { $newest_item_id = session()->get('newest_item_id'); session()->forget('newest_item_id'); } // get service times from plan dates $plan->start = Carbon::instance($plan->date)->toTimeString(); // for backwards compatibility, we allowed for null as end date if ($plan->date_end) { $plan->end = Carbon::instance($plan->date_end)->toTimeString(); } else { $plan->end = "23:59"; } return view($this->view_one, array('plan' => $plan, 'types' => $types, 'users' => $users, 'versionsEnum' => json_decode(env('BIBLE_VERSIONS')), 'newest_item_id' => $newest_item_id, 'trashedItemsCount' => $trashedItemsCount)); } flashError('Plan with id "' . $id . '" not found'); return \Redirect::route($this->view_idx); }