/**
  * @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);
 }
 /**
  * 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];
 }
 /**
  * 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;
 }
 protected function _getSelect(ParamFetcher $paramFetcher, Request $request)
 {
     $select = new \Kwf_Model_Select();
     $select->limit($paramFetcher->get('limit'), $paramFetcher->get('start'));
     $queryValue = trim($request->get('query'));
     if ($queryValue) {
         $exprs = array();
         if (!$this->_queryColumns) {
             throw new \Kwf_Exception("_queryColumns are required to be set");
         }
         if ($this->_querySplit) {
             $queryValue = explode(' ', $queryValue);
         } else {
             $queryValue = array($queryValue);
         }
         foreach ($queryValue as $q) {
             $e = array();
             foreach ($this->_queryColumns as $c) {
                 $e[] = new \Kwf_Model_Select_Expr_Like($c, '%' . $q . '%');
             }
             if (count($e) > 1) {
                 $exprs[] = new \Kwf_Model_Select_Expr_Or($e);
             } else {
                 $exprs[] = $e[0];
             }
         }
         if (count($exprs) > 1) {
             $select->where(new \Kwf_Model_Select_Expr_And($exprs));
         } else {
             $select->where($exprs[0]);
         }
     }
     return $select;
 }
 /**
  * @View()
  * @QueryParam(name="offset")
  * @QueryParam(name="limit")
  * @QueryParam(name="sort", default="username")
  * @QueryParam(name="order")
  * @QueryParam(name="search")
  *
  * @return array
  */
 public function getUsersAction(ParamFetcher $paramFetcher)
 {
     $pagination = array('offset' => $paramFetcher->get('offset'), 'limit' => $paramFetcher->get('limit'));
     $sort = array('sort' => $paramFetcher->get('sort'), 'order' => $paramFetcher->get('order'));
     $search = $paramFetcher->get('search');
     return $this->get('kingdomhall.user_manager')->searchUser($pagination, $sort, $search);
 }
 /**
  * @QueryParam(name="page", requirements="\d+", default="1", description="Page of the overview")
  * @QueryParam(name="limit", requirements="\d+", default="10", description="Size of the page")
  * @QueryParam(name="sort", requirements="[a-z]+", description="Sort parameter")
  * @QueryParam(name="sort_order", requirements="(asc|desc)", allowBlank=false, default="asc", description="Sort direction")
  * @QueryParam(name="search", requirements="[a-zA-Z0-9]+", description="Search")
  * @QueryParam(name="status", requirements="(pending|publish|draft|auto-draft|future|private|inherit|trash)",  default="", nullable=true, description="Status of the posts")
  * @QueryParam(name="by_author", requirements="[a-zA-Z]+", description="By author's username", incompatibles={"search"})
  * @QueryParam(name="by_category", requirements="[a-zA-Z]+", description="By category", incompatibles={"search"})
  * @QueryParam(name="by_keywords", requirements="[a-zA-Z]+", description="By keywords", incompatibles={"search"})
  * @QueryParam(name="format", requirements="[a-z]+", default="lite", description="Format of request")
  * @Rest\View()
  */
 public function getPostsAction(ParamFetcher $paramFetcher)
 {
     $page = $paramFetcher->get("page");
     $limit = $paramFetcher->get("limit");
     $sort = $paramFetcher->get("sort");
     $sort_order = $paramFetcher->get("sort_order");
     $search = $paramFetcher->get("search");
     $status = $paramFetcher->get("status");
     $by_author = $paramFetcher->get("by_author");
     $by_category = $paramFetcher->get("by_category");
     $by_keywords = $paramFetcher->get("by_keywords");
     $format = $paramFetcher->get("format");
     $repo = $this->getDoctrine()->getManager()->getRepository('ESGISGabonPostBundle:CorporatePost');
     $posts = $repo->getPosts($format);
     $adapter = new ArrayAdapter($posts);
     $pager = new Pagerfanta($adapter);
     $pager->setMaxPerPage($limit);
     try {
         $pager->setCurrentPage($page);
     } catch (NotValidCurrentPageException $e) {
         throw new NotFoundHttpException();
     }
     $pagerfantaFactory = new PagerfantaFactory();
     $paginatedCollection = $pagerfantaFactory->createRepresentation($pager, new Route('api_get_posts', array('page' => $page, 'limit' => $limit, 'sort' => $sort, 'sort_order' => $sort_order)), new CollectionRepresentation($pager->getCurrentPageResults(), 'posts', 'posts'));
     return $paginatedCollection;
 }
 /**
  * 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);
     //        }
 }
 /**
  * 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;
 }
 /**
  * @param              $id
  * @param ParamFetcher $paramFetcher
  * @return Address
  * @throws \Exception
  */
 public function updateAddress($id, ParamFetcher $paramFetcher)
 {
     $entityManager = $this->getEntityManager();
     $address = $this->getAddress($id);
     $address->setAddressLines($paramFetcher->get('address'))->setPostcode($paramFetcher->get('postcode'))->setCountry($paramFetcher->get('country'))->setCounty($paramFetcher->get('county'))->setDistrict($paramFetcher->get('district'));
     $entityManager->flush($address);
     return $address;
 }
 /**
  *  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)));
 }
 /**
  * @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 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)));
 }
Exemple #13
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);
 }
 function it_should_respond_to_cget_action(ParamFetcher $paramFetcher, $repository)
 {
     $paramFetcher->get('latitude')->willReturn('foo-latitude');
     $paramFetcher->get('longitude')->willReturn('foo-longitude');
     $paramFetcher->get('from')->willReturn('foo-from');
     $paramFetcher->get('to')->willReturn('foo-to');
     $repository->findAllNear('foo-latitude', 'foo-longitude', 'foo-from', 'foo-to')->willReturn(['foo', 'bar']);
     $this->cgetAction($paramFetcher)->shouldReturn(['foo', 'bar']);
 }
 /**
  * @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;
 }
Exemple #16
0
 /**
  * @ApiDoc(
  *   section="Metric",
  *   resource=true,
  *   description="Returns a collection of metrics",
  *   output= {
  *       "class"="array<AppBundle\Entity\Core\Metric>",
  *       "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 metrics.")
  * @QueryParam(name="displayed", requirements="(0|1)", allowBlank=false, default="1", description="filter displayed metric")
  *
  * @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();
     $metricRepository = $em->getRepository('AppBundle:Core\\Metric');
     $page = $paramFetcher->get('page');
     $displayed = $paramFetcher->get('displayed');
     $paginator = $this->get('knp_paginator');
     $pagination = $paginator->paginate($metricRepository->findDisplayedMetrics($displayed, true), $page, Metric::MAX_METRIC);
     return new PagerRepresentation($pagination);
 }
 protected function paramFetcherSort(ParamFetcher $paramFetcher)
 {
     $sortField = null;
     $sortOrder = null;
     if ($paramFetcher->get('sortField') !== null) {
         $sortField = $paramFetcher->get('sortField');
         $sortOrder = $paramFetcher->get('sortOrder');
     }
     return ['sortField' => $sortField, 'sortOrder' => $sortOrder];
 }
Exemple #18
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);
 }
 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]);
 }
 /**
  * @FOS\Get("players")
  * @FOS\View()
  * @FOS\QueryParam(name="p1", description="Player 1 ID", requirements="\d+")
  * @FOS\QueryParam(name="p2", description="Player 2 ID", requirements="\d+")
  * @FOS\QueryParam(name="limit", requirements="\d+", description="Limit to how many games", default="10")
  * @FOS\QueryParam(name="page", requirements="\d+", description="Paging", default="1")
  * @ApiDoc(
  *  section="game",
  *  description="Get latest games between 2 players",
  *  statusCodes={
  *      404={
  *          "Player 1 not found",
  *          "Player 2 not found"
  *      }
  *  },
  *  output="AppBundle\Entity\PlayerGame"
  * )
  *
  * @param ParamFetcher $params
  * @return JsonResponse
  */
 public function getPlayerGamesAction(ParamFetcher $params)
 {
     try {
         $games = $this->get('game.service')->listGamesByPlayers($params->get('p1'), $params->get('p2'), $params->get('limit'), $params->get('page'));
         $view = $this->view($games, 200);
     } catch (\Exception $e) {
         $view = $this->view($e->getMessage(), 404);
     }
     return $this->handleView($view);
 }
 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]);
 }
 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]);
 }
 /**
  * @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);
     }
 }
 /**
  * @FosRest\Post("")
  *
  * @ApiDoc(
  *  description = "Create or update regId.",
  *  parameters={
  *   {"name"="token", "dataType"="string", "required"=true, "description"="Mobilit token of the application."},
  *   {"name"="regId", "dataType"="string", "required"=true, "description"="RegId to save."},
  *   {"name"="section", "dataType"="string", "required"=true, "description"="CodeSection of the user section."},
  *  },
  * )
  *
  * @FosRest\RequestParam(name="token", description="Mobilit token of the application.", nullable=false)
  * @FosRest\RequestParam(name="regId", description="RegId to save.", nullable=false)
  * @FosRest\RequestParam(name="section", description="CodeSection of the user section.", nullable=false)
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return Response
  *
  */
 public function createAction(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);
     }
     if (!$this->get('main.section.service')->checkSection($paramFetcher->get('section'))) {
         return new Response(json_encode(["message" => $this->get('translator')->trans("errors.api.android.v1.no_section")]), Response::HTTP_FORBIDDEN);
     }
     $serializer = $this->get('serializer');
     return new Response($serializer->serialize($this->get('main.regid.manager')->saveRegId($paramFetcher->get('regId'), $paramFetcher->get('section')), 'json', SerializationContext::create()->setGroups(array('list'))));
 }
