示例#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
 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);
 }
示例#3
0
 public function getList($page, $actionsRestriction, $logFilterFormType, $workspaceIds = null, $maxResult = -1, $resourceNodeIds = null, $resourceClass = null)
 {
     $dateRangeToTextTransformer = new DateRangeToTextTransformer($this->container->get('translator'));
     $data = $this->processFormData($actionsRestriction, $logFilterFormType, $workspaceIds, $resourceClass, $dateRangeToTextTransformer);
     $range = $data['range'];
     $filterForm = $this->container->get('form.factory')->create($logFilterFormType, $data);
     $data['range'] = $dateRangeToTextTransformer->transform($range);
     $filter = urlencode(json_encode($data));
     //Find if action refers to an resource type
     $actionData = $this->getResourceTypeFromAction($data['action']);
     $actionString = $actionData['action'];
     $resourceType = $actionData['resourceType'];
     $query = $this->logRepository->findFilteredLogsQuery($actionString, $range, $data['user'], $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 = $this->logRepository->countByDayFilteredLogs($actionString, $range, $data['user'], $actionsRestriction, $workspaceIds, false, $resourceType, $resourceNodeIds);
     //List item delegation
     $views = $this->renderLogs($pager->getCurrentPageResults());
     return ['pager' => $pager, 'listItemViews' => $views, 'filter' => $filter, 'filterForm' => $filterForm->createView(), 'chartData' => $chartData, 'actionName' => $actionString];
 }