Beispiel #1
0
 public function index()
 {
     // main
     $newsGadget = new \Own\App\Standard\Gadget($this->app);
     $userGadget = new \Own\App\User\Gadget($this->app);
     $column1 = [];
     $column2 = [];
     $column1[] = $userGadget->status($this->player);
     if ($this->signedUser->getId() == 0) {
         $column1[] = $newsGadget->filteredList(3);
     } else {
         $tplBook = new Util\Template(Util\Template::MODULE, ['bus', 'book']);
         $column1[] = $tplBook->render('own-bookings-placeholder');
         $column1[] = $newsGadget->filteredList(2);
         if ($this->signedUser->getIsAdmin()) {
             $tplAdminBook = new Util\Template(Util\Template::MODULE, ['bus', 'book']);
             $options = [];
             $options['where'][] = 'status = 1';
             $courts = \Own\Bus\Court\Data::loadAll($options);
             $tplAdminBook->set('courts', $courts);
             $tplAdminBook->set('days', [1 => Util\Lang::lang('monday'), 2 => Util\Lang::lang('tuesday'), 3 => Util\Lang::lang('wednesday'), 4 => Util\Lang::lang('thursday'), 5 => Util\Lang::lang('friday'), 6 => Util\Lang::lang('saturday'), 0 => Util\Lang::lang('sunday')]);
             $column2[] = $tplAdminBook->render('admin-book');
         }
     }
     $column2[] = \Own\Bus\Book\Service::renderCalendar($this->player);
     return $this->response('tpl-default', ['title' => Util\Lang::lang('home')], 'layout-home', ['column1' => $column1, 'column2' => $column2]);
 }
Beispiel #2
0
 public function buildCourts()
 {
     $items = \Own\Bus\Court\Data::loadAll();
     $courts = \Own\Bus\MembershipCourt\Data::loadAllByMembershipId($this->getModel()->getId());
     $selectedValues = [];
     foreach ($courts as $court) {
         $selectedValues[] = $court->getCourtId();
     }
     return Util\Form::buildCheckboxList('court' . $this->unique, $items, 'id', 'title', $selectedValues);
 }
Beispiel #3
0
 public function adminBooking()
 {
     $isAllowed = Util\Auth::isAdminAuthorized($this->signedUser);
     $json = [];
     $json['result'] = \Rebond\Core\ResultType::ERROR;
     if (!$isAllowed) {
         $json['message'] = Util\Lang::lang('accessNonAuthorized');
         return json_encode($json);
     }
     $title = Util\Converter::toString('title', 'post');
     $color = Util\Converter::toString('color', 'post');
     $courtIds = Util\Converter::toArray('courtIds', 'post');
     $startDate = Util\Converter::toDate('startDate', 'post', new \DateTime());
     $endDate = Util\Converter::toDate('endDate', 'post', new \DateTime());
     $days = Util\Converter::toArray('days', 'post');
     $startTime = Util\Converter::toInt('startTime', 'post');
     $endTime = Util\Converter::toInt('endTime', 'post');
     $count = 0;
     // @todo validate param
     $json['startDate'] = $startDate->format('datetime');
     $json['endDate'] = $endDate->format('datetime');
     $options = [];
     $options['where'][] = ['id IN (?)', $courtIds];
     $courts = \Own\Bus\Court\Data::loadAll($options);
     $book = new Book\Model();
     $book->setType(\Own\Bus\BookingType::ADMIN);
     $book->setTitle($title);
     $book->setSequence(uniqid());
     $book->setColor($color);
     $dateLoop = clone $startDate;
     $today = new \DateTime();
     $now = (int) $today->format('H') * 60 + (int) $today->format('i');
     $today->setTime(0, 0, 0);
     $rule = \Own\Bus\Rule\Data::loadById(1, true);
     $timeLength = $rule->getTimeLength();
     foreach ($courts as $court) {
         $book->setCourtId($court->getId());
         while ($dateLoop <= $endDate) {
             if ($dateLoop < $today) {
                 $dateLoop->add(new \DateInterval('P1D'));
                 continue;
             }
             if (!in_array($dateLoop->format('w'), $days)) {
                 $dateLoop->add(new \DateInterval('P1D'));
                 continue;
             }
             $possibleTime = (int) $court->getStartTime()->format('H') * 60 + (int) $court->getStartTime()->format('i');
             $limitTime = (int) $court->getEndTime()->format('H') * 60 + (int) $court->getEndTime()->format('i');
             while ($possibleTime < min($limitTime, $endTime)) {
                 if ($possibleTime >= $startTime && ($dateLoop != $today || $possibleTime >= $now)) {
                     $dateLoop->setTime(floor($possibleTime / 60), $possibleTime % 60, 0);
                     // check for court already booked
                     $options = [];
                     $options['where'][] = ['court_id = ?', $court->getId()];
                     $options['where'][] = ['booking_date = ?', $dateLoop->format('Y-m-d H:i:00')];
                     $booking = Book\Data::load($options);
                     if (!isset($booking)) {
                         $book->setBookingDate($dateLoop);
                         $book->save();
                         $book->setId(0);
                         $count++;
                     }
                 }
                 $dateLoop->setTime(0, 0, 0);
                 $possibleTime += $timeLength;
             }
             $dateLoop->add(new \DateInterval('P1D'));
         }
         $dateLoop = clone $startDate;
     }
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     $json['count'] = $count;
     return json_encode($json);
 }