Exemple #25
0
 /**
  * @Rest\QueryParam(name="q", nullable=false, description="Query text")
  * @Rest\QueryParam(name="page_limit", nullable=true, requirements="\d+", description="Query limit", default="10")
  * @Rest\View(serializerGroups={"search"})
  *
  * @param  ParamFetcher $paramFetcher
  * @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)
 {
     $em = $this->getDoctrine()->getManager();
     $journal = $this->get('ojs.journal_service')->getSelectedJournal();
     if (!$journal) {
         return $this->createNotFoundException();
     }
     $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'), $journal, $limit);
     return $journalUsers;
 }
 function it_gets_projects(ContainerInterface $container, ProjectRepository $projectRepository, ParamFetcher $paramFetcher, TokenStorageInterface $context, TokenInterface $token, UserInterface $user, ProjectInterface $project)
 {
     $container->get('kreta_project.repository.project')->shouldBeCalled()->willReturn($projectRepository);
     $container->has('security.token_storage')->shouldBeCalled()->willReturn(true);
     $container->get('security.token_storage')->shouldBeCalled()->willReturn($context);
     $context->getToken()->shouldBeCalled()->willReturn($token);
     $token->getUser()->shouldBeCalled()->willReturn($user);
     $paramFetcher->get('sort')->shouldBeCalled()->willReturn('name');
     $paramFetcher->get('limit')->shouldBeCalled()->willReturn(10);
     $paramFetcher->get('offset')->shouldBeCalled()->willReturn(1);
     $projectRepository->findByParticipant($user, ['name' => 'ASC'], 10, 1)->shouldBeCalled()->willReturn([$project]);
     $this->getProjectsAction($paramFetcher)->shouldReturn([$project]);
 }
 /**
  * @View()
  * @Get("/api/v1/visitors.{_format}", requirements={"_format"="json, xml"}, name="get_monthly_visitors", defaults={"_format"="json"})
  * @QueryParam(name="year", requirements="\d+", description="Year of the month")
  * @QueryParam(name="month", requirements="\d+", description="Month of the calendar")
  * @ApiDoc(description="Get the number of visitors for each days of a month")
  */
 public function monthlyVisitorsAction(ParamFetcher $paramFetcher)
 {
     $month = intval($paramFetcher->get('month'));
     $year = intval($paramFetcher->get('year'));
     if ($month < 1 || $month > 12) {
         throw new HttpException('404', 'Paramètre month incorrect');
     }
     if ($year < 2000) {
         throw new HttpException('404', 'Paramètre year incorrect');
     }
     $calendarInformation = $this->get('app.calendar_information');
     return $calendarInformation->getMonthlyStatus($year, $month);
 }
 /**
  * @View()
  * @Delete("/api/v1/ticket.{_format}", requirements={"_format"="json, xml"}, name="delete_ticket", defaults={"_format"="json"})
  * @QueryParam(name="order_id", requirements="\d+", description="id of the order that contents the ticket")
  * @QueryParam(name="order_ref", requirements="[0-9A-Za-z]{16}", description="ref of the order that contents the ticket")
  * @QueryParam(name="id", requirements="\d+", description="id of the ticket to remove")
  * @ApiDoc(description="delete a ticket of an order")
  */
 public function deleteTicketAction(ParamFetcher $paramFetcher)
 {
     $orderId = intval($paramFetcher->get('order_id'));
     $orderRef = strtoupper($paramFetcher->get('order_ref'));
     $ticketId = intval($paramFetcher->get('id'));
     $order = $this->getOrder($orderId, $orderRef);
     $entityManager = $this->getDoctrine()->getManager();
     foreach ($order->getTickets() as $ticket) {
         if ($ticket->getId() == $ticketId) {
             $order->removeTicket($ticket);
             $entityManager->remove($ticket);
         }
     }
     $entityManager->flush();
 }
 /**
  * @FosRest\View()
  * @FosRest\Post("/send")
  *
  * @QueryParam(
  *     name="title",
  *     nullable=false,
  *     description="Title of the notification"
  * )
  * @QueryParam(
  *     name="content",
  *     nullable=false,
  *     description="Content of the notification"
  * )
  * @QueryParam(
  *     name="sections",
  *     nullable=true,
  *     default=null,
  *     description="Esn section of the notification"
  * )
  * @param ParamFetcher $paramFetcher
  *
  * @return array|Response
  *
  * @Security("has_role('ROLE_BOARD')")
  */
 public function sendAction(ParamFetcher $paramFetcher)
 {
     $title = $paramFetcher->get('title');
     $content = $paramFetcher->get('content');
     $sections = $paramFetcher->get('sections');
     if (!$title || !$content) {
         return new Response("Invalid post arguments", Response::HTTP_BAD_REQUEST);
     }
     if (!$sections) {
         $sections = array();
         array_push($sections, $this->getUser()->getSection()->getCodeSection());
     }
     $notification = $this->get('main.notification.service')->sendNotifications($title, $content, $this->getUser(), $sections);
     return ["title" => $notification->getTitle(), "content" => $notification->getContent(), "sent_at" => $notification->getSentAt()];
 }
 /**
  * @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'))));
 }