public function findAllByParameters(AccountSearchParameters $parameters) { $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $ex = $qb->expr(); $qb->select('tsAccount')->from('PublicUHCTeamspeakAuthBundle:TeamspeakAccount', 'tsAccount')->leftJoin('tsAccount.authentications', 'authentication')->leftJoin('authentication.minecraftAccount', 'mcAccount'); if (count($parameters->getUuids()) > 0) { $qb->where($ex->in('tsAccount.uuid', explode(',', $parameters->getUuids()))); } else { $qb->setMaxResults($parameters->getLimit()); $qb->setFirstResult($parameters->getOffset()); } if ($parameters->isVerified()) { $qb->groupBy('tsAccount')->having($ex->gt($ex->count('authentication'), 0)); } return $qb->getQuery()->getResult(); }
/** * @Get("/v1/minecraft_account", name="api_v1_minecraft_account_list") * @Method({"GET"}) * * @QueryParam( * name="type", * description="Search type. If 'online' will only return accounts with online teamspeak accounts. If 'verified' will only return accounts with verified accounts (with at least 1 authentication). If 'any' or missing will return all accounts", * requirements="(online|verified|any)", * default="any" * ) * @QueryParam(name="uuids", description="Comma separated list of user UUIDs (without dashes)", nullable=true) * @QueryParam(name="limit", description="Limit amount returned, ignored if searching by UUIDs, max 50", requirements="\d+", default="10") * @QueryParam(name="offset", description="Offset, ignored if searching by UUIDs", requirements="\d+", default="0") * * @ApiDoc( * section="Minecraft Accounts", * description="View minecraft accounts", * tags={"API"}, * output="PublicUHC\Bundle\TeamspeakAuthBundle\Entity\MinecraftAccount", * statusCodes={ * 200="On success", * 400="On invalid parameters", * 503="On unable to reach Teamspeak server (online checks only)" * } * ) */ public function apiV1CheckMinecraftAccountAction($uuids, $type, $limit, $offset) { if ($limit > 50) { throw new BadRequestHttpException('Only 50 accounts may be fetched per request'); } $params = new AccountSearchParameters(); if (null != $uuids) { $params->setUuids($uuids); } if ($type != 'any') { $params->setVerified(true); } $params->setLimit($limit); $params->setOffset($offset); /** @var MinecraftAccountRepository $repo */ $repo = $this->getDoctrine()->getManager()->getRepository('PublicUHCTeamspeakAuthBundle:MinecraftAccount'); $results = $repo->findAllByParameters($params); if ($type == 'online') { $results = $this->filterOnlineOnly($results); } return $this->view($results); }