Example #1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $steam = $builder->getData();
     $builder->add('name', 'text', ['label' => 'game.name'])->add('machine', 'dedipanel_machine_entity')->add('dir', 'text', ['label' => 'game.dir'])->add('port', 'integer', ['label' => 'game.port'])->add('game', 'entity', ['label' => 'game.selectGame', 'class' => 'DPGameBundle:Game', 'query_builder' => function (GameRepository $repo) {
         return $repo->getQBAvailableSteamGames();
     }])->add('mode', 'choice', ['choices' => SteamServer::getModeList(), 'empty_value' => 'steam.chooseGameMode', 'label' => 'steam.gameMode', 'required' => false])->add('maxplayers', 'integer', ['label' => 'game.maxplayers'])->add('rconPassword', 'text', ['label' => 'game.rcon.password'])->add('svPassword', 'text', ['label' => 'steam.svPassword', 'required' => false])->add('core', 'dedipanel_core_assignment', ['machine' => $steam->getMachine()])->add('alreadyInstalled', 'dictionary', ['name' => 'yes_no', 'label' => 'game.isAlreadyInstalled', 'expanded' => true]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         /** @var \Symfony\Component\Form\FormInterface $form */
         $form = $event->getForm();
         /** @var \DP\GameServer\SteamServerBundle\Entity\SteamServer $steam */
         $steam = $event->getData();
         if ($steam->getId() != null && $steam->getInstallationStatus() > 100) {
             $form->add('rebootAt', 'time', ['label' => 'steam.rebootAt', 'required' => false]);
         }
     });
     $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
         /** @var \Symfony\Component\Form\FormInterface $form */
         $form = $event->getForm();
         /** @var \DP\GameServer\SteamServerBundle\Entity\SteamServer $steam */
         $steam = $event->getData();
         if ($steam->getGame() !== null && $steam->getGame()->getAppId() == 740) {
             // == csgo
             $form->add('mode', 'choice', ['choices' => SteamServer::getModeList(), 'label' => 'steam.gameMode', 'empty_value' => 'steam.chooseGameMode']);
         } elseif ($steam->getGame() !== null) {
             $form->remove('mode');
         }
     });
 }
Example #2
0
 public function thereIsSteamServer($name, $machine = null, $port = 27025, $rconPassword = '******', $game = 'Counter-Strike', $installDir = 'test', $maxplayers = 2, $installed = true, $flush = true)
 {
     if (null === ($server = $this->getRepository('steam')->findOneBy(array('name' => $name)))) {
         $game = $this->thereIsGame($game);
         $machine = $this->thereIsMachine($machine);
         $server = new SteamServer();
         $server->setName($name);
         $server->setMachine($machine);
         $server->setPort($port);
         $server->setRconPassword($rconPassword);
         $server->setGame($game);
         $server->setDir($installDir);
         $server->setMaxplayers($maxplayers);
         if ($installed) {
             $server->setInstallationStatus(101);
         }
         $this->validate($server);
         $this->getEntityManager()->persist($server);
         if ($flush) {
             $this->getEntityManager()->flush();
         }
     }
     return $server;
 }