Paginated list of contents

@param Request $request
@param Application $app
@param Paginator $paginator

@return array
769789
public function page(Request $request, Application $app, Paginator $paginator)
    {
        return array_merge(
            ['pages' => count($paginator)],
            $this->extractViewParameters($request, ['app', 'paginator'])
        );
    }
702785
public function listAction(Request $request, Response $response, array $args)
    {
        $entities = $this->em->getRepository($this->entityClass)->findAll();

        $response->setContent($this->twig->render($this->views['list'], [
            'entities' => $entities
        ]));

        return $response;
    }
812771
public function getPage(Request $request)
    {
        $parameters = $this->fixParameters($request->query->all());

        $transUnits = $this->storage->getTransUnitList(
            $this->localeManager->getLocales(),
            $request->query->get('rows', 20),
            $request->query->get('page', 1),
            $parameters
        );

        $count = $this->storage->countTransUnits($this->localeManager->getLocales(), $parameters);

        return array($transUnits, $count);
    }
128647
public static function findAll($page_request = null)
    {
        if($page_request != null){
            return self::listAllGateways(['page' => $page_request->getPageNumber(), 'size' => $page_request->getSize() ]);
        }else {
            return self::listAllGateways();
        }
    }
337457
protected function getPageApplicationData(PageApplicationInterface $application)
	{
		return array(
			'id'		=> $application->getId(),
			'title'		=> $application->getTitle(),
			'icon'		=> $application->getIcon(),
			'isDropTarget' => $application->getAllowChildren(),
			'childInsertPolicy' => $application->getNewChildInsertPolicy(),
		);
	}
96502
public function newPagePartAction(Request $request)
    {
        $em = $this->get('doctrine.orm.entity_manager');

        $pageId = $request->get('pageid');
        $pageClassName = $request->get('pageclassname');
        $context = $request->get('context');
        $pagePartClass = $request->get('type');

        /** @var HasPagePartsInterface $page */
        $page = $em->getRepository($pageClassName)->find($pageId);

        if (false === $page instanceof HasPagePartsInterface) {
            throw new \RuntimeException(sprintf('Given page (%s:%d) has no pageparts', $pageClassName, $pageId));
        }

        $pagePartConfigurationReader = $this->container->get('kunstmaan_page_part.page_part_configuration_reader');
        $pagePartAdminConfigurators = $pagePartConfigurationReader->getPagePartAdminConfigurators($page);

        $pagePartAdminConfigurator = null;
        foreach ($pagePartAdminConfigurators as $ppac) {
            if ($context == $ppac->getContext()) {
                $pagePartAdminConfigurator = $ppac;
            }
        }

        if (is_null($pagePartAdminConfigurator)) {
            throw new \RuntimeException(sprintf('No page part admin configurator found for context "%s".', $context));
        }

        $pagePartAdmin = new PagePartAdmin($pagePartAdminConfigurator, $em, $page, $context, $this->container);
        /** @var PagePartInterface $pagePart */
        $pagePart = new $pagePartClass();

        if (false === $pagePart instanceof PagePartInterface) {
            throw new \RuntimeException(sprintf(
                'Given pagepart expected to implement PagePartInterface, %s given',
                $pagePartClass
            ));
        }

        $formFactory = $this->container->get('form.factory');
        $formBuilder = $formFactory->createBuilder(FormType::class);
        $pagePartAdmin->adaptForm($formBuilder);
        $id = 'newpp_' . time();

        $data = $formBuilder->getData();
        $data['pagepartadmin_' . $id] = $pagePart;

        $formBuilder->add('pagepartadmin_' . $id, $pagePart->getDefaultAdminType());
        $formBuilder->setData($data);
        $form = $formBuilder->getForm();
        $formview = $form->createView();
        $extended = $this->getParameter('kunstmaan_page_part.extended');

        return [
            'id' => $id,
            'form' => $formview,
            'pagepart' => $pagePart,
            'pagepartadmin' => $pagePartAdmin,
            'page' => $pagePartAdmin->getPage(),
            'editmode' => true,
            'extended' => $extended,
        ];
    }
