/** * Admin Dashboard Page * * @return mixed View Admin Dashboard Page */ public function dashboard() { $invalid_taxi_complaints = TaxiComplaint::getPaginated(0); $valid_taxi_complaints = TaxiComplaint::getPaginated(1); $taxi_complaints['unvalidated'] = $invalid_taxi_complaints; $taxi_complaints['validated'] = $valid_taxi_complaints; return view('admin.dashboard', compact('taxi_complaints')); }
/** * Send email to LTFRB support, cc to reporter, bcc to admin * * @param object $taxi_complaint TaxiComplaint report * * @return boolean true on success false on failure */ public static function sendMail(TaxiComplaint $taxi_complaint) { $taxi = $taxi_complaint->taxi(); $reporter = $taxi_complaint->user(); $violations = $taxi_complaint->violations(); $data = ['taxi' => $taxi, 'reporter' => $reporter, 'violations' => $violations, 'complaint' => $taxi_complaint]; $target_email = config('app.taxi_complaint_gov_email'); $target_name = config('app.taxi_complaint_gov_name'); $tc_admin_email = config('app.taxi_complaint_admin_email'); $tc_admin_name = config('app.taxi_complaint_app_name'); $message_data = ['reporter' => $reporter, 'target_email' => $target_email, 'target_name' => $target_name, 'tc_admin_email' => $tc_admin_email, 'tc_admin_name' => $tc_admin_name, 'plate_number' => $taxi->plate_number]; // send url for full details of the complaints $mail = Mail::later(5, 'emails.taxi-complaint', ['data' => $data], function ($message) use($message_data) { $message->to($message_data['target_email'], $message_data['target_name'])->from($message_data['reporter']->email, $message_data['reporter']->name)->cc($message_data['reporter']->email, $message_data['reporter']->name)->bcc($message_data['tc_admin_email'], $message_data['tc_admin_name'])->replyTo($message_data['reporter']->email, $message_data['reporter']->name)->subject('Taxi Complaint - Plate # : ' . $message_data['plate_number']); }); return $mail; }
/** * Get the unique reported taxi details * * @return object List of Taxi's */ public function taxis() { $taxis = []; $taxi_complaints = TaxiComplaint::where('created_by', $this->id)->get(); foreach ($taxi_complaints as $tc) { $taxis[] = $tc->taxi()->toArray(); } $taxis = $this->uniqueMultidimArray($taxis, 'id'); return $taxis; }
/** * Put: Send email report to LTFRB support * * @param object $request Send Mail Button from Dashboard * * @return json boolean true on success, false on failure */ public function sendMail(Request $request) { // generated, send email and update db record $taxi_complaint = TaxiComplaint::find($request->taxi_complaint_id); $mail = TaxiComplaint::sendMail($taxi_complaint); $taxi_complaint->mail_sent = $request->toggle; $taxi_complaint->save(); return response()->json(['data' => $mail, 200]); }
/** * Store Taxi and Report information to the database * If $user param is null, this will register the based on the form info. * If the reported taxi already exist on the database use it then create a report * If it doesn't exist yet, register this a new taxi then create a report * * @param object $request Request object from the form * @param object $user User object * * @return array Taxi information */ public static function store($request, $user) { $data = DB::transaction(function () use($request, $user) { // register the new user if (is_null($user)) { $user = new User(); $user->name = $request->full_name; $user->email = $request->email; $user->password = bcrypt($request->password); $user->contact_number = $request->contact_number; $user->save(); } $user_id = $user ? $user->id : 1; // user's id or admin $plate_number = self::sanitize($request->plate_number); // 1. find if it exist, if not create one // 2. if search result yielded more than 1 do a taxi search $taxi_search = self::search($plate_number); // use the existing taxi, if (count($taxi_search) === 1) { // todo: should we also update with the new data? $taxi = $taxi_search->first(); $taxi->description = $request->description; $taxi->save(); } else { if (count($taxi_search) === 0) { $taxi = new Taxi(); $taxi->plate_number = $plate_number; $taxi->name = $request->name; $taxi->description = $request->description; $taxi->save(); } else { return ['plate_number' => $plate_number]; } } if (!empty($request->incident_time)) { $incident_time = date('H:i:s', strtotime($request->incident_time)); } else { $incident_time = null; } $taxi_complaint = new TaxiComplaint(); $taxi_complaint->taxi_id = $taxi->id; $taxi_complaint->incident_date = $request->incident_date; $taxi_complaint->incident_time = $incident_time; $taxi_complaint->incident_location = $request->incident_location; $taxi_complaint->notes = $request->notes; $taxi_complaint->drivers_name = $request->drivers_name; $taxi_complaint->created_by = $user_id; $taxi_complaint->save(); foreach ($request->violations as $violation_id) { $taxi_violation = new TaxiViolation(); $taxi_violation->taxi_complaint_id = $taxi_complaint->id; $taxi_violation->violation_id = $violation_id; $taxi_violation->save(); } $path_prefix = 'images/uploads/' . $user_id; // this is the directory where to save the uploaded images $user_dir = public_path($path_prefix); if (!empty($request->taxi_pictures) && is_array($request->taxi_pictures)) { foreach ($request->taxi_pictures as $picture) { if (!is_null($picture) && $picture->isValid()) { //prepare the filename and url $fname = str_random(40); $ext = strtolower($picture->getClientOriginalExtension()); $filename = $fname . '.' . $ext; $file_uri = $path_prefix . '/' . $filename; // move the uploaded file to it's location $picture->move($user_dir, $filename); // save the url and new filename to db $taxi_picture = new TaxiPicture(); $taxi_picture->taxi_id = $taxi->id; // added taxi_complaint_id so that we could // track taxi physical changes $taxi_picture->taxi_complaint_id = $taxi_complaint->id; $taxi_picture->path = $file_uri; $taxi_picture->created_by = $user_id; $taxi_picture->save(); } } } return ['taxi_id' => $taxi->id]; }); // end db::transaction return $data; }