/**
  * @FosRest\Get("/{section}")
  *
  * @ApiDoc(
  *  description = "Get the details of a section."
  * )
  *
  * @ParamConverter("section", class="MainBundle:Section")
  *
  * @FosRest\QueryParam(
  *     name = "token",
  *     nullable = false,
  *     description = "Mobilit token."
  * )
  *
  * @param Section $section
  * @param ParamFetcher $paramFetcher
  *
  * @return Response
  */
 public function getAction(Section $section, ParamFetcher $paramFetcher)
 {
     if ($this->container->getParameter('mobilit_token') != $paramFetcher->get('token')) {
         return new Response(json_encode(["message" => $this->get('translator')->trans("errors.api.android.v1.token")]), Response::HTTP_FORBIDDEN);
     }
     return new Response($this->get('serializer')->serialize($section, 'json', SerializationContext::create()->setGroups(array('details'))));
 }
Пример #2
0
 /**
  * @Rest\GET("/me/recommended-games")
  * @QueryParam(name="lat", nullable=true)
  * @QueryParam(name="long", nullable=true)
  * @View(serializerEnableMaxDepthChecks=true)
  */
 public function getRecommendedGamesAction(ParamFetcher $paramFetcher)
 {
     $dm = $this->get('doctrine.odm.mongodb.document_manager');
     $user = $this->get('security.context')->getToken()->getUser();
     if ($user == "anon.") {
         throw new NotFoundHttpException();
     }
     $lat = $paramFetcher->get('lat') != null ? floatval($paramFetcher->get('lat')) : $user->getAddress()->getCoordinates()->getX();
     $long = $paramFetcher->get('long') != null ? floatval($paramFetcher->get('long')) : $user->getAddress()->getCoordinates()->getY();
     if (!isset($lat) || !isset($long)) {
         throw new NotFoundHttpException(" Debe haber alguna localización");
     }
     $nearCenters = $dm->getRepository('MIWDataAccessBundle:Center')->findClosestCenters($lat, $long);
     $geolocationService = $this->get('geolocation_service');
     $recommendedGames = array();
     $sports = $user->getSports();
     $sportsKey = is_array($sports) ? array_keys($sports) : array();
     foreach ($nearCenters as $center) {
         $games = $dm->getRepository('MIWDataAccessBundle:Game')->findAllByCenterAndSports($center, $sportsKey);
         $coordinates = $center->getAddress()->getCoordinates();
         if (count($games) > 0) {
             foreach ($games as $game) {
                 $line = array();
                 $line['distance'] = $geolocationService->getDistance($lat, $long, $coordinates->getX(), $coordinates->getY(), "K");
                 $line['game'] = $game;
                 $recommendedGames[] = $line;
             }
         }
     }
     return $this->view($recommendedGames, 200);
 }
Пример #3
0
 /**
  * Create a Category from the submitted data.
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "Creates a new category from the submitted data.",
  *   statusCodes = {
  *     201 = "Returned when successful",
  *     400 = "Returned when the form has errors"
  *   }
  * )
  *
  * @param ParamFetcher $paramFetcher Paramfetcher
  *
  * @RequestParam(name="label", nullable=false, strict=true, description="Label.")
  * @RequestParam(name="description", nullable=true, strict=true, description="Description.")
  * @RequestParam(name="color", nullable=true, strict=true, description="Color.")
  *
  * @return View
  */
 public function postCategoryAction(ParamFetcher $paramFetcher)
 {
     $label = filter_var($paramFetcher->get('label'), FILTER_SANITIZE_STRING);
     $desc = filter_var($paramFetcher->get('description'), FILTER_SANITIZE_STRING);
     $statusCode = 201;
     if (isset($label) && $label != '') {
         //            $category = new Task();
         //            $category->setLabel($label);
         //            $category->setDescription($desc);
         //            $category->setDate(new \DateTime('now'));
         //
         //            $manager = $this->getEntityManager();
         //            $manager->persist($category);
         //            $manager->flush();
         //            $id = $category->getId();
         //            if(!isset($id)) {
         //                $statusCode = 400;
         //            }
     } else {
         $statusCode = 400;
     }
     $view = View::create();
     $view->setData('')->setStatusCode($statusCode);
     return $view;
 }
