Esempio n. 1
0
 /**
  * Set Report configuration according to request parameters
  *
  * @param  Application    $app     An application instance
  * @param  Request        $request A request instance
  * @param  \module_report $report  A report instance
  * @param  Array          $conf    A report column configuration
  * @param  Boolean        $what    Whether to group on a particular field or not
  * @return Array
  */
 private function doReport(Application $app, Request $request, \module_report $report, $conf, $what = false)
 {
     if ($app['conf']->get(['registry', 'modules', 'anonymous-report']) == true) {
         if (isset($conf['user'])) {
             unset($conf['user']);
         }
         if (isset($conf['ip'])) {
             unset($conf['ip']);
         }
     }
     //save initial conf
     $base_conf = $conf;
     //format conf according user preferences
     if ('' !== ($columnsList = $request->request->get('list_column', ''))) {
         $new_conf = $conf;
         $columns = explode(',', $columnsList);
         foreach (array_keys($conf) as $col) {
             if (!in_array($col, $columns)) {
                 unset($new_conf[$col]);
             }
         }
         $conf = $new_conf;
     }
     //display content of a table column when user click on it
     if ($request->request->get('conf') == 'on') {
         return $app->json(['liste' => $app['twig']->render('report/listColumn.html.twig', ['conf' => $base_conf]), 'title' => $app->trans('configuration')]);
     }
     //set order
     if ('' !== ($order = $request->request->get('order', '')) && '' !== ($field = $request->request->get('champ', ''))) {
         $report->setOrder($field, $order);
     }
     //work on filters
     $mapColumnTitleToSqlField = $report->getTransQueryString();
     $currentfilter = [];
     if ('' !== ($serializedFilter = $request->request->get('liste_filter', ''))) {
         $currentfilter = @unserialize(urldecode($serializedFilter));
     }
     $filter = new \module_report_filter($app, $currentfilter, $mapColumnTitleToSqlField);
     if ('' !== ($filterColumn = $request->request->get('filter_column', ''))) {
         $field = current(explode(' ', $filterColumn));
         $value = $request->request->get('filter_value', '');
         if ($request->request->get('liste') == 'on') {
             return $app->json(['diag' => $app['twig']->render('report/colFilter.html.twig', ['result' => $report->colFilter($field), 'field' => $field]), 'title' => $app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])]);
         }
         if ($field === $value) {
             $filter->removeFilter($field);
         } else {
             $filter->addFilter($field, '=', $value);
         }
     }
     //set new request filter if user asking for them
     if ($request->request->get('precise') == 1) {
         $filter->addFilter('xml', 'LIKE', $request->request->get('word', ''));
     } elseif ($request->request->get('precise') == 2) {
         $filter->addFilter('record_id', '=', $request->request->get('word', ''));
     }
     //set filters to current report
     $report->setFilter($filter->getTabFilter());
     $report->setActiveColumn($filter->getActiveColumn());
     $report->setPostingFilter($filter->getPostingFilter());
     // display a new arraywhere results are group
     if ('' !== ($groupby = $request->request->get('groupby', ''))) {
         $report->setConfig(false);
         $groupby = current(explode(' ', $groupby));
         $reportArray = $report->buildReport(false, $groupby);
         if (count($reportArray['allChamps']) > 0 && count($reportArray['display']) > 0) {
             $groupField = isset($reportArray['display'][$reportArray['allChamps'][0]]['title']) ? $reportArray['display'][$reportArray['allChamps'][0]]['title'] : '';
         } else {
             $groupField = isset($conf[strtolower($groupby)]['title']) ? $conf[strtolower($groupby)]['title'] : '';
         }
         return $app->json(['rs' => $app['twig']->render('report/ajax_data_content.html.twig', ['result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray, 'is_infouser' => false, 'is_nav' => false, 'is_groupby' => true, 'is_plot' => false, 'is_doc' => false]), 'display_nav' => false, 'title' => $app->trans('Groupement des resultats sur le champ %name%', ['%name%' => $groupField])]);
     }
     //set Limit
     if ($report->getEnableLimit() && '' !== ($page = $request->request->get('page', '')) && '' !== ($limit = $request->request->get('limit', ''))) {
         $report->setLimit($page, $limit);
     } else {
         $report->setLimit(false, false);
     }
     //time to build our report
     if (false === $what) {
         $reportArray = $report->buildReport($conf);
     } else {
         $reportArray = $report->buildReport($conf, $what, $request->request->get('tbl', false));
     }
     return $reportArray;
 }
Esempio n. 2
0
 public function testGetterSetter()
 {
     $report = new module_report(self::$DI['app'], $this->dmin, $this->dmax, 1, '');
     $bool = true;
     $report->setPrettyString($bool);
     $this->assertEquals($bool, $report->getPrettyString());
     $title = 'test';
     $report->setTitle($title);
     $this->assertEquals($title, $report->getTitle());
     $bool = false;
     $report->setCsv($bool);
     $this->assertEquals($bool, $report->getCsv());
     $filter = ['test', 'array'];
     $report->setFilter($filter);
     $this->assertEquals($filter, $report->getTabFilter());
     $periode = "2 years";
     $report->setPeriode($periode);
     $this->assertEquals($periode, $report->getPeriode());
     $postingFilter = 'my posting filter !';
     $report->setpostingFilter($postingFilter);
     $this->assertEquals($postingFilter, $report->getPostingFilter());
     $page = 223;
     $limit = 125;
     $report->setLimit($page, $limit);
     $this->assertEquals($page, $report->getNbPage());
     $this->assertEquals($limit, $report->getNbRecord());
     $report->setGroupBy($bool);
     $this->assertEquals($bool, $report->getGroupBy());
     $column = ['col1', 'col2'];
     $report->setActiveColumn($column);
     $this->assertEquals($column, $report->getActiveColumn());
     $report->setConfig($bool);
     $report->setPrint($bool);
     $report->setHasLimit($bool);
     $this->assertFalse($report->getConfig());
     $this->assertFalse($report->getPrint());
     $this->assertFalse($report->getHasLimit());
     $result = ['result', 'result'];
     $report->setResult($result);
     $this->assertEquals($result, $report->getResult());
     $total = 3200;
     $report->setTotal($total);
     $this->assertEquals($total, $report->getTotal());
     $default_display = ['a', 'b', 'c'];
     $report->setDefault_display($default_display);
     $this->assertEquals($default_display, $report->getDefault_display());
 }