/** * 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; }