Пример #4
0
 /**
  * Ajoute un postulant à une voiture
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "Ajoute un postulant à une voiture",
  *   statusCodes = {
  *     201 = "Created",
  *     404 = "Returned when the voiture is not found"
  *   }
  * )
  * @RequestParam(name="nomPostulant", nullable=true, strict=true, description="nom postulant.")
  * @RequestParam(name="telephone", nullable=true, strict=true, description="telephone postulant.")
  * @RequestParam(name="idVoiture", nullable=true,requirements="\d+", strict=true, description="id voiture postulant.")
  * @Route("api/postulants",name="nicetruc_post_postulant", options={"expose"=true})
  * @Method({"POST"})
  */
 public function postPostulant(ParamFetcher $paramFetcher)
 {
     //        try{
     $em = $this->getDoctrine()->getManager();
     $voiture = $em->getRepository('AppBundle:Voiture')->customFind($paramFetcher->get('idVoiture'));
     if (!$voiture) {
         return MessageResponse::message('Voiture introuvable', 'danger', 404);
     }
     $postulant = $em->getRepository('AppBundle:Postulant')->findBy(array('telephone' => $paramFetcher->get('telephone'), 'voiture' => $voiture));
     if ($postulant) {
         return MessageResponse::message('Ce numero a déjà postulé à cette annonce', 'warning', 200);
     }
     $postulant = new Postulant();
     $postulant->setNomPostulant($paramFetcher->get('nomPostulant'));
     $postulant->setTelephone($paramFetcher->get('telephone'));
     $postulant->setVoiture($voiture);
     $validator = $this->get('validator');
     $error = $validator->validate($postulant);
     if (count($error) > 0) {
         $message = "";
         foreach ($error as $er) {
             $message = $message . $er->getMessage() . '<br>';
         }
         return MessageResponse::message($message, 'danger', 400);
     }
     $em->persist($postulant);
     $em->flush();
     return MessageResponse::message('Enregistrement effectué avec succes', 'success', 201);
     //        }catch (BadRequestHttpException $e){
     //            dump($e);
     //            return MessageResponse::message($e->getMessage(),'danger',400);
     //        }
 }
Пример #5
0
 /**
  * Récupère la liste des départements
  * GET api/offers
  * @Rest\View()
  * @Rest\QueryParam(name="sort", requirements="(created|id|name)", default="created", description="search according to date, id or name")
  * @Rest\QueryParam(name="dir", requirements="(asc|desc)", default="desc", description="sort search ascending or descending")
  *
  * @return [type] [description]
  */
 public function getOffersAction(ParamFetcher $paramFetcher)
 {
     $sortBy = $paramFetcher->get('sort');
     $sortDir = $paramFetcher->get('dir');
     $offers = $this->getDoctrine()->getManager()->getRepository('RscineOfferBundle:Offer')->findBy(array(), array($sortBy => $sortDir));
     return $offers;
 }
Пример #6
0
 /**
  * Paginate query results using knp paginator bundle
  * 
  * @param ParamFetcher $paramFetcher
  * @param Query $query
  * @param string $sortAlias
  * @return Hal
  */
 protected function paginate(ParamFetcher $paramFetcher, $query, $sortAlias)
 {
     $request = $this->getRequest();
     $params = $paramFetcher->all() + $this->getPagingParams();
     //alternative page start index support
     if (!empty($params['pageStartIndex'])) {
         $page = abs(round($params['pageStartIndex'] / $params['pageSize'])) + 1;
     }
     $aliasPrefix = $sortAlias . '.';
     //paginator
     $paginator = $this->get('knp_paginator');
     //sort fields resource values to entity fields conversion
     if (!empty($params['sortBy']) && substr($params['sortBy'], 0, 2) != $aliasPrefix) {
         $_GET['sortBy'] = $aliasPrefix . $params['sortBy'];
         //set default sortBy if none is set
     } else {
         //$_GET['sortBy'] = $aliasPrefix . 'id';
     }
     if (empty($params['sortOrder'])) {
         //$_GET['sortOrder'] = 'asc';
     }
     $items = $paginator->paginate($query, $params['page'], $params['pageSize']);
     $paginationData = $items->getPaginationData();
     //root data
     $rootArr = array('totalCount' => $paginationData['totalCount'], 'pageCount' => $paginationData['pageCount'], 'pageSize' => $paginationData['numItemsPerPage'], 'currentPage' => intval($paginationData['current']), 'currentPageItemCount' => $paginationData['currentItemCount']);
     $entityName = $this->getEntityNameFromResourceObject($items);
     $hal = new Hal($request->getUri(), $rootArr, $entityName);
     //paging links
     $this->addPagingLinks($hal, $paginationData);
     //collection output
     foreach ($items as $item) {
         $hal->addResource($this->getResourceName(), new Hal($this->getResourceUrl($item, $params), $item));
     }
     return $hal;
 }
