/** * {@inheritDoc} */ protected function build($builder) { $durations = \Service::getParameter('bzion.league.duration'); foreach ($durations as $duration => &$value) { $durations[$duration] = $duration; } return $builder->add('first_team', new MatchTeamType())->add('second_team', new MatchTeamType())->add('duration', 'choice', array('choices' => $durations, 'constraints' => new NotBlank(), 'expanded' => true))->add('server_address', 'text', array('required' => false, 'attr' => array('placeholder' => 'brad.guleague.org:5100')))->add('time', new DatetimeWithTimezoneType(), array('constraints' => array(new NotBlank(), new LessThan(array('value' => \TimeDate::now()->addMinutes(10), 'message' => 'The timestamp of the match must not be in the future'))), 'data' => \TimeDate::now(\Controller::getMe()->getTimezone())))->add('enter', 'submit'); }
/** * {@inheritdoc} */ protected function build($builder) { $durations = \Service::getParameter('bzion.league.duration'); foreach ($durations as $duration => &$value) { $durations[$duration] = $duration; } return $builder->add('first_team', new MatchTeamType(), array('disableTeam' => $this->isEdit() && $this->editing->isOfficial()))->add('second_team', new MatchTeamType(), array('disableTeam' => $this->isEdit() && $this->editing->isOfficial()))->add('duration', 'choice', array('choices' => $durations, 'constraints' => new NotBlank(), 'expanded' => true))->add('server_address', 'text', array('required' => false, 'attr' => array('placeholder' => 'brad.guleague.org:5100')))->add('time', new DatetimeWithTimezoneType(), array('constraints' => array(new NotBlank(), new LessThan(array('value' => \TimeDate::now()->addMinutes(10), 'message' => 'The timestamp of the match must not be in the future'))), 'data' => $this->isEdit() ? $this->editing->getTimestamp()->setTimezone(\Controller::getMe()->getTimezone()) : \TimeDate::now(\Controller::getMe()->getTimezone()), 'with_seconds' => $this->isEdit()))->add('map', new ModelType('Map'), array('required' => false))->add('type', 'choice', array('choices' => array(\Match::OFFICIAL => 'Official', \Match::FUN => 'Fun match', \Match::SPECIAL => 'Special event match'), 'disabled' => $this->editing && $this->editing->isOfficial(), 'label' => 'Match Type'))->add('enter', 'submit'); }
public function testCache() { $this->_setPrefs("Y-m-d", "H:i:s", "GMT"); $this->time_date->allow_cache = true; $now1 = $this->time_date->now(); sleep(2); $now2 = $this->time_date->now(); $this->assertEquals($now1, $now2, "now() should produce same result when cached"); }
public function testAutomaticExpiry() { $victim = $this->getNewPlayer(); $ban = Ban::addBan($victim->getId(), $this->getNewPlayer()->getId(), TimeDate::now()->addDay(), "Reason"); $this->assertTrue($victim->isBanned()); $this->assertEquals(Ban::getBan($victim->getId())->getId(), $ban->getId()); $ban->setExpiration(TimeDate::now()->subDay()); $this->assertFalse($victim->isBanned()); $this->assertNull(Ban::getBan($victim->getId())); }
/** * Handle the admin notes form * @param Form $form The form * @param Player $player The player in question * @param Player $me The currently logged in player * @return Form The updated form */ private function handleAdminNotesForm($form, $player, $me) { $notes = $form->get('notes')->getData(); if ($form->get('save_and_sign')->isClicked()) { $notes .= ' — ' . $me->getUsername() . ' on ' . TimeDate::now()->toRFC2822String(); } $player->setAdminNotes($notes); $this->getFlashBag()->add('success', "The admin notes for {$player->getUsername()} have been updated"); // Reset the form so that the user sees the updated admin notes return $this->creator->create(); }
public function acceptAction(Invitation $invitation, Player $me) { if (!$me->isTeamless()) { throw new ForbiddenException("You can't join a new team until you leave your current one."); } if ($invitation->getInvitedPlayer()->getId() != $me->getId()) { throw new ForbiddenException("This invitation isn't for you!"); } if ($invitation->getExpiration()->lt(TimeDate::now())) { throw new ForbiddenException("This invitation has expired"); } $inviter = $invitation->getSentBy()->getEscapedUsername(); $team = $invitation->getTeam(); return $this->showConfirmationForm(function () use($invitation, $team, $me) { $team->addMember($me->getId()); $invitation->updateExpiration(); Service::getDispatcher()->dispatch(Events::TEAM_JOIN, new TeamJoinEvent($team, $me)); return new RedirectResponse($team->getUrl()); }, "Are you sure you want to accept the invitation from {$inviter} to join {$team->getEscapedName()}?", "You are now a member of {$team->getName()}"); }
/** * Take a timezone and put its value on the time and timezone fields, so the * user can see it * * @param string $timezone The timezone * @return null|string */ public function transform($timezone) { if ($timezone === null) { return null; } $timezones = array_keys($this->timezones); // The provided timezone is in the reduced list of timezones that we // show to the user, so we can use it immediately if (in_array($timezone, $timezones)) { return $timezone; } // The timezone isn't in the list, just find one with the same offset // and use that instead foreach ($timezones as $t) { if (\TimeDate::now()->setTimezone($t)->offset === \TimeDate::now()->setTimezone($timezone)->offset) { return $t; } } return 'UTC'; // Default if we can't find a timezone }
/** * Get a count for each month's matches * * @param Team $team The team in question * @return array */ public function getSummary(Team $team) { $this->groupByMonth(); $query = $this->createQuery("YEAR(timestamp) as y, MONTH(timestamp) as m, COUNT(*) as count"); $matches = array(); $results = Database::getInstance()->query($query, $this->types, $this->parameters); foreach ($results as $match) { $matches[$match['y'] . '-' . sprintf('%02d', $match['m'])] = $match['count']; } // Add entries for dates with 0 matches $timestamp = $team->getCreationDate()->setTimezone('UTC')->startOfMonth(); while ($timestamp->lte(TimeDate::now())) { $key = $timestamp->format('Y-m'); if (!isset($matches[$key])) { $matches[$key] = 0; } $timestamp->addMonth(); } ksort($matches); return $matches; }
/** * Update the last edit timestamp * @return self */ public function updateEditTimestamp() { return $this->updateProperty($this->updated, "updated", TimeDate::now(), 's'); }
/** * {@inheritdoc} */ protected function build($builder) { return $builder->add('player', new AdvancedModelType('player'), array('constraints' => new NotBlank(), 'disabled' => $this->isEdit(), 'data' => $this->controller->data->get('player')))->add($builder->create('automatic_expiration', 'checkbox', array('data' => true, 'required' => false))->setDataLocked(false))->add($builder->create('expiration', 'datetime', array('data' => \TimeDate::now()))->setDataLocked(false))->add('reason', 'textarea', array('constraints' => new NotBlank(), 'required' => true))->add('server_join_allowed', 'checkbox', array('data' => true, 'required' => false))->add('server_message', 'text', array('required' => false, 'constraints' => new Length(array('max' => 150))))->add('ip_addresses', new IpType(), array('required' => false))->add('enter', 'submit')->setDataLocked(false); }
/** * Mark the invitation as having expired * * @return self */ public function updateExpiration() { return $this->updateProperty($this->expiration, 'expiration', TimeDate::now(), 's'); }
/** * Updates this player's last login */ public function updateLastLogin() { $this->update("last_login", TimeDate::now()->toMysql(), 's'); }
/** * Make sure that we are not using expired sessions * @return string The oldest timestamp that is not considered expired, in a * MySQL-readable format */ private function getOldestTimestamp() { $maxLifetime = (int) ini_get('session.gc_maxlifetime'); $oldestTimestamp = \TimeDate::now()->subSeconds($maxLifetime); return $oldestTimestamp->toMysql(); }
/** * Checks if the last update is older than or equal to the update interval * @return bool Whether the information is older than the update interval */ public function staleInfo() { $update_time = $this->updated->copy(); $update_time->modify(Service::getParameter('bzion.miscellaneous.update_interval')); return TimeDate::now() >= $update_time; }
/** * Get a list of changes that will be shown to the user * * @param array[] $changelog The parsed changelog.yml file * @return array[] The changes to show to the user */ private function parseChangelog($changelog) { $listed = array(); $firstEntry = true; $lastChangeDate = \TimeDate::now()->startOfDay(); $lastChanges = array(); foreach ($changelog as $date => $changes) { $date = \TimeDate::from($date); if ($firstEntry) { // The array has been sorted, the first entry represents the // most recent change. Store its date so that we don't show the // same entry many times $firstEntry = false; if ($lastChangeDate >= $date) { $lastChangeDate = $date; $lastChanges = $changes; } } // Don't list changes that we've listed before if ($date == $this->lastUpdateDate) { $this->filterAlreadyListedChanges($changes); } elseif ($this->lastUpdateDate && $date < $this->lastUpdateDate) { break; } $listed = array_merge_recursive($listed, $changes); } $this->alreadyListedChanges = $lastChanges; $this->lastUpdateDate = $lastChangeDate; return $listed; }
/** * Update the conversation's last activity timestamp * * @return void */ public function updateLastActivity() { $this->last_activity = TimeDate::now(); $this->update('last_activity', $this->last_activity->toMysql()); }
/** * Update the last edit timestamp * @return self */ public function updateEditTimestamp() { return $this->updateProperty($this->updated, 'updated', TimeDate::now()); }