public function listCheck($day, $room, $page) { $pagelen = 20; $day = Carbon::parse($day)->format('Y-m-d'); $startDate = date("Y-m-d H:i:s", strtotime($day)); $stopDate = date("Y-m-d H:i:s", strtotime($day . " 23:59:59")); $total_row = Cards::select(DB::raw('COUNT(*) as count'))->where('room_id', '=', $room)->get(); $total_page = ceil((int) $total_row[0]->count / $pagelen); $start = ($page - 1) * $pagelen; $cards = Cards::with("room")->where('room_id', '=', $room)->skip($start)->take($pagelen)->get(); $shows = Logs::with("card")->where('room_id', '=', $room)->whereBetween('access', array($startDate, $stopDate))->groupBy('card_id')->get(); $status = true; return compact("shows", "day", "cards", "status", "total_page"); }
public function store_log(Request $request) { $valid = Validator::make($request->all(), ['file' => 'required|mimes:txt']); if ($valid->fails()) { $error = $valid->errors()->all(); return $error; } if ($request->hasFile('file')) { $files = $request->file('file'); $mime = $files->getClientMimeType(); $path = $files->getRealPath(); $room = $request->input('room'); if ($room == 1) { if ($mime == "text/plain") { $contents = file($files->getRealPath()); for ($i = 1; $i < count($contents); $i++) { $tmp = preg_split("/\\s+/", $contents[$i]); $date = $tmp[3] . " " . $tmp[4]; $date = str_replace('/', '-', $date); $date = date("Y-m-d H:i:s", strtotime($date)); $log = Logs::where('access', '=', $date)->get(); if ($log->isEmpty()) { $query = Cards::where('card_id', '=', $tmp[2])->where('room_id', '=', $room)->get(); $log = new Logs(); $log->card_id = $query[0]->id; $log->room_id = $room; $log->date = date("d-m-Y", strtotime($date)); $log->access = $date; $log->save(); } } return "true"; } else { if ($mime == "text/csv") { $open = fopen($path, "r"); $tmp = 0; while (!empty($data = fgetcsv($open))) { if ($tmp != 0) { $data[3] = str_replace('/', '-', $data[3]); $date = date("Y-m-d H:i:s", strtotime($data[3])); $log = Logs::where('access', '=', $date)->get(); if ($log->isEmpty()) { $query = Cards::where('card_id', '=', $data[2])->where('room_id', '=', $room)->get(); $log = new Logs(); $log->card_id = $query[0]->id; $log->room_id = $room; $log->date = date("d-m-Y", strtotime($data[3])); $log->access = $date; $log->save(); } } $tmp = 1; } fclose($open); return "true"; } } } else { if ($room == 2) { $contents = file($files->getRealPath()); for ($i = 1; $i < count($contents); $i++) { $tmp = explode("\t", $contents[$i]); $log = Logs::where('access', '=', $tmp[9])->get(); if ($log->isEmpty()) { if ($tmp[2] != '00000000') { $query = Cards::where('card_id', '=', $tmp[2])->where('room_id', '=', $room)->get(); $log = new Logs(); $log->card_id = $query[0]->id; $log->room_id = $room; $log->date = date("d-m-Y", strtotime($tmp[9])); $log->access = $tmp[9]; $log->save(); } } } return "true"; } } } return "Error"; }
/** * Display a listing of the resource. * * @return Response */ public function index() { $cards = Cards::all(); return $cards; }