/**
  *
  *
  * @ApiDoc(
  *   section = "User - Public data",
  *   description = "List of the users (scope: public)",
  *   filters = {
  *      { "name"="firstname",       "dataType"="string"     },
  *      { "name"="lastname",        "dataType"="string"     },
  *      { "name"="branch",          "dataType"="string"     },
  *      { "name"="level",           "dataType"="string"     },
  *      { "name"="speciality",      "dataType"="string"     },
  *      { "name"="is_student",      "dataType"="boolean"    },
  *      { "name"="bde_member",      "dataType"="boolean"    }
  *   },
  *   parameters={
  *      { "name"="embed", "dataType"="string", "description"="Embed foreign entities in the users data (available: badges)" }
  *   }
  * )
  *
  * @Route("/public/users", name="api_public_users_list", options={"expose"=true})
  * @Method("GET")
  */
 public function listAction(Request $request)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $page = (int) $request->query->get('page', 1);
     /** @var $query QueryBuilder */
     $query = $em->createQueryBuilder()->select('u, m')->from('EtuUserBundle:User', 'u')->leftJoin('u.bdeMemberships', 'm')->orderBy('u.lastName');
     $query = $this->get('etu.api.user.mapper')->map($query, $request->query);
     /** @var SlidingPagination $pagination */
     $pagination = $this->get('knp_paginator')->paginate($query, $page, 30);
     $previous = false;
     $next = false;
     if ($page > 1) {
         $previous = $this->generateUrl('api_public_users_list', ['page' => $page - 1]);
     }
     if ($page < $pagination->getPaginationData()['pageCount']) {
         $next = $this->generateUrl('api_public_users_list', ['page' => $page + 1]);
     }
     $embedBag = EmbedBag::createFromRequest($request);
     return $this->format(['pagination' => ['currentPage' => $pagination->getCurrentPageNumber(), 'totalPages' => $pagination->getPaginationData()['pageCount'], 'totalItems' => $pagination->getTotalItemCount(), 'perPage' => $pagination->getItemNumberPerPage(), 'previous' => $previous, 'next' => $next], 'embed' => $embedBag->getMap(['badges']), 'data' => $this->get('etu.api.user.transformer')->transform($pagination->getItems(), $embedBag)]);
 }
 /**
  * This endpoint list you the organizations the current user are in and the permission
  * he or she has in these organizations.
  *
  * @ApiDoc(
  *   section = "User - Private data",
  *   authentication = true,
  *   authenticationRoles = {"private_user_organizations"},
  *   description = "Get the list of organizations of the current user and its permissions in them"
  * )
  *
  * @Route("/organizations", name="api_private_user_organizations", options={"expose"=true})
  * @Method("GET")
  * @Scope("private_user_organizations")
  */
 public function organizationsAction(Request $request)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $user = $em->getRepository('EtuUserBundle:User')->find($this->getAccessToken()->getUser());
     return $this->format(['data' => $this->get('etu.api.user_orgas_private.transformer')->transform($user->getMemberships()->toArray(), EmbedBag::createFromRequest($request))]);
 }