-
app/Traits/PeriodSelection.php
Open in GitHubuse App\Models\Period; use Illuminate\Http\Request; trait PeriodSelection { public $currentPeriod; public function __construct() { if (Period::count() > 0) { $this->currentPeriod = Period::get_default_period()->id; } } protected function selectPeriod(Request $request) { $period_id = $request->query('period', null); if ($period_id == null) { $period = Period::get_default_period(); } else { $period = Period::find($period_id); } return $period; } }
-
app/Http/Controllers/HomeController.php
Open in GitHubuse App\Traits\PeriodSelection; use Illuminate\Http\Request; class HomeController extends Controller { use PeriodSelection; // public function teacher(Request $request) { if (! backpack_user()->isTeacher()) { abort(403); } $period = $this->selectPeriod($request); $teacher = Teacher::where('id', backpack_user()->id)->first(); Log::info($teacher->name.' accessed the student dashboard'); $remoteVolume = $teacher->courses()->whereNull('parent_course_id')->where('period_id', $period->id)->sum('remote_volume'); $presentialVolume = $teacher->courses()->whereNull('parent_course_id')->where('period_id', $period->id)->sum('volume'); return view('teacher.dashboard', [ 'teacher' => $teacher, 'courses' => $teacher->period_courses($period), 'pending_attendance' => $teacher->events_with_pending_attendance($period), 'selected_period' => $period, 'remoteVolume' => $remoteVolume, 'volume' => $presentialVolume, 'totalVolume' => $remoteVolume + $presentialVolume, ]); } // }