public function testNotification() { $event = new WelcomeEvent("Welcome!", $this->player); $this->notification = Notification::newNotification($this->player->getId(), Events::WELCOME, $event); $this->assertEquals($event, $this->notification->getEvent()); $this->assertEquals(Events::WELCOME, $this->notification->getCategory()); $this->assertEquals($this->player->getId(), $this->notification->getReceiver()->getId()); $this->assertFalse($this->notification->isRead()); $this->notification->markAsRead(); $this->assertTrue($this->notification->isRead()); // Refresh the notification from the database $this->notification = Notification::get($this->notification->getId()); $this->assertTrue($this->notification->isRead()); }
$blast = Player::newPlayer(180, "blast", null, "active", Player::S_ADMIN); $kierra = Player::newPlayer(2229, "kierra", null, "active", Player::ADMIN, "", "", 174); $mdskpr = Player::newPlayer(8312, "mdskpr"); $snake = Player::newPlayer(54497, "Snake12534"); $tw1sted = Player::newPlayer(9736, "tw1sted", null, "active", Player::DEVELOPER); $brad = Player::newPlayer(3030, "brad", null, "active", Player::S_ADMIN, "", "I keep nagging about when this project will be done"); $constitution = Player::newPlayer(9972, "Constitution", null, "active", Player::S_ADMIN); $themap = Player::newPlayer(57422, "the map", null, "active", Player::COP); $oldSnake = Player::newPlayer(54498, "Snake12534"); $oldSnake->setOutdated(true); $allPlayers = array($alezakos, $allejo, $ashvala, $autoreport, $blast, $kierra, $mdskpr, $snake, $tw1sted, $brad, $constitution, $themap); echo " done!"; echo "\nSending notifications..."; foreach (Player::getPlayers() as $player) { $event = new WelcomeEvent('Welcome to ' . Service::getParameter('bzion.site.name') . '!', $player); Notification::newNotification($player->getId(), 'welcome', $event); } echo " done!"; echo "\nAdding deleted objects..."; Team::createTeam("Amphibians", $snake->getId(), "", "")->delete(); $snake->refresh(); Team::createTeam("Serpents", $snake->getId(), "", "")->delete(); $snake->refresh(); Page::addPage("Test", "<p>This is a deleted page</p>", $tw1sted->getId())->delete(); echo " done!"; echo "\nAdding teams..."; $olfm = Team::createTeam("OpenLeague FM?", $kierra->getId(), "", ""); $reptitles = Team::createTeam("Reptitles", $snake->getId(), "", "", "open"); $fflood = Team::createTeam("Formal Flood", $allejo->getId(), "", ""); $lweak = Team::createTeam("[LakeWeakness]", $mdskpr->getId(), "", ""); $gsepar = Team::createTeam("Good Separation", $tw1sted->getId(), "", "");
/** * Sends a notification to some players * * @param mixed $players A single player/ID or a player/ID list * @param string $type The type of the event * @param null|\Player|int $except A player who should not receive a notification * @param \Player $except */ protected function doNotify($players, $type, $except = null) { Debug::log("Notifying about {$type}", array('players' => $players, 'except' => $except)); if ($except instanceof \Player) { $except = $except->getId(); } if (!is_array($players)) { $players = array($players); } foreach ($players as $player) { if ($player instanceof \Player) { $player = $player->getId(); } if ($player != $except) { $notification = \Notification::newNotification($player, $type, $this); \Service::getContainer()->get('event_dispatcher')->dispatch(Events::NOTIFICATION_NEW, new NewNotificationEvent($notification)); } } }