/**
  * @param Member $member
  * @param EmbedBag $includes
  * @return array
  */
 private function getIncludes(Member $member, EmbedBag $includes)
 {
     $embed = ['organization' => null];
     if ($includes->has('organization')) {
         $embed['organization'] = $this->orgaTransformer->transform($member->getOrganization());
     } else {
         $embed['organization'] = $member->getOrganization()->getLogin();
     }
     return ['_embed' => $embed];
 }
예제 #2
0
 /**
  * @param Member $member
  * @param EmbedBag $includes
  * @return array
  */
 private function getIncludes(Member $member, EmbedBag $includes)
 {
     $embed = ['user' => null];
     if ($includes->has('user')) {
         $embed['user'] = $this->userTransformer->transform($member->getUser());
     } else {
         $embed['user'] = $member->getUser()->getLogin();
     }
     return ['_embed' => $embed];
 }
 /**
  * @param User $user
  * @param EmbedBag $includes
  * @return array
  */
 private function getIncludes(User $user, EmbedBag $includes)
 {
     $embed = ['badges' => []];
     if ($includes->has('badges')) {
         foreach ($user->getBadges() as $userBadge) {
             $embed['badges'][] = $this->badgeTransformer->transform($userBadge->getBadge(), new EmbedBag());
         }
     } else {
         foreach ($user->getBadges() as $userBadge) {
             $embed['badges'][] = $userBadge->getBadge()->getId();
         }
     }
     return ['_embed' => $embed];
 }
예제 #4
0
 /**
  * @param Organization $orga
  * @param EmbedBag $includes
  * @return array
  */
 private function getIncludes(Organization $orga, EmbedBag $includes)
 {
     $embed = ['members' => []];
     if ($includes->has('members')) {
         foreach ($orga->getMemberships() as $membership) {
             $embed['members'][] = $this->orgaMemberTransformer->transform($membership, new EmbedBag(['user']));
         }
     } else {
         foreach ($orga->getMemberships() as $membership) {
             $embed['members'][] = $this->orgaMemberTransformer->transform($membership, new EmbedBag());
         }
     }
     return ['_embed' => $embed];
 }
 /**
  *
  *
  * @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)]);
 }
예제 #6
0
 /**
  * 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))]);
 }