Пример #7
0
 /**
  * Get albums collection
  * Test with GET /api/v1/albums
  *
  * @ApiDoc()
  *
  * @QueryParam(name="offset", requirements="\d+", default="0", description="Offset from which to start listing")
  * @QueryParam(name="limit", requirements="\d+", default="10")
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return array
  */
 public function getAlbumsAction(ParamFetcher $paramFetcher)
 {
     $limit = $paramFetcher->get('limit');
     $offset = $paramFetcher->get('offset');
     $albums = $this->get('doctrine.orm.entity_manager')->getRepository('MusicAppBundle:Album')->findBy([], null, $limit, $offset);
     return ['albums' => $albums];
 }
 /**
  * @param Smoking      $smoking
  * @param ParamFetcher $paramFetcher
  * @return Questionnaire
  * @throws \Exception
  */
 public function updateSmoking(Smoking $smoking, ParamFetcher $paramFetcher)
 {
     $entityManager = $this->getEntityManager();
     $smoking->setDoYouSmoke($paramFetcher->get('do_you_smoke'))->setCompletedDate(new \DateTime());
     $entityManager->persist($smoking);
     $entityManager->flush();
     return $this->getQuestionnaireFromSmoking($smoking);
 }
Пример #9
0
 /**
  * @Rest\QueryParam(name="q", nullable=false, description="Query text")
  * @Rest\QueryParam(name="page_limit", nullable=true, requirements="\d+", description="Query limit", default="10")
  *
  * @param  ParamFetcher $paramFetcher
  * @param  integer $journalId
  * @return Response
  *
  * @Rest\Get("/search/journal/{journalId}/users")
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "Search Journal's Users",
  *   output = "Ojs\UserBundle\Entity\User[]",
  *   statusCodes = {
  *     "200" = "Users listed successfully",
  *     "403" = "Access Denied"
  *   }
  * )
  */
 public function searchJournalUsersAction(ParamFetcher $paramFetcher, $journalId)
 {
     $em = $this->getDoctrine()->getManager();
     $defaultLimit = 20;
     $limit = $paramFetcher->get('page_limit') && $defaultLimit >= $paramFetcher->get('page_limit') ? $paramFetcher->get('page_limit') : $defaultLimit;
     $journalUsers = $em->getRepository('OjsUserBundle:User')->searchJournalUser($paramFetcher->get('q'), $journalId, $limit);
     return $journalUsers;
 }
 /**
  *  Get Catalogs 
  *             
  * @QueryParam(name="page", requirements="\d+", default="0", description="record offset.")
  * @QueryParam(name="limit", requirements="\d+", default="100", description="number of records.")
  * @QueryParam(name="orderby", requirements="[a-z]+", allowBlank=true, default="name", description="OrderBy field")
  * @QueryParam(name="sort", requirements="(asc|desc)+", allowBlank=true, default="asc", description="Sorting order")
  *             
  * @Route("/catalogs")
  * @Method("GET")
  */
 public function getCatalogsAction(ParamFetcher $paramFetcher)
 {
     $page = $paramFetcher->get('page');
     $limit = $paramFetcher->get('limit');
     $orderby = $paramFetcher->get('orderby');
     $sort = $paramFetcher->get('sort');
     return $this->handleView($this->createView($this->get('catalog_service')->getCatalogs($page, $limit, $orderby, $sort)));
 }
 /**
  *  Get Products 
  *             
  * @QueryParam(name="page", requirements="\d+", default="0", description="record offset.")
  * @QueryParam(name="limit", requirements="\d+", default="100", description="number of records.")
  * @QueryParam(name="orderby", requirements="[a-z]+", allowBlank=true, default="name", description="OrderBy field")
  * @QueryParam(name="sort", requirements="(asc|desc)+", allowBlank=true, default="asc", description="Sorting order")
  *             
  * @Route("/products/{category_id}")
  * @Method("GET")
  */
 public function getProductsAction($category_id, ParamFetcher $paramFetcher)
 {
     $page = $paramFetcher->get('page');
     $limit = $paramFetcher->get('limit');
     $orderby = $paramFetcher->get('orderby');
     $sort = $paramFetcher->get('sort');
     return $this->handleView($this->createView($this->get('product_service')->getProductsForCategory($category_id, $page, $limit, $orderby, $sort)));
 }
