Beispiel #1
0
 private function createEvent()
 {
     $event = new Event();
     $event->setUid('1234567890');
     $event->setName('original');
     $event->setDescription('original description');
     $event->setStart(new \DateTimeImmutable(), '2000-01-01');
     $event->setEnd(new \DateTimeImmutable(), '2000-01-02');
     $event->setDescription('original description');
     return $event;
 }
 /**
  * @test
  */
 public function shouldEmitEventAfterHit()
 {
     //given
     $field = '20t';
     //when
     $this->post('/hit', ['field' => $field]);
     //then
     /** @var Event $event */
     $event = Arrays::first(Event::all());
     $this->assertEquals('hit', $event->name);
     $this->assertEquals('{"field":20,"multiplier":3,"scored":true,"winner":false,"shots_left":2}', $event->params);
 }
Beispiel #3
0
 public function index()
 {
     $field = $this->params['field'];
     $game = Game::currentGame();
     $currentGameUser = $game->current_game_user;
     $leftShoots = $currentGameUser->getLeftShoots();
     if ($leftShoots) {
         $hit = Hit::createFor($field, $currentGameUser);
         $params = Json::encode(['game' => $game->type, 'field' => $hit->field, 'multiplier' => $hit->multiplier, 'scored' => $hit->handleScore(), 'winner' => $currentGameUser->isWinner(), 'shots_left' => $leftShoots - 1, 'shitty_round' => $currentGameUser->isShittyRound()]);
         Event::create(['name' => 'hit', 'params' => $params]);
     } else {
         Event::create(['name' => 'next_player', 'params' => '']);
     }
 }
Beispiel #4
0
 /**
  * @return Event[]
  */
 public static function loadNew()
 {
     $lastEventId = Session::get('last_event_id');
     if (!$lastEventId) {
         //do not load events that we triggered before this session was started
         /** @var Event $lastEvent */
         $lastEvent = Event::queryBuilder()->limit(1)->order('id desc')->fetch();
         Session::set('last_event_id', $lastEvent ? $lastEvent->id : 0);
     }
     $events = Event::where(['id' => Restrictions::greaterThan($lastEventId)])->order('id asc')->fetchAll();
     if ($events) {
         Session::set('last_event_id', Arrays::last($events)->id);
     }
     return $events;
 }
 public function poll()
 {
     Stats::reset();
     session_write_close();
     $stop = Clock::now()->plusSeconds(self::TIMEOUT);
     while (true) {
         if (!$stop->isAfter(Clock::now()) || connection_aborted()) {
             $this->layout->renderAjax("[]");
             return;
         }
         session_start();
         $events = Event::loadNew();
         session_write_close();
         if ($events) {
             $this->layout->renderAjax(Json::encode(Arrays::map($events, function (Event $event) {
                 return $event->toJsonArray();
             })));
             return;
         }
         Stats::reset();
         usleep(100 * 1000);
     }
 }
 public function next_player()
 {
     $game = Game::currentGame();
     $game->nextPlayer();
     Event::create(['name' => 'refresh', 'params' => json_encode([])]);
     $this->layout->renderAjax();
 }
Beispiel #7
0
 private function assertRepetition(Event $repetition, Event $original, $isOverwriting)
 {
     $this->assertSame($original, $repetition->getOriginal(), 'Repetition should have original. Repetion=' . $repetition->getName() . ' Expected=' . $original->getName() . ' Actual=' . $repetition->getOriginal()->getName());
     $this->assertSame($isOverwriting, $repetition->isOverwriting(), 'Repetition should ' . ($isOverwriting ? '' : 'NOT ') . 'overwrite original. Repetion=' . $repetition->getName());
 }
Beispiel #8
0
 /**
  * Compare two events to sort them by date (and whether they are repetitions)
  * This is mostly for debugging
  * @param \Application\Model\Event $event
  * @return int
  */
 public function compare(Event $event)
 {
     // Keep repetitions at the end of the list
     if ($this->getOriginal() && !$event->getOriginal()) {
         return 1;
     } elseif (!$this->getOriginal() && $event->getOriginal()) {
         return -1;
     }
     $s1 = $this->getStart();
     $s2 = $event->getStart();
     $e1 = $this->getEnd();
     $e2 = $event->getEnd();
     // First compare start date
     if ($s1 > $s2) {
         return 1;
     } elseif ($s1 < $s2) {
         return -1;
     }
     // Then end date
     if ($e1 > $e2) {
         return 1;
     } elseif ($e1 < $e2) {
         return -1;
     }
     // Finally full day events come first
     if ($this->isAllDay() && !$event->isAllDay()) {
         return 1;
     } elseif (!$this->isAllDay() && $event->isAllDay()) {
         return -1;
     }
     return 0;
 }
 /**
  * Add date to the vevent
  * @param Event $event
  * @param VEvent $vevent
  * @param string $name name of property
  * @param \DateTimeImmutable $date
  */
 private function addDate(Event $event, VEvent $vevent, $name, \DateTimeImmutable $date)
 {
     if ($date) {
         $dtstart = $vevent->add($name, $date);
         if ($event->isAllDay()) {
             $dtstart['VALUE'] = 'DATE';
         }
     }
 }