Ejemplo n.º 1
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));
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function testMakeRecurringMonthly()
 {
     $order = new \Application\BookingOrder();
     $order->setDate(2015, 10, 17);
     $order->setStartTime24(8, 15);
     $order->setEndTime24(9, 25);
     $order->setNotes('notes');
     $order->setEmpId(3);
     $order->setRecurring(BookingOrder::RECURRING_MONTHLY, 2);
     $start = new \DateTime('2015-10-17 08:15:00');
     $end = new \DateTime('2015-10-17 09:25:00');
     $matcher = new \Application\AppointmentMatcher();
     $chain = $matcher->makeChain($order, 1, 2);
     $counted = 0;
     $step = new \DateInterval('P1M');
     foreach ($chain as $res) {
         $this->assertEquals($start->getTimestamp(), $res->getTimeStart()->getTimestamp());
         $this->assertEquals($end->getTimestamp(), $res->getTimeEnd()->getTimestamp());
         $this->assertEquals('notes', $res->getNotes());
         $this->assertEquals(3, $res->getEmpId());
         $this->assertEquals(2, $res->getRoomId());
         $start->add($step);
         $end->add($step);
         ++$counted;
     }
     $this->assertEquals(3, $counted);
 }