/**
  * @param City $city
  * @param $slot_num
  * @return $this|bool
  */
 public function buildingCompleted($building_id)
 {
     $building = Building::where('id', $building_id)->first();
     if (!$building) {
         return false;
     }
     if ($building->finished_at->gte(Carbon::now())) {
         return false;
     }
     return $building;
 }
 public function getBuilding($id)
 {
     $building = \App\Building::where('street_id', $id)->orderBy('number')->orderBy('housing')->get();
     $data = [];
     foreach ($building as $item) {
         $n = strval($item->number);
         if ($item->housing) {
             $n .= '/' . $item->housing;
         }
         array_push($data, ['id' => $item->id, 'title' => $n]);
     }
     return json_encode($data);
 }
Beispiel #3
0
 /**
  * Get the number of levels that a building has
  * @param $id
  * @return mixed
  */
 public function getLevelsCount($id)
 {
     return $this->building->where('id', '=', $id)->first()->levelsCount;
 }
Beispiel #4
0
 /**
  * Store a csv created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function import(Request $request)
 {
     if ($request->file('csv-file')->isValid()) {
         $csv_file = $request->file('csv-file');
         if ("text/csv" == $csv_file->getClientMimeType()) {
             $dest_path = storage_path('temp');
             $file_name = time() . '_' . str_replace(" ", "_", $csv_file->getClientOriginalName());
             $csv_file->move($dest_path, $file_name);
             $fname = $dest_path . '/' . $file_name;
             $file = fopen($fname, "r");
             $flash_message = [];
             $flash_error = 0;
             while (!feof($file)) {
                 $tmp_data = fgetcsv($file);
                 $item['building_id'] = !empty($tmp_data[0]) ? $tmp_data[0] : '';
                 $building = Building::where('code', '=', $item['building_id'])->first();
                 if ($building) {
                     $item['building_id'] = $building->id;
                 }
                 $item['code'] = !empty($tmp_data[1]) ? $tmp_data[1] : '';
                 $item['name'] = !empty($tmp_data[2]) ? $tmp_data[2] : '';
                 $item['capacity'] = !empty($tmp_data[3]) ? $tmp_data[3] : '0';
                 $item['feature_id'] = !empty($tmp_data[4]) ? $tmp_data[4] : '1';
                 $v = Validator::make($item, ['building_id' => 'required|integer', 'code' => 'required|unique:rooms|max:20', 'name' => 'required|max:254', 'capacity' => 'integer|min:5', 'feature_id' => 'integer|min:1']);
                 if (!$v->fails()) {
                     Room::create($item);
                     $flash_message['success'][] = '[' . $item['code'] . '] ' . $item['name'];
                 } else {
                     $flash_error++;
                     $flash_message['error'] = $flash_error;
                 }
             }
             \Session::flash('flash_message', $flash_message);
             fclose($file);
             chmod($fname, 0777);
             unlink($fname);
         }
     }
     return redirect('/rooms');
 }