/
home
/
maktab
/
server
/
app
/
Http
/
Controllers
/
api
/
File Upload :
llllll
Current File: /home/maktab/server/app/Http/Controllers/api/ReportAttendanceController.php
<?php namespace App\Http\Controllers\api; use App\Http\Controllers\Controller; use App\Http\Controllers\InterfaceController; use App\Http\Controllers\SuperController; use App\Models\ReportStudentAttendance; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Str; class ReportAttendanceController extends SuperController { public $add; public function __construct(Request $request) { $str = Str::of($request->path())->contains('report/attendance/teacher'); if ($str){ $request->request->add(['type'=>'teacher']); } $this->add = (new Controller())->addToRequest($request); $request->request->add($this->add); $select = ['*',ReportStudentAttendance::$SELECT_DAJ]; parent::__construct(ReportStudentAttendance::class, [], $select); } public function getList(Request $request){ $query = ReportStudentAttendance::whereDate('date_at',$request->date_at) ->where('maktab_id',$this->add['maktab_id']); if ($request->type == 'student'){ $query->where('teacher_id',$this->add['teacher_id']) ->whereNull('type'); }else{ $query->whereNotNull('type'); } $query->select(['*',ReportStudentAttendance::$SELECT_DAJ]) ->orderBy('date_at','desc'); return response()->json($query->get()); } public function index(Request $request){ $query = ReportStudentAttendance::whereDate('date_at',$request->date_at) ->whereNull('type'); $search = ['title']; $select = ['*',ReportStudentAttendance::$SELECT_DAJ]; $query = (new InterfaceController())->index($request->all(),$search,$select,$query); return response()->json($query); } public function indexTeacher(Request $request){ $query = ReportStudentAttendance::whereDate('date_at',$request->date_at) ->whereNotNull('type'); $search = ['title']; $select = ['*',ReportStudentAttendance::$SELECT_DAJ]; $query = (new InterfaceController())->index($request->all(),$search,$select,$query); return response()->json($query); } public function listById(Request $request){ $query = ReportStudentAttendance::with(['studentAttendance'=>function($q)use($request){ return $q->where('student_id',$request->student_id); }])->whereHas('studentAttendance',function ($q)use ($request){ return $q->where('student_id',$request->student_id); })->select(['*',ReportStudentAttendance::$SELECT_DAJ]) ->whereNull('type') ->orderBy('date_at','desc') ->get(); return response()->json($query); } public function getListInDate(Request $request){ $start_at = Carbon::parse($request->start_at); $end_at = Carbon::parse($request->end_at); if ($request->type == 'teacher'){ $report = ReportStudentAttendance::where('date_at','>=',$start_at) ->where('date_at','<=',$end_at) ->where('maktab_id',$request->maktab_id) ->whereNotNull('type') ->distinct() ->get('date_at'); }else{ $report = ReportStudentAttendance::where('date_at','>=',$start_at) ->where('date_at','<=',$end_at) ->where('maktab_id',$request->maktab_id) ->where('teacher_id',$request->teacher_id) ->whereNull('type') ->distinct() ->get('date_at'); } return response()->json($report); } }
Copyright ©2k19 -
Hexid
|
Tex7ure