895148
public static function findAll($page_request = null)
    {
        if($page_request != null){
            return self::listAllCancelOperations(['page' => $page_request->getPageNumber(), 'size' => $page_request->getSize() ]);
        }else {
            return self::listAllCancelOperations();
        }
    }
689490
public function listAction(Request $request)
    {
        $current_page = $request->get('page', 1);
        $current_page = $current_page > 1 ? $current_page : 1;
        $rep = $this->getRepository();

        // filter list notice
        $filter = $this->createForm('notices_filter')->handleRequest($request);
        if ($filter->isValid()) {
            $query = $rep->getFilteredQuery($filter->getData()['status'], $filter->getData()['type']);
        } else {
            $query = $rep->createQueryBuilder('n');
        }
        $query
            ->orderBy('n.date_created', 'DESC')
            ->setFirstResult(($current_page - 1) * self::NOTICE_PER_PAGE)
            ->setMaxResults(self::NOTICE_PER_PAGE);
        $list = $query->getQuery()->getResult();

        // get count all items
        $count = $query
            ->select('COUNT(n)')
            ->getQuery()
            ->getSingleScalarResult();

        // pagination
        $that = $this;
        $request_query = $request->query->all();
        unset($request_query['page']);
        $pagination = $this->get('anime_db.pagination')
            ->create(ceil($count / self::NOTICE_PER_PAGE), $current_page)
            ->setPageLink(function ($page) use ($that, $request_query) {
                return $that->generateUrl('notice_list', array_merge($request_query, ['page' => $page]));
            })
            ->setFirstPageLink($this->generateUrl('notice_list', $request_query))
            ->getView();

        return $this->render('AnimeDbCatalogBundle:Notice:list.html.twig', [
            'list' => $list,
            'pagination' => $pagination,
            'change_form' => $this->createForm(new ChangeNotice())->createView(),
            'filter' => $filter->createView(),
            'action_remove' => ChangeNotice::ACTION_REMOVE,
        ]);
    }
267477
public function pagination($criteria, $params = [], $pageSize = 10, $pageNo = null)
    {
        return (new Pagination($criteria, $params, $this))->getData($pageSize, $pageNo);
    }
563727
public function getList($params = array(), ServiceManager $sm) 
	{
		$page = isset($params['page']) ? (int)$params['page'] : 1;
		unset($params['page']);
		
		$params['limit'] = isset($params['limit']) ? (int) $params['limit'] : 30;
		// The eventual presence of 'offset' key has priority over calculated 'page' value
		$params['offset'] = isset($params['offset']) ? (int) $params['offset'] : ($page * $params['limit'] - $params['limit']);
		
		$routeName = 'UserUser/page';
		$routeParams = array('page' => $page);
		
		$paginator = $this->getPaginator($params);
		
		$data = array();
		foreach($paginator as $user) {
			$data[] = $this->get($user, $sm);
		}
		
		unset($params['limit']);
		unset($params['offset']);
		$queryParams = $params;

		$mainService = $sm->get('neobazaar.service.main');
		return array(
			'data' => $data,
			'paginationData' => Json::decode($mainService->getView()->paginationControl(
				$paginator,
				'Sliding',
				array('pagination/paginatorjson', 'Document'),
				array(
					'route' => $routeName,
					'params' => $routeParams, 
					'query' => $queryParams
				)
			))
		);
	}
