public function _list($page = 1, $searchString = null) { if (!empty($searchString)) { $ucionice = Ucionica::where('naziv', 'like', '%' . $searchString . '%')->orderBy('naziv'); } else { $ucionice = Ucionica::orderBy('naziv'); } if ($page != 1) { Paginator::setCurrentPage($page); } $ucionice = $ucionice->paginate(10); $v = View::make('Ucionica.list')->with('ucionice', $ucionice); if (Request::ajax()) { return $v->renderSections()['list']; } return $v; }
/** * Gets all reservations in specified day for all ucionice. * The key is the id of the ucionica, and the value is an array of * arrays with offset, span, rezervacija, boja and instruktor each. * @param int $day Offset from first day * @param int $week ISO week number * @param int $year year * @return array */ private static function RezervacijeForDay($day, $week, $year) { $time = new \DateTime(); $time->setTime(0, 0); $time->setISODate($year, $week, $day); $min = $time->format('Y-m-d H:i:s'); $max = $time->modify('+1 day')->format('Y-m-d H:i:s'); $rezervacije = \Rezervacija::with('mjera', 'predmet', 'instruktor')->whereBetween('pocetak_rada', array($min, $max))->get(); $ucionice = \Ucionica::orderBy('polozaj')->get(); $data = array(); foreach ($ucionice as $ucionica) { $data[$ucionica->id] = array('ucionica' => $ucionica); } foreach ($rezervacije as $r) { $pocetak = strtotime($r->pocetak_rada); $kraj = strtotime($r->kraj_rada); $key = $r->ucionica_id; $data[$key][] = array('offset' => (int) (((date('H', $pocetak) - \BaseController::START_HOUR) * 60 + date('i', $pocetak)) / 15), 'span' => (int) (($kraj - $pocetak) / 60 / 15), 'rezervacija' => $r->link(), 'extra' => $r->instruktor->link(), 'boja' => $r->instruktor->boja); } return $data; }