Пример #12
0
 /**
  * Retrieve all the project resources.
  *
  * @ApiDoc(
  *     resource=true,
  *     description="List all project resources",
  *     statusCodes={
  *         200="Returned when successful",
  *         403="Returned when the user is not authorized",
  *         404="Returned when project does not exist"
  *     },
  *     requirements={
  *         { "name"="project", "dataType"="string", "required"=true, "description"="Project's slug" }
  *     }
  * )
  * @Rest\QueryParam(name="project", strict=true, nullable=false)
  * @Rest\View
  */
 public function cgetAction(ParamFetcher $paramFetcher)
 {
     $project = $this->findProjectOr404($paramFetcher->get('project'));
     $resources = $this->get('openl10n.repository.resource')->findByProject($project);
     return (new ArrayCollection($resources))->map(function (Resource $resource) {
         return new ResourceFacade($resource);
     });
 }
 /**
  * @param ParamFetcher $paramFetcher
  * @param string       $prefix
  * @return array
  */
 protected function normaliseDayDurationsToArray(ParamFetcher $paramFetcher, $prefix)
 {
     $durationArray = array();
     foreach (DayDuration::$validDays as $day) {
         $durationArray[$day] = $paramFetcher->get($prefix . $day);
     }
     return $durationArray;
 }
 /**
  * @FosRest\Get("/{section}")
  *
  * @ApiDoc(
  *  description = "Get the guide of a section"
  * )
  *
  * @ParamConverter("section", class="MainBundle:Section")
  *
  * @FosRest\QueryParam(
  *     name = "token",
  *     nullable = false,
  *     description = "Mobilit token."
  * )
  * @param Section $section
  * @param ParamFetcher $paramFetcher
  *
  * @return array|GuideModel
  */
 public function getAction(Section $section, ParamFetcher $paramFetcher)
 {
     if ($this->container->getParameter('mobilit_token') != $paramFetcher->get('token')) {
         return new Response(json_encode(["message" => $this->get('translator')->trans("errors.api.android.v1.token")]), Response::HTTP_FORBIDDEN);
     }
     $guide = $this->get('main.guide.fetcher')->getGuide($section);
     $guide = $this->get('main.guide.adapter')->getModel($guide, true);
     return $guide;
 }
Пример #15
0
 /**
  * @ApiDoc(
  *   section="Incident",
  *   resource=true,
  *   description="Returns a collection of incidents",
  *   output={
  *       "class"="array<AppBundle\Entity\Core\Incident>",
  *       "groups"={"list"}
  *   },
  *
  *   statusCodes={
  *     200="Returned when successful",
  *     401="Returned when authentication fails"
  *   }
  * )
  * @QueryParam(name="page", requirements="\d+", default="1", description="Page from which to start listing incidents.")
  *
  * @Route("", methods={"GET"})
  * @View(serializerGroups={"Default","list"})
  *
  * @param Request      $request
  * @param ParamFetcher $paramFetcher
  *
  * @return array
  */
 public function listAction(Request $request, ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $incidentRepository = $em->getRepository('AppBundle:Core\\Incident');
     $page = $paramFetcher->get('page');
     $paginator = $this->get('knp_paginator');
     $pagination = $paginator->paginate($incidentRepository->findAllIncidents(), $page, Incident::MAX_INCIDENT);
     return new PagerRepresentation($pagination);
 }