992463
public function handle(Request $request, Application $app = null)
    {
        $this->request = $request;

        try {
            // init services providers
            /** @var \Alchemy\Service\ServiceProviderInterface $providers */
            $providers = $app->getServiceProviders();

            foreach ($providers as $provider) {
                $provider->init($app);
            }


            /*
             * "EVENT" KernelEvents::REQUEST using GetResponse Event
             *
             * This event can be used by an application to filter a request before
             * ever all kernel logic being executed, listeners for this event should
             * be registered outside framework logic (should be on application logic).
             */
            if ($this->dispatcher->hasListeners(KernelEvents::REQUEST)) {
                $event = new GetResponseEvent($this, $request, $app);
                $this->dispatcher->dispatch(KernelEvents::REQUEST, $event);

                if ($event->hasResponse()) {
                    //var_dump($event->getResponse()); die("ee");
                    $event = new FilterResponseEvent($this, $request, $event->getResponse());
                    $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);

                    return $event->getResponse();
                }
            }

            /*
             * try match the url request with a defined route.
             * it any route match the current url a ResourceNotFoundException
             * will be thrown.
             */
            $params = $this->mapper->match($request);
            $uriParams = $params["params"];

            // prepare request params.
            $params = $this->prepareRequestParams(array($params["mapped"], $request->query->all(), $request->request->all()));

            // add prepared params to request as attributes.
            $request->attributes->add($params);

            // resolve controller
            try {
                $controller = $this->resolver->getController($request);
            } catch (\Exception $exception) {
                /*
                 * Detailed exception types are only for development environments
                 * if the current is a non dev environment just overrides the current exception with
                 * a ResourceNotFoundException exception
                 */
                if ($this->config->get('env.type') !== 'dev') {
                    $exception = new ResourceNotFoundException($request->getPathInfo());
                }

                throw $exception;
            }

            if (! $controller) {
                throw new ResourceNotFoundException($request->getPathInfo());
            }

            // setting default annotations namespace
            $this->annotationReader->setDefaultNamespace('\Alchemy\Annotation\\');
            // seeting annotation reader target
            $this->annotationReader->setTarget($params['_controllerClass'], $params['_controllerMethod']);

            $arguments = $this->resolver->getArguments($app, $request, $controller);

            //"EVENT" FILTER_CONTROLLER
            if ($this->dispatcher->hasListeners(KernelEvents::FILTER_CONTROLLER)) {
                $event = new FilterControllerEvent($this, $controller, $request);
                $this->dispatcher->dispatch(KernelEvents::FILTER_CONTROLLER, $event);

                // getting controller; this can be the same or other filtered controller
                $controller = $event->getController();
            }

            //"EVENT" BEFORE_CONTROLLER
            if ($this->dispatcher->hasListeners(KernelEvents::BEFORE_CONTROLLER)) {
                $event = new ControllerEvent($this, $controller, $arguments, $request);
                $this->dispatcher->dispatch(KernelEvents::BEFORE_CONTROLLER, $event);
            }

            // Execute controller action
            $response = call_user_func_array($controller, $arguments);

            // check returned value by method is a array
            if (is_array($response)) {
                // set controller view data object
                foreach ($response as $key => $value) {
                    $controller[0]->view->$key = $value;
                }
            }

            // getting controller's data.
            $controllerData = (array) $controller[0]->view;

            if (! ($response instanceof Response || $response instanceof JsonResponse)) {
                if ($this->annotationReader->getAnnotation('JsonResponse')) {
                    $controllerData = $response;
                    $response = new JsonResponse();
                    $response->setData($controllerData);
                } else {
                    $response = new Response();
                }
            }

            //"EVENT" AFTER_CONTROLLER
            if ($this->dispatcher->hasListeners(KernelEvents::AFTER_CONTROLLER)) {
                if (!isset($event) || !($event instanceof ControllerEvent)) {
                    $event = new ControllerEvent($this, $controller, $arguments, $request);
                }
                $event->setResponse($response);

                $this->dispatcher->dispatch(KernelEvents::AFTER_CONTROLLER, $event);
            }

            // handling view
            $view = $this->handleView(
                $params['_controllerClass'],
                $params['_controllerMethod'],
                $controllerData,
                $this->annotationReader->getAnnotation('View')
            );

            // handling meta ui
            if ($this->annotationReader->getAnnotation('ServeUi')) {
                $view = $this->handleMetaUi(
                    $controllerData,
                    $this->annotationReader->getAnnotation('ServeUi'),
                    $view,
                    $request
                );
            }

            // if there is a view adapter instance, get its contents and set to response content
            if (! empty($view)) {
                foreach ($uriParams as $keyParam => $valParam) {
                    $view->assign($keyParam, $valParam);
                }

                //"EVENT" VIEW dispatch all KernelEvents::VIEW events
                if ($this->dispatcher->hasListeners(KernelEvents::VIEW)) {
                    $event = new ViewEvent($this, $view, $request, $this->annotationReader, $app);
                    $this->dispatcher->dispatch(KernelEvents::VIEW, $event);
                    $view = $event->getView();
                }

                $response->setContent($view->getOutput());
            }

        } catch (ResourceNotFoundException $e) {
            $exceptionHandler = new Exception\Handler();

            if ($request->isXmlHttpRequest()) {
                $response = new JsonResponse();
                $response->setData(array('success'=>false, 'message'=>$e->getMessage()));
            } else {
                $response = new Response($exceptionHandler->getOutput($e), 404);
            }
        } catch (\Exception $e) {
//            echo $e->getMessage();
//            echo "<br><pre>";
//            echo $e->getTraceAsString();
//            die;

            $exceptionHandler = new Exception\Handler();

            if ($request->isXmlHttpRequest()) {
                $response = new JsonResponse();
                $response->setData(array('success'=>false, 'message'=>$e->getMessage()));
            } else {
                $response = new Response($exceptionHandler->getOutput($e), 500);
            }
        }

        if ($this->annotationReader->hasTarget()) {
            $responseAnnotation = $this->annotationReader->getAnnotation('Response');
        } else {
            $responseAnnotation = null;
        }

        // dispatch a response event
        $this->dispatcher->dispatch(
            KernelEvents::RESPONSE,
            new FilterResponseEvent($this, $request, $response, $responseAnnotation)
        );

        return $response;
    }
