示例#1
0
 public function __construct(PagerFanta $data)
 {
     $this->data = $data;
     $this->addMeta('limit', $data->getMaxPerPage());
     $this->addMeta('current_items', count($data->getCurrentPageResults()));
     $this->addMeta('total_items', $data->getNbResults());
     $this->addMeta('offset', $data->getCurrentPageOffsetStart());
 }
示例#2
0
 /**
  * @Route("/{blogId}/search/{search}/{page}", name="icap_blog_view_search", requirements={"blogId" = "\d+", "page" = "\d+"}, defaults={"page" = 1})
  * @ParamConverter("blog", class="IcapBlogBundle:Blog", options={"id" = "blogId"})
  * @Template()
  */
 public function viewSearchAction(Blog $blog, $page, $search)
 {
     $this->checkAccess('OPEN', $blog);
     $user = $this->get('security.token_storage')->getToken()->getUser();
     /** @var \Icap\BlogBundle\Repository\PostRepository $postRepository */
     $postRepository = $this->get('icap.blog.post_repository');
     try {
         /** @var \Doctrine\ORM\QueryBuilder $query */
         $query = $postRepository->searchByBlog($blog, $search, false);
         if (!$this->isUserGranted('EDIT', $blog)) {
             $query->andWhere('post.publicationDate IS NOT NULL')->andWhere('post.status = :publishedStatus')->setParameter('publishedStatus', Statusable::STATUS_PUBLISHED);
         }
         $adapter = new DoctrineORMAdapter($query);
         $pager = new PagerFanta($adapter);
         $pager->setMaxPerPage($blog->getOptions()->getPostPerPage())->setCurrentPage($page);
     } catch (NotValidCurrentPageException $exception) {
         throw new NotFoundHttpException();
     } catch (TooMuchResultException $exception) {
         $this->get('session')->getFlashBag()->add('error', $this->get('translator')->trans('icap_blog_post_search_too_much_result', [], 'icap_blog'));
         $adapter = new ArrayAdapter([]);
         $pager = new PagerFanta($adapter);
         $pager->setCurrentPage($page);
     }
     return ['_resource' => $blog, 'bannerForm' => $this->getBannerForm($blog->getOptions()), 'user' => $user, 'pager' => $pager, 'search' => $search];
 }
示例#3
0
 public function getList($page, $actionsRestriction, $logFilterFormType, $workspaceIds = null, $maxResult = -1, $resourceNodeIds = null, $resourceClass = null)
 {
     $request = $this->container->get('request');
     $data = $request->query->all();
     $action = null;
     $range = null;
     $userSearch = null;
     $dateRangeToTextTransformer = new DateRangeToTextTransformer($this->container->get('translator'));
     if (array_key_exists('filter', $data)) {
         $decodeFilter = json_decode(urldecode($data['filter']));
         if ($decodeFilter !== null) {
             $action = $decodeFilter->action;
             $range = $dateRangeToTextTransformer->reverseTransform($decodeFilter->range);
             $userSearch = $decodeFilter->user;
         }
     } else {
         $dataClass['resourceClass'] = $resourceClass ? $resourceClass : null;
         $tmpForm = $this->container->get('form.factory')->create($logFilterFormType, $dataClass);
         $tmpForm->submit($request);
         $formData = $tmpForm->getData();
         $action = isset($formData['action']) ? $formData['action'] : null;
         $range = isset($formData['range']) ? $formData['range'] : null;
         $userSearch = isset($formData['user']) ? $formData['user'] : null;
     }
     if ($range == null) {
         $range = $this->getDefaultRange();
     }
     $data = array();
     $data['action'] = $action;
     $data['range'] = $range;
     $data['user'] = $userSearch;
     if ($resourceClass !== null) {
         $data['resourceClass'] = $resourceClass;
     }
     $filterForm = $this->container->get('form.factory')->create($logFilterFormType, $data);
     $data['range'] = $dateRangeToTextTransformer->transform($range);
     $filter = urlencode(json_encode($data));
     $entityManager = $this->container->get('doctrine.orm.entity_manager');
     /** @var \Claroline\CoreBundle\Repository\Log\LogRepository $repository */
     $repository = $entityManager->getRepository('ClarolineCoreBundle:Log\\Log');
     //Find if action refers to an resource type
     $actionString = $action;
     $resourceType = null;
     preg_match('/\\[\\[([^\\]]+)\\]\\]/', $action, $matches);
     if (!empty($matches)) {
         $resourceType = $matches[1];
         $actionString = preg_replace('/\\[\\[([^\\]]+)\\]\\]/', '', $action);
         $actionString = trim($actionString);
     }
     $query = $repository->findFilteredLogsQuery($actionString, $range, $userSearch, $actionsRestriction, $workspaceIds, $maxResult, $resourceType, $resourceNodeIds);
     $adapter = new DoctrineORMAdapter($query);
     $pager = new PagerFanta($adapter);
     $pager->setMaxPerPage(self::LOG_PER_PAGE);
     try {
         $pager->setCurrentPage($page);
     } catch (NotValidCurrentPageException $e) {
         throw new NotFoundHttpException();
     }
     $chartData = $repository->countByDayFilteredLogs($actionString, $range, $userSearch, $actionsRestriction, $workspaceIds, false, $resourceType, $resourceNodeIds);
     //List item delegation
     $views = $this->renderLogs($pager->getCurrentPageResults());
     //$views = array();
     return array('pager' => $pager, 'listItemViews' => $views, 'filter' => $filter, 'filterForm' => $filterForm->createView(), 'chartData' => $chartData);
 }
示例#4
0
 public function countByUser($page, $actionsRestriction, $logFilterFormType, $workspaceIds = null, $resourceNodeIds = null, $resourceClass = null)
 {
     $page = max(1, $page);
     $dateRangeToTextTransformer = new DateRangeToTextTransformer($this->container->get('translator'));
     $data = $this->processFormData($actionsRestriction, $logFilterFormType, $workspaceIds, $resourceClass, $dateRangeToTextTransformer);
     $range = $data['range'];
     $orderBy = 'name';
     if (isset($data['orderBy'])) {
         $orderBy = $data['orderBy'];
     }
     $order = 'ASC';
     if (isset($data['order'])) {
         $order = $data['order'];
     }
     $filterForm = $this->container->get('form.factory')->create($logFilterFormType, $data);
     $data['range'] = $dateRangeToTextTransformer->transform($range);
     //Find if action refers to an resource type
     $actionData = $this->getResourceTypeFromAction($data['action']);
     $actionString = $actionData['action'];
     $resourceType = $actionData['resourceType'];
     $nbUsers = $this->logRepository->countTopUsersByAction($actionString, $range, $data['user'], $actionsRestriction, $workspaceIds, $resourceType, $resourceNodeIds, false);
     $maxResult = self::LOG_PER_PAGE;
     if (($page - 1) * $maxResult > $nbUsers) {
         throw new NotFoundHttpException();
     }
     $topUsers = $this->logRepository->topUsersByActionQuery($actionString, $range, $data['user'], $actionsRestriction, $workspaceIds, $maxResult, $resourceType, $resourceNodeIds, false, $page, $orderBy, $order)->getResult();
     $formatedData = $this->formatTopUserDataArray($topUsers);
     $resultUserList = null;
     if (!empty($formatedData)) {
         $userActionsByDay = $this->logRepository->findUserActionsByDay($actionString, $range, $actionsRestriction, $workspaceIds, $resourceType, $resourceNodeIds, $formatedData['ids']);
         $userActionsByDay[] = null;
         $resultUserList = $formatedData['userData'];
         $currentUserId = null;
         $userActionsArray = [];
         foreach ($userActionsByDay as $userAction) {
             if ($userAction === null || $currentUserId !== null && $currentUserId !== $userAction['id']) {
                 $resultUserList[$currentUserId]['stats'] = $this->logRepository->extractChartData($userActionsArray, $range);
                 $resultUserList[$currentUserId]['maxValue'] = max(array_column($userActionsArray, 'total'));
                 $userActionsArray = [];
             }
             if ($userAction !== null) {
                 $currentUserId = $userAction['id'];
                 $userActionsArray[] = $userAction;
             }
         }
     }
     $adapter = new FixedAdapter($nbUsers, $resultUserList);
     $pager = new PagerFanta($adapter);
     $pager->setMaxPerPage(self::LOG_PER_PAGE);
     $pager->setCurrentPage($page);
     return ['pager' => $pager, 'filter' => $data, 'filterForm' => $filterForm->createView(), 'actionName' => $actionString, 'orderBy' => $orderBy, 'order' => $order];
 }