Пример #16
0
 /**
  * @ApiDoc(
  *   section="Subscriber",
  *   resource=true,
  *   description="Returns a collection of subscribers",
  *   output={
  *       "class"="array<AppBundle\Entity\Core\Subscriber>",
  *       "groups"={"list"}
  *   },
  *
  *   statusCodes={
  *     200="Returned when successful",
  *     401="Returned when authentication fails"
  *   }
  * )
  * @QueryParam(name="page", requirements="\d+", default="1", description="Page from which to start listing Subscribers.")
  *
  * @Route("", methods={"GET"})
  * @View(serializerGroups={"Default","list"})
  *
  * @param Request      $request
  * @param ParamFetcher $paramFetcher
  *
  * @return array
  */
 public function listAction(Request $request, ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $subscriberRepository = $em->getRepository('AppBundle:Core\\Subscriber');
     $page = $paramFetcher->get('page');
     $paginator = $this->get('knp_paginator');
     $pagination = $paginator->paginate($subscriberRepository->findAllSubscribers(), $page, Subscriber::MAX_SUBSCRIBER);
     return new PagerRepresentation($pagination);
 }
Пример #17
0
 /**
  * @ApiDoc(
  *   section="MetricPoint",
  *   resource=true,
  *   description="Returns a collection of metrics",
  *   output={
  *       "class"="array<AppBundle\Entity\Core\MetricPoint>",
  *       "groups"={"list"}
  *   },
  *   statusCodes={
  *     200="Returned when successful",
  *     401="Returned when authentication fails"
  *   }
  * )
  * @QueryParam(name="page", requirements="\d+", default="1", description="Page from which to start metric point listing.")
  *
  * @Route("", methods={"GET"})
  * @View(serializerGroups={"Default","list"})
  *
  * @param Request      $request
  * @param ParamFetcher $paramFetcher
  *
  * @return array
  */
 public function listAction(Request $request, ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $metricPointRepository = $em->getRepository('AppBundle:Core\\MetricPoint');
     $page = $paramFetcher->get('page');
     $paginator = $this->get('knp_paginator');
     $pagination = $paginator->paginate($metricPointRepository->findAllMetricPoint(), $page, MetricPoint::MAX_METRIC_POINT);
     return new PagerRepresentation($pagination);
 }
 /**
  * @param ParamFetcher $paramFetcher
  * @return Questionnaire
  * @throws \Exception
  */
 public function createQuestionnaire(ParamFetcher $paramFetcher)
 {
     $entityManager = $this->getEntityManager();
     $person = (new Person())->setFirstName($paramFetcher->get('firstname'))->setAge($paramFetcher->get('age'))->setGender($paramFetcher->get('gender'));
     $questionnaire = new Questionnaire($person);
     $entityManager->persist($questionnaire);
     $entityManager->flush($questionnaire);
     return $questionnaire;
 }
 /**
  * @FosRest\Get("")
  *
  * @ApiDoc(
  *  description = "List all the countries and their sections."
  * )
  *
  * @FosRest\QueryParam(
  *     name = "token",
  *     nullable = false,
  *     description = "Mobilit token."
  * )
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return Response
  */
 public function listAction(ParamFetcher $paramFetcher)
 {
     if ($this->container->getParameter('mobilit_token') != $paramFetcher->get('token')) {
         return new Response(json_encode(["message" => $this->get('translator')->trans("errors.api.android.v1.token")]), Response::HTTP_FORBIDDEN);
     }
     $countries = $this->get('main.country.service')->getCountries(true);
     $serializer = $this->get('serializer');
     return new Response($serializer->serialize($countries, 'json', SerializationContext::create()->setGroups(array('listSection'))));
 }
Пример #20
0
 /**
  * @ApiDoc(
  *  section="Tools",
  *  description="Returns all stored log requests"
  * )
  *
  * @Rest\QueryParam(name="page", requirements="[0-9]+",  default="1", description="page")
  *
  * @Rest\Get("admin/system/tools/requests")
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return array[items => array[], maxPages => int]
  */
 public function getLogRequestsAction(ParamFetcher $paramFetcher)
 {
     $page = $paramFetcher->get('page');
     $query = LogRequestQuery::create()->orderByDate(Criteria::DESC);
     $count = ceil($query->count() / 50) ?: 0;
     $paginate = $query->paginate($page, 50);
     $items = $paginate->getResults()->toArray(null, null, TableMap::TYPE_CAMELNAME);
     return ['items' => $items, 'maxPages' => $count];
 }
