/**
  * @ApiDoc(
  * resource=true,
  *  description="Returns a collection of Performances",
  *  statusCodes={
  *      200="Returned when all parameters were correct",
  *      404="Returned when the entity is not found",
  *  },
  *  output = "array<AppBundle\Model\PerformancesResponse>"
  * )
  *
  * @QueryParam(name="limit", requirements="\d+", default="10", description="Count entries at one page")
  * @QueryParam(name="page", requirements="\d+", default="1", description="Number of page to be shown")
  * @QueryParam(name="locale", requirements="^[a-zA-Z]+", default="uk", description="Selects language of data you want to receive")
  *
  * @RestView
  */
 public function cgetAction(ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $performances = $em->getRepository('AppBundle:Performance')->findBy(['festival' => null], null, $paramFetcher->get('limit'), ($paramFetcher->get('page') - 1) * $paramFetcher->get('limit'));
     $performancesTranslated = array();
     foreach ($performances as $performance) {
         $performance->setLocale($paramFetcher->get('locale'));
         $em->refresh($performance);
         if ($performance->getTranslations()) {
             $performance->unsetTranslations();
         }
         $performancesTranslated[] = $performance;
     }
     $performances = $performancesTranslated;
     $performancesResponse = new PerformancesResponse();
     $performancesResponse->setPerformances($performances);
     $performancesResponse->setTotalCount($this->getDoctrine()->getManager()->getRepository('AppBundle:Performance')->getCount());
     $performancesResponse->setPageCount(ceil($performancesResponse->getTotalCount() / $paramFetcher->get('limit')));
     $performancesResponse->setPage($paramFetcher->get('page'));
     $self = $this->generateUrl('get_performances', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page')], true);
     $first = $this->generateUrl('get_performances', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit')], true);
     $nextPage = $paramFetcher->get('page') < $performancesResponse->getPageCount() ? $this->generateUrl('get_performances', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page') + 1], true) : 'false';
     $previsiousPage = $paramFetcher->get('page') > 1 ? $this->generateUrl('get_performances', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page') - 1], true) : 'false';
     $last = $this->generateUrl('get_performances', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $performancesResponse->getPageCount()], true);
     $links = new PaginationLinks();
     $performancesResponse->setLinks($links->setSelf(new Link($self)));
     $performancesResponse->setLinks($links->setFirst(new Link($first)));
     $performancesResponse->setLinks($links->setNext(new Link($nextPage)));
     $performancesResponse->setLinks($links->setPrev(new Link($previsiousPage)));
     $performancesResponse->setLinks($links->setLast(new Link($last)));
     foreach ($performances as $performance) {
         $performance->setLinks([['rel' => 'self', 'href' => $this->generateUrl('get_performance', ['slug' => $performance->getSlug()], true)], ['rel' => 'self.roles', 'href' => $this->generateUrl('get_performance_roles', ['slug' => $performance->getSlug()], true)], ['rel' => 'self.events', 'href' => $this->generateUrl('get_performanceevents', ['performance' => $performance->getSlug()], true)]]);
     }
     return $performancesResponse;
 }
 /**
  * @ApiDoc(
  *  resource=true,
  *  description="Returns a collection of theatre employees.",
  *  statusCodes={
  *      200="Returned when all parameters were correct",
  *      404="Returned when the entities with given limit and offset are not found",
  *  },
  *  output = "array<AppBundle\Model\EmployeesResponse>"
  * )
  *
  * @QueryParam(name="limit", requirements="\d+", default="10", description="Count entries at one page")
  * @QueryParam(name="page", requirements="\d+", default="1", description="Number of page to be shown")
  * @QueryParam(name="locale", requirements="^[a-zA-Z]+", default="uk", description="Selects language of data you want to receive")
  *
  * @RestView
  */
 public function cgetAction(ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $employees = $em->getRepository('AppBundle:Employee')->findBy([], ['lastName' => 'ASC'], $paramFetcher->get('limit'), ($paramFetcher->get('page') - 1) * $paramFetcher->get('limit'));
     $employeesTranslated = array();
     foreach ($employees as $employee) {
         $employee->setLocale($paramFetcher->get('locale'));
         $em->refresh($employee);
         if ($employee->getTranslations()) {
             $employee->unsetTranslations();
         }
         $this->get('translator')->setLocale($paramFetcher->get('locale'));
         $employee->setPosition($this->get('translator')->trans($employee->getPosition()));
         $employeesTranslated[] = $employee;
     }
     $employees = $employeesTranslated;
     $employeesResponse = new EmployeesResponse();
     $employeesResponse->setEmployees($employees);
     $employeesResponse->setTotalCount($this->getDoctrine()->getManager()->getRepository('AppBundle:Employee')->getCount());
     $employeesResponse->setPageCount(ceil($employeesResponse->getTotalCount() / $paramFetcher->get('limit')));
     $employeesResponse->setPage($paramFetcher->get('page'));
     $self = $this->generateUrl('get_employees', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page')], true);
     $first = $this->generateUrl('get_employees', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit')], true);
     $nextPage = $paramFetcher->get('page') < $employeesResponse->getPageCount() ? $this->generateUrl('get_employees', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page') + 1], true) : 'false';
     $previsiousPage = $paramFetcher->get('page') > 1 ? $this->generateUrl('get_employees', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page') - 1], true) : 'false';
     $last = $this->generateUrl('get_employees', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $employeesResponse->getPageCount()], true);
     $links = new PaginationLinks();
     $employeesResponse->setLinks($links->setSelf(new Link($self)));
     $employeesResponse->setLinks($links->setFirst(new Link($first)));
     $employeesResponse->setLinks($links->setNext(new Link($nextPage)));
     $employeesResponse->setLinks($links->setPrev(new Link($previsiousPage)));
     $employeesResponse->setLinks($links->setLast(new Link($last)));
     return $employeesResponse;
 }
 /**
  * @ApiDoc(
  *  resource=true,
  *  description="Returns a collection of History",
  *  statusCodes={
  *      200="Returned when all parameters were correct",
  *      404="Returned when the entities with given limit and offset are not found",
  *  },
  *  output = "array<AppBundle\Model\HistoryResponse>"
  * )
  *
  * @QueryParam(name="limit", requirements="\d+", default="10", description="Count entries at one page")
  * @QueryParam(name="page", requirements="\d+", default="1", description="Number of page to be shown")
  * @QueryParam(name="locale", requirements="^[a-zA-Z]+", default="uk", description="Selects language of data you want to receive")
  *
  * @RestView
  */
 public function cgetAction(ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $history = $em->getRepository('AppBundle:History')->findAllHistory($paramFetcher->get('limit'), ($paramFetcher->get('page') - 1) * $paramFetcher->get('limit'));
     $historyTranslated = [];
     foreach ($history as $hist) {
         $hist->setLocale($paramFetcher->get('locale'));
         $em->refresh($hist);
         if ($hist->getTranslations()) {
             $hist->unsetTranslations();
         }
         $historyTranslated[] = $hist;
     }
     $history = $historyTranslated;
     $historyResponse = new HistoryResponse();
     $historyResponse->setHistory($history);
     $historyResponse->setTotalCount($this->getDoctrine()->getManager()->getRepository('AppBundle:History')->getCount());
     $historyResponse->setPageCount(ceil($historyResponse->getTotalCount() / $paramFetcher->get('limit')));
     $historyResponse->setPage($paramFetcher->get('page'));
     $self = $this->generateUrl('get_histories', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page')], true);
     $first = $this->generateUrl('get_histories', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit')], true);
     $nextPage = $paramFetcher->get('page') < $historyResponse->getPageCount() ? $this->generateUrl('get_histories', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page') + 1], true) : 'false';
     $previsiousPage = $paramFetcher->get('page') > 1 ? $this->generateUrl('get_histories', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page') - 1], true) : 'false';
     $last = $this->generateUrl('get_histories', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $historyResponse->getPageCount()], true);
     $links = new PaginationLinks();
     $historyResponse->setLinks($links->setSelf(new Link($self)));
     $historyResponse->setLinks($links->setFirst(new Link($first)));
     $historyResponse->setLinks($links->setNext(new Link($nextPage)));
     $historyResponse->setLinks($links->setPrev(new Link($previsiousPage)));
     $historyResponse->setLinks($links->setLast(new Link($last)));
     return $historyResponse;
 }
 /**
  * @ApiDoc(
  *  resource=true,
  *  description="Returns a collection of Posts",
  *  statusCodes={
  *      200="Returned when all parameters were correct",
  *      404="Returned when the entities with given limit and offset are not found",
  *  },
  *  output = "array<AppBundle\Model\PostsResponse>"
  * )
  *
  * @QueryParam(name="limit", requirements="\d+", default="10", description="Count entries at one page")
  * @QueryParam(name="page", requirements="\d+", default="1", description="Number of page to be shown")
  * @QueryParam(name="locale", requirements="^[a-zA-Z]+", default="uk", description="Selects language of data you want to receive")
  * @QueryParam(name="tag", description="You can receive posts by Tag slug, without Tag you will receive all posts")
  *
  * @RestView
  */
 public function cgetAction(ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $posts = $em->getRepository('AppBundle:Post')->findAllOrByTag($paramFetcher->get('limit'), ($paramFetcher->get('page') - 1) * $paramFetcher->get('limit'), $paramFetcher->get('tag'));
     $postsTranslated = [];
     foreach ($posts as $post) {
         $post->setLocale($paramFetcher->get('locale'));
         $em->refresh($post);
         if ($post->getTranslations()) {
             $post->unsetTranslations();
         }
         $tags = $post->getTags();
         foreach ($tags as $tag) {
             $tag->setLocale($paramFetcher->get('locale'));
             $em->refresh($tag);
             if ($tag->getTranslations()) {
                 $tag->unsetTranslations();
             }
         }
         $postsTranslated[] = $post;
     }
     $posts = $postsTranslated;
     $postsResponse = new PostsResponse();
     $postsResponse->setPosts($posts);
     $postsResponse->setTotalCount($this->getDoctrine()->getManager()->getRepository('AppBundle:Post')->getCount($paramFetcher->get('tag')));
     $postsResponse->setPageCount(ceil($postsResponse->getTotalCount() / $paramFetcher->get('limit')));
     $postsResponse->setPage($paramFetcher->get('page'));
     $self = $this->generateUrl('get_posts', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page'), 'tag' => $paramFetcher->get('tag')], true);
     $first = $this->generateUrl('get_posts', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'tag' => $paramFetcher->get('tag')], true);
     $nextPage = $paramFetcher->get('page') < $postsResponse->getPageCount() ? $this->generateUrl('get_posts', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page') + 1, 'tag' => $paramFetcher->get('tag')], true) : 'false';
     $previsiousPage = $paramFetcher->get('page') > 1 ? $this->generateUrl('get_posts', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $paramFetcher->get('page') - 1, 'tag' => $paramFetcher->get('tag')], true) : 'false';
     $last = $this->generateUrl('get_posts', ['locale' => $paramFetcher->get('locale'), 'limit' => $paramFetcher->get('limit'), 'page' => $postsResponse->getPageCount(), 'tag' => $paramFetcher->get('tag')], true);
     $links = new PaginationLinks();
     $postsResponse->setLinks($links->setSelf(new Link($self)));
     $postsResponse->setLinks($links->setFirst(new Link($first)));
     $postsResponse->setLinks($links->setNext(new Link($nextPage)));
     $postsResponse->setLinks($links->setPrev(new Link($previsiousPage)));
     $postsResponse->setLinks($links->setLast(new Link($last)));
     return $postsResponse;
 }