260185
public function indexAction(Request $request)
    {

        $page = $request->get("page", 1);
        $em = $this->getDoctrine()->getManager();
        $dql = "SELECT p FROM AmulenPageBundle:Page p";
        $query = $em->createQuery($dql);
        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate($query, $this->get('request')->query->get('page', $page));

        return array(
            'pagination' => $pagination,
        );
    }
158946
public function defaultIndexAction(Application $app, Request $request)
    {
        return $this->renderIndex($app, array(
            'entities' => $app->getRepository($this->getModelName())->findAll(),
        ));
    }
728589
protected function paginate(Request $request)
    {
        return $this->jobs->getFailed($request->query('starting_at') ?: -1)->map(function ($job) {
            return $this->decode($job);
        });
    }
1163759
public function beforeRequest(Request $request, Application $app)
    {
        if ($canonical = $this->getCanonicalUrl($request)) {
            $request->attributes->set('_canonical', $canonical);
            $app['twig']->addGlobal('canonical', $canonical);
        }

        if ($root = $this->getRootUrl($request)) {
            $request->attributes->set('_root', $root);
            $app['twig']->addGlobal('root', $root);
        }
    }
984736
def paginate(self, request, collection):
        
        p = Paginator(request, self, collection)
        return p.paginator and p or UpdatedList(collection)
676275
public function findPaginated(
        $entityClass,
        array $criteria,
        $sorting = [],
        $offset = Request\Params::DEFAULT_PAGE_OFFSET,
        $limit = Request\Params::DEFAULT_PAGE_SIZE,
        $translatable = false
    )
    {
        $qb = $this->getQueryBuilder($entityClass, $criteria, $sorting, $translatable);
        
        $qb->setFirstResult($offset)
            ->setMaxResults($limit);

        $paginator = new Paginator($qb->getQuery());
        $collection = new PaginatedCollection($paginator);

        return $collection;
    }