Пример #21
0
 /**
  * @QueryParam(name="lat", strict=true)
  * @QueryParam(name="long", strict=true)
  * @QueryParam(name="datetime", strict=true)
  */
 public function indexAction(ParamFetcher $paramFetcher)
 {
     $latitude = $paramFetcher->get('lat');
     $longtitude = $paramFetcher->get('long');
     $datetime = $paramFetcher->get('datetime');
     $city = $this->get('doctrine.orm.entity_manager')->getRepository('WeatherBundle\\Entity\\LogItem')->findNearestLogItem($latitude, $longtitude, $datetime);
     $view = View::create()->setData($city);
     return $this->container->get('fos_rest.view_handler')->handle($view);
 }
Пример #22
0
 /**
  * @get("customer/by-remote-id")
  * @QueryParam(name="remote_id", description="Customer remote Id")
  * @View(serializerGroups={"REST"})
  * @param ParamFetcher $paramFetcher
  * @return Customer
  */
 public function getCustomerByRemoteIdAction(ParamFetcher $paramFetcher)
 {
     $remoteId = $paramFetcher->get('remote_id');
     $em = $this->getDoctrine()->getManager();
     $customer = $em->getRepository('DonateCoreBundle:Customer')->findOneByRemoteId(['remoteId' => $remoteId]);
     $this->throwNotFoundExceptionIfNotCustomer($customer);
     // Contrôle sur l'existence de l'entité
     return ['customer' => $customer];
 }
Пример #23
0
 /**
  * @ApiDoc(
  *   section="Service",
  *   resource=true,
  *   description="Returns a collection of services",
  *   output={
  *       "class"="array<AppBundle\Entity\Core\Service>",
  *       "groups"={"list"}
  *   },
  *
  *   statusCodes={
  *     200="Returned when successful",
  *     401="Returned when authentication fails"
  *   }
  * )
  * @QueryParam(name="page", requirements="\d+", default="1", description="Page from which to start listing Services.")
  *
  * @Route("", methods={"GET"})
  * @View(serializerGroups={"Default","list"})
  *
  * @param Request      $request
  * @param ParamFetcher $paramFetcher
  *
  * @return array
  */
 public function listAction(Request $request, ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $serviceRepository = $em->getRepository('AppBundle:Core\\Service');
     $page = $paramFetcher->get('page');
     $paginator = $this->get('knp_paginator');
     $pagination = $paginator->paginate($serviceRepository->findAllServices(), $page, Service::MAX_SERVICE);
     return new PagerRepresentation($pagination);
 }
Пример #24
0
 function it_gets_participants(ContainerInterface $container, Request $request, ParticipantRepository $participantRepository, ParamFetcher $paramFetcher, ProjectInterface $project, ParticipantInterface $participant)
 {
     $container->get('kreta_project.repository.participant')->shouldBeCalled()->willReturn($participantRepository);
     $request->get('project')->shouldBeCalled()->willReturn($project);
     $paramFetcher->get('limit')->shouldBeCalled()->willReturn(2);
     $paramFetcher->get('offset')->shouldBeCalled()->willReturn(0);
     $paramFetcher->get('q')->shouldBeCalled()->willReturn('*****@*****.**');
     $participantRepository->findByProject($project, 2, 0, '*****@*****.**')->shouldBeCalled()->willReturn([$participant]);
     $this->getParticipantsAction($request, 'project-id', $paramFetcher)->shouldReturn([$participant]);
 }
Пример #25
0
 /**
  * @param ParamFetcher  $paramFetcher
  * @param string        $class
  * @param array         $criterias
  *
  * @return \Doctrine\ODM\MongoDB\Cursor
  */
 protected function getListResults(ParamFetcher $paramFetcher, $class, array $criterias = [])
 {
     $orderBy = array($paramFetcher->get('orderBy') => $paramFetcher->get('sort'));
     $limit = (int) $paramFetcher->get('limit');
     $offset = (int) $paramFetcher->get('offset');
     if (count(array_filter($criterias))) {
         return $this->get('doctrine.odm.mongodb.document_manager')->getRepository($class)->findBy($criterias, $orderBy, $limit, $offset);
     }
     return $this->get('doctrine.odm.mongodb.document_manager')->getRepository($class)->getFindAllCursor($orderBy, $limit, $offset);
 }
 /**
  * @ApiDoc(
  *     resource=true,
  *     description="Activates the recently created user",
  *     statusCodes={204="Successful activation", 403="Invalid activation key"}
  * )
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return View
  *
  * @Rest\Patch("/users/activate.{_format}", name="app.user.activate")
  * @Rest\View(statusCode=204)
  *
  * @Rest\QueryParam(name="username", description="Name of the user to activate")
  * @Rest\QueryParam(name="activation_key", description="Activation key")
  */
 public function activateUserAction(ParamFetcher $paramFetcher)
 {
     /** @var \AppBundle\Model\User\Registration\TwoStepRegistrationApproach $registrator */
     $registrator = $this->get('app.user.registration');
     try {
         $registrator->approveByActivationKey($paramFetcher->get('activation_key'), $paramFetcher->get('username'));
     } catch (UserActivationException $ex) {
         return View::create(null, Codes::HTTP_FORBIDDEN);
     }
 }
Пример #27
0
 /**
  * Global search in the website.
  *
  * @Post("search")
  * @RequestParam(name="term", requirements="[a-z]", allowBlank=false, description="The term")
  * @RequestParam(name="domains", requirements=".+", allowBlank=false, nullable=true, description="Domains to be included")
  *
  * @ApiDoc()
  *
  * @param Request      $request
  * @param ParamFetcher $paramFetcher
  *
  * @return Response
  */
 public function postSearchAction(Request $request, ParamFetcher $paramFetcher)
 {
     $term = $paramFetcher->get('term');
     // if the form is posted, redirect to the GET route with the term in the query
     if ('html' === $request->getRequestFormat()) {
         $view = $this->routeRedirectView('purjus_search', ['term' => $term], 301);
         return $this->handleView($view);
     }
     return $this->forward('PurjusSearchBundle:Search:search', ['request' => $request, 'term' => $term]);
 }
 /**
  * @return \AppBundle\Entity\Degree[]|array
  *
  * @ApiDoc(
  *  resource=true,
  *  description="Returns a collection of Degrees",
  *  https=true,
  * )
  * @QueryParam(name="branch", description="Branch name", nullable=true)
  */
 public function getDegreesAction(ParamFetcher $paramFetcher)
 {
     $branch = $paramFetcher->get('branch');
     if ($branch === null) {
         $degrees = $this->getDoctrine()->getRepository('AppBundle:Degree')->findBy([], ['name' => 'ASC']);
     } else {
         $degrees = $this->getDoctrine()->getRepository('AppBundle:Degree')->findBy(['branch' => $branch], ['name' => 'ASC']);
     }
     return $degrees;
 }
 function it_gets_issue_priorities(ContainerInterface $container, Request $request, IssuePriorityRepository $repository, ParamFetcher $paramFetcher, ProjectInterface $project, IssuePriorityInterface $issuePriority)
 {
     $container->get('kreta_project.repository.issue_priority')->shouldBeCalled()->willReturn($repository);
     $request->get('project')->shouldBeCalled()->willReturn($project);
     $paramFetcher->get('limit')->shouldBeCalled()->willReturn(10);
     $paramFetcher->get('offset')->shouldBeCalled()->willReturn(1);
     $paramFetcher->get('q')->shouldBeCalled()->willReturn('Low');
     $repository->findByProject($project, 10, 1, 'Low')->shouldBeCalled()->willReturn([$issuePriority]);
     $this->getIssuePrioritiesAction($request, 'project-id', $paramFetcher)->shouldReturn([$issuePriority]);
 }
Пример #30
0
 function it_gets_labels(ContainerInterface $container, Request $request, LabelRepository $labelRepository, ParamFetcher $paramFetcher, ProjectInterface $project, LabelInterface $label)
 {
     $container->get('kreta_project.repository.label')->shouldBeCalled()->willReturn($labelRepository);
     $request->get('project')->shouldBeCalled()->willReturn($project);
     $paramFetcher->get('limit')->shouldBeCalled()->willReturn(10);
     $paramFetcher->get('offset')->shouldBeCalled()->willReturn(1);
     $paramFetcher->get('q')->shouldBeCalled()->willReturn('java');
     $labelRepository->findByProject($project, 10, 1, 'java')->shouldBeCalled()->willReturn([$label]);
     $this->getLabelsAction($request, 'project-id', $paramFetcher)->shouldReturn([$label]);
 }