Example #1
0
 public function render(array $appData, $templateName, \Core\Application $app, \Core\Database $db, \DBMappers\RoomItem $roomMapper, \DBMappers\EmpItem $empMapper)
 {
     $current_room = $app->getCurrentRoom();
     if ($current_room === false) {
         $rooms = $roomMapper->getAll($db);
         $app->setCurrentRoom($rooms[0]->getId());
         $current_room = $app->getCurrentRoom();
     }
     $roomItem = $roomMapper->getById($current_room, $db);
     $emps = $empMapper->getAll($db);
     if (isset($appData['book_crossings'])) {
         $message = 'Can\'t add appointment, it crosses existing appointments: ';
         foreach ($appData['book_crossings'] as $cross) {
             $empItem = $empMapper->getById($cross->getEmpId(), $db);
             $message .= $empItem->getName();
             $message .= ' ' . $cross->getTimeStart()->format('M-j-Y H:i');
             $message .= '-' . $cross->getTimeEnd()->format('H:i') . ';';
         }
     }
     return (new \Utility\Template())->parse($templateName, array('book_hour_mode' => $app->getHourMode(), 'book_room_name' => $roomItem->getRoomName(), 'book_emps' => $emps, 'book_values' => isset($appData['book_values']) ? $appData['book_values'] : null, 'book_errors' => isset($appData['book_errors']) ? $appData['book_errors'] : null));
 }
Example #2
0
 public function act($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\AppointmentItem $appMapper, \DBMappers\EmpItem $empItemMapper)
 {
     if ($http->getRequestMethod() == 'GET') {
         $app->setStateBook(array());
     } else {
         if ($http->getRequestMethod() == 'POST') {
             $bookErrors = array();
             $bookValues = array_merge(array(), $http->post());
             $bookingOrder = new \Application\BookingOrder();
             $this->validateForm($bookValues, $bookErrors, $bookingOrder, $app->getHourMode());
             //error_log("\nbookingData:" . print_r($bookingOrder, true), 3, 'my_errors.txt');
             if ($this->isEmptyValues($bookErrors)) {
                 $appMatcher = new \Application\AppointmentMatcher();
                 $chain = $appMatcher->makeChain($bookingOrder, $app->getEmpId(), $app->getCurrentRoom());
                 $crossings = $appMatcher->getCrossingAppointments($chain, $appMapper, $db);
                 // test for crossing appointments
                 if (count($crossings) > 0) {
                     $message = \Utility\HtmlHelper::MakeCrossingMessage($crossings, $empItemMapper, $db);
                     $app->setStateBook(array('book_values' => $bookValues, 'book_errors' => $bookErrors, 'error_message' => $message, 'book_crossings' => $crossings));
                 } else {
                     $max_chain_id = $appMapper->getMaxChainId($db);
                     if ($max_chain_id === false) {
                         $max_chain_id = 1;
                     } else {
                         ++$max_chain_id;
                     }
                     $chain->setChainId($max_chain_id);
                     foreach ($chain as $appointment) {
                         $appMapper->save($appointment, $db);
                     }
                     $chain->rewind();
                     $message = \Utility\HtmlHelper::MakeSuccessAppCreationMessage($chain->current(), $app->getHourMode());
                     $app->setMessage($message);
                     $app->setStateRedirect(BROWSE_URL);
                 }
             } else {
                 $app->setStateBook(array('book_values' => $bookValues, 'book_errors' => $bookErrors, 'error_message' => isset($bookErrors['common']) ? $bookErrors['common'] : null));
             }
         }
     }
 }