Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
public_html
/
admin
/
app
/
Http
/
Controllers
/
Api
/
V2
/
Filename :
V2BaseController.php
back
Copy
<?php namespace App\Http\Controllers\Api\V2; use App\Http\Controllers\Api\CommonController; use App\Http\Controllers\Controller; use App\Models\College; use App\Models\User; use App\V2\Resources\AttendanceResource; use App\V2\Services\AttendanceService; use App\V2\Services\CalendarService; use App\V2\Services\CommonService; class V2BaseController extends Controller{ protected $old_commonController; protected $commonService; private $attendanceService; private $calendarService; private $attendanceResource; function __construct() { $this->old_commonController = new CommonController(); $this->commonService = new CommonService(); } protected function getContextualDetails($request) { $currentUser = $request->user(); $currentStore = $this->old_commonController->getActiveStore($request); $currentGroup = $this->commonService->getActiveGroup($currentUser); $currentUser->populateTeamAndRole($currentGroup); return [$currentUser, $currentStore, $currentGroup]; } protected function getAttendanceService(): AttendanceService { if($this->attendanceService == null){ $this->attendanceService = new AttendanceService(); } return $this->attendanceService; } protected function getCalendarService() : CalendarService{ if($this->calendarService == null){ $this->calendarService = new CalendarService(); } return $this->calendarService; } protected function getAttendanceResource() : AttendanceResource{ if($this->attendanceResource == null){ $this->attendanceResource = new AttendanceResource(); } return $this->attendanceResource; } protected function getUserWiseCalendarAttendancesInGroup($group, $startDate, $endDate, $userIds = null){ if($userIds == null){ $userIds = $group->children()->map(function($child){ return $child->user_id; }); } $attendance_details = $this->getAttendanceService()->getCalendarAttendances($userIds, $group->group_id, $startDate, $endDate); $attendance_details_user_wise = []; foreach($attendance_details AS $user_id => $attendance_detail_summary){ $details = []; $user = User::where('user_id', $user_id)->first(); if($user != null){ // $college = $user->preferredCollege != null ? $user->preferredCollege : College::get()->first(); $school = $user->preferredSchool; $details['user_name'] = $user->full_name; $details['college'] = $school != null ? $school->school_name : ''; $details['attendance_summary'] = []; $details['attendance_summary']['present_num'] = $attendance_detail_summary['summary']['present_num']; $details['attendance_summary']['absent_num'] = $attendance_detail_summary['summary']['absent_num']; $details['attendance_summary']['holiday_num'] = $attendance_detail_summary['summary']['holiday_num']; $details['attendance_summary']['total_num'] = $attendance_detail_summary['summary']['total_num']; $details['attendance_summary']['summary_str'] = $attendance_detail_summary['summary']['summary_str']; $details['attendance'] = $this->getAttendanceResource()->fromAttendancesToArray($attendance_detail_summary['attendence'],false, false); } $attendance_details_user_wise [] = $details; } return $attendance_details_user_wise; } } ?>