Esempio n. 1
0
 public function teamsPlayersAction()
 {
     $teamId = $this->routeParam('team_id');
     $callback = function (QueryBuilder $queryBuilder) use($teamId) {
         return $queryBuilder->leftJoin('e.team', 't')->where('t.id=:teamId')->setParameter('teamId', $teamId);
     };
     $players = $this->service->fetchAll(\Fulbis\Core\Entity\Player::class, $callback);
     $collection = new \ZF\Hal\Collection($players, 'fulbis.rest.players');
     $collection->setCollectionName('players');
     return new ViewModel(['payload' => $this->getPluginManager()->get('hal')->createCollection($collection, 'fulbis.rpc.teams-players')]);
 }
Esempio n. 2
0
 public function tournamentsTeamsAction()
 {
     $tournamentId = $this->routeParam('tournament_id');
     if ($this->getRequest()->getMethod() == 'POST') {
         $POST = json_decode($this->getRequest()->getContent(), true);
         $teams = $this->createTeams($POST['teams'], $tournamentId);
     } else {
         // GET
         $teams = $this->getTeams($tournamentId);
     }
     $collection = new \ZF\Hal\Collection($teams, 'fulbis.rest.teams');
     $collection->setCollectionName('teams');
     return new ViewModel(['payload' => $this->getPluginManager()->get('hal')->createCollection($collection, 'fulbis.rpc.tournaments-teams')]);
 }
 public function tournamentsMatchesAction()
 {
     $tournamentId = $this->routeParam('tournament_id');
     $callback = function (QueryBuilder $queryBuilder) use($tournamentId) {
         return $queryBuilder->leftJoin('e.team1', 't1')->leftJoin('t1.tournament', 't')->where('t.id=:tournamentId')->orderBy('e.gameNumber', 'ASC')->setParameter('tournamentId', $tournamentId);
     };
     $matches = $this->service->fetchAll(\Fulbis\Core\Entity\Match::class, $callback);
     /** @var \ZF\Hal\Plugin\Hal $hal */
     $hal = $this->getPluginManager()->get('hal');
     $metadataMap = $hal->getMetadataMap()->get(\Fulbis\Core\Entity\Team::class);
     if ($metadataMap) {
         $metadataMap->getHydrator()->addFilter('players', new MethodMatchFilter('getPlayers'), FilterComposite::CONDITION_AND);
     }
     $collection = new \ZF\Hal\Collection($matches, 'fulbis.rest.matches');
     $collection->setCollectionName('matches');
     return new ViewModel(['payload' => $hal->createCollection($collection, 'fulbis.rpc.tournaments-matches')]);
 }