public function destroy($id) { $clockin = UserClockin::find($id); $clockin->delete(); }
/** * Returns an array of merged events from both the * Practices & Bouts and Activities & Events calendars * * @param App\Services\GoogleCalendar $calendar * @return array */ public function clockin(Request $request, GoogleCalendar $calendar) { // thanks page if (stripos($request->path(), 'thanks')) { return view('clock-in-thanks'); // clock in page } else { // save the clockin if ($request->isMethod('post')) { $input = $request->all(); $userId = User::where('clock_number', $input['clock_number'])->pluck('id'); $selectedEvent = explode(' :: ', $input['event_type']); $eventDetails = explode(' | ', $selectedEvent[1]); $calDate = $selectedEvent[0]; $calTime = $eventDetails[0]; $times = explode(' - ', $calTime); $startTime = $times[0]; $endTime = $times[1]; $eventDateStartTime = $calDate . ' ' . $startTime; $clockedTimeString = strtotime($input['clock_time']); $eventStartTimeString = strtotime($eventDateStartTime); $event = explode(': ', $eventDetails[1]); $type = $event[0]; $calendarName = $event[1]; $data = array('user_id' => $userId, 'clock_number' => $input['clock_number'], 'type' => strtolower($type), 'calendar_name' => $calendarName, 'calendar_date' => $this->formatDateTime($eventDateStartTime), 'calendar_time' => $this->formatDateTime($eventDateStartTime, 'time'), 'clocked' => $this->formatDateTime($input['clock_time'], 'datetime')); // late clockins do not make a clockin invalid // mark late if user marked late OR if not marked late but same day and > 5 min or < 15 min late if (isset($input['late_reason'])) { $data['late_clockin'] = 1; $data['late_clockin_note'] = $input['late_reason']; if (isset($input['late_reason_other'])) { $data['late_clockin_note'] .= ': ' . $data['late_other_reason']; } } $data['invalid'] = false; // user marked as late if (isset($input['late_reason']) && $input['late_reason'] === 'Late') { $data['invalid_desc'] = 'Clock-in marked as late by member.'; $data['invalid'] = true; } // 15+ minutes past start time if (!isset($input['late_reason']) && round(abs($clockedTimeString - $eventStartTimeString) / 60, 2) > 15) { $data['invalid_desc'] = 'Clock-in was 15+ minutes after practice with no late reason selected.'; $data['invalid'] = true; } // clocking in for last hour; need full two hours to count as valid scrimmage if ($type === 'scrimmage' && $startTime === '08:40PM') { $data['invalid_desc'] = 'Clock-in was for last hour of scrimmage.'; $data['invalid'] = true; } $duplicateClockins = UserClockin::where('user_id', '=', $data['user_id'])->where('clock_number', '=', $data['clock_number'])->where('type', '=', $data['type'])->where('calendar_name', '=', $data['calendar_name'])->where('calendar_date', '=', $data['calendar_date'])->where('invalid', '=', false)->get(); // check if a duplicate clockin exists if (count($duplicateClockins) > 0) { $data['duplicate'] = true; // also need to update USER_REQUIREMENTS count } else { $req = UserRequirement::where('user_id', '=', $data['user_id'])->where('year', '=', date('Y'))->where('quarter', '=', $this->currentQtr())->first(); // if user requirements do not exist, create a record if (empty($req)) { $newUserReq = new UserRequirement(); $newUserReq->user_id = $data['user_id']; $newUserReq->year = date('Y'); $newUserReq->quarter = $this->currentQtr(); $newUserReq->practice_count = 0; $newUserReq->scrimmage_count = 0; $newUserReq->activity_count = 0; $newUserReq->facility_count = 0; $newUserReq->bout_count = 0; $newUserReq->committee_count = 0; $newUserReq->min_practice = null; $newUserReq->min_scrimmage = null; $newUserReq->min_activity = null; $newUserReq->min_facility = null; $newUserReq->min_bout = null; $newUserReq->min_committee = null; $newUserReq->save(); // otherwise, update the user requirements count } else { switch ($data['type']) { case 'practice': $req->practice_count++; break; case 'scrimmage': $req->practice_count++; $req->scrimmage_count++; break; case 'activity': $req->activity_count++; break; case 'event': $req->event_count++; break; case 'bout': $req->bout_count++; break; case 'facility': $req->facility_count++; break; } $req->save(); } } // end duplicate clockin $clockin = new UserClockin(); $clockin->fill($data); $clockin->save(); return redirect('clock-in/thanks'); } return view('clock-in'); } // end "thanks" check }