public function colFilter($field, $on = false) { $ret = []; $sqlBuilder = $this->sqlBuilder('question'); $var = $sqlBuilder->sqlDistinctValByField($field); $sql = $var['sql']; $params = $var['params']; $stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt->execute($params); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) { $value = $row['val']; if ($field == 'appli') { $caption = implode(' ', phrasea::modulesName($this->app['translator'], @unserialize($row['val']))); } elseif ($field == "ddate") { $caption = $this->app['date-formatter']->getPrettyString(new DateTime($value)); } else { $caption = $row['val']; } $ret[] = ['val' => $caption, 'value' => $value]; } return $ret; }
/** * @desc build the result from the specified sql * @param array $champ all the field from the request displayed in a array * @param string $sql the request from buildreq * @return $this->result */ protected function buildResult(Application $app, $rs) { $i = 0; foreach ($rs as $row) { if ($this->enable_limit && $i > $this->nb_record) { break; } foreach ($this->champ as $key => $value) { if (!isset($row[$value])) { $this->result[$i][$value] = '<i>' . $this->app->trans('report:: non-renseigne') . '</i>'; continue; } if ($value == 'appli') { $applis = false; if (($applis = @unserialize($row[$value])) !== false) { if (empty($applis)) { $this->result[$i][$value] = '<i>' . $this->app->trans('report:: non-renseigne') . '</i>'; } else { $this->result[$i][$value] = implode(' ', phrasea::modulesName($this->app['translator'], $applis)); } } else { $this->result[$i][$value] = '<i>' . $this->app->trans('report:: non-renseigne') . '</i>'; } } elseif ($value == 'ddate') { $this->result[$i][$value] = $this->pretty_string ? $this->app['date-formatter']->getPrettyString(new DateTime($row[$value])) : $row[$value]; } else { $this->result[$i][$value] = $row[$value]; } } $i++; } }
/** * @desc report the most consulted module by the users * @param array $tab * @return array */ public function buildTabModule($tab = false) { $this->initialize(); $sqlBuilder = new module_report_sql($this->app, $this); $filter = $sqlBuilder->getFilters(); $this->title = $this->app->trans('report:: modules'); $x = []; $tab_appli = []; $this->total_pourcent = $this->setTotalPourcent(); if (is_null($this->total_pourcent)) { return $this->report; } $report_filter = $filter->getReportFilter(); $params = array_merge([], $report_filter['params']); $sql = ' SELECT appli FROM log FORCE INDEX (date_site) WHERE ' . $report_filter['sql'] . ' AND appli != \'a:0:{}\' AND !ISNULL(usrid) GROUP BY appli'; // no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND); $this->initialize(); $stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt->execute($params); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) { $applis = false; if (($applis = @unserialize($row['appli'])) !== false) { array_push($x, phrasea::modulesName($this->app['translator'], $applis)); } else { array_push($x, 'NULL'); } } foreach ($x as $key => $tab_value) { if (is_array($tab_value)) { foreach ($tab_value as $key2 => $value) { if (!isset($tab_appli[$value])) { $tab_appli[$value] = 0; } $tab_appli[$value]++; } } } $total = array_sum($tab_appli); $this->setChamp($rs); $this->setDisplay($tab); foreach ($tab_appli as $appli => $nb) { $pourcent = round($nb / $total * 100, 1); foreach ($this->champ as $key => $value) { $this->result[] = ['appli' => $appli, 'nb' => $nb, 'pourcent' => $pourcent . '%']; } $this->report['value'][] = $nb; $this->report['legend'][] = $appli; } $this->total = sizeof($this->result); $this->calculatePages(); $this->setDisplayNav(); $this->setReport(); return $this->report; }
/** * @desc report the most consulted module by the users * @param array $tab * @return array */ public function buildTabModule($tab = false) { $this->initialize(); $sqlBuilder = new module_report_sql($this->app, $this); $filter = $sqlBuilder->getFilters(); $this->title = $this->app->trans('report:: modules'); $x = []; $tab_appli = []; $this->total_pourcent = $this->setTotalPourcent(); if (is_null($this->total_pourcent)) { return $this->report; } $report_filter = $filter->getReportFilter(); $params = array_merge([], $report_filter['params']); $sql = ' SELECT tt.appli FROM ( SELECT DISTINCT(log.id), appli FROM log FORCE INDEX (date_site, appli) INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE ' . $report_filter['sql'] . ' AND appli != \'a:0:{}\' ) AS tt GROUP BY tt.appli'; $this->initialize(); $stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt->execute($params); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) { $applis = false; if (($applis = @unserialize($row['appli'])) !== false) { array_push($x, phrasea::modulesName($this->app['translator'], $applis)); } else { array_push($x, 'NULL'); } } foreach ($x as $key => $tab_value) { if (is_array($tab_value)) { foreach ($tab_value as $key2 => $value) { if (!isset($tab_appli[$value])) { $tab_appli[$value] = 0; } $tab_appli[$value]++; } } } $total = array_sum($tab_appli); $this->setChamp($rs); $this->setDisplay($tab); foreach ($tab_appli as $appli => $nb) { $pourcent = round($nb / $total * 100, 1); foreach ($this->champ as $key => $value) { $this->result[] = ['appli' => $appli, 'nb' => $nb, 'pourcent' => $pourcent . '%']; } $this->report['value'][] = $nb; $this->report['legend'][] = $appli; } $this->total = sizeof($this->result); $this->calculatePages(); $this->setDisplayNav(); $this->setReport(); return $this->report; }
public function getPostingFilter() { if (sizeof($this->tab_filter) > 0) { foreach ($this->tab_filter as $key => $filter) { if (empty($filter['v'])) { $value = $this->app->trans('report:: non-renseigne'); } else { $value = $filter['v']; } switch ($filter['f']) { case 'user': $field = $this->app->trans('phraseanet::utilisateurs'); break; case 'ddate': $field = $this->app->trans('report:: date'); break; case 'ip': $field = $this->app->trans('report:: IP'); break; case 'appli': $field = $this->app->trans('report:: modules'); break; case 'fonction': $field = $this->app->trans('report::fonction'); break; case 'activite': $field = $this->app->trans('report::activite'); break; case 'pays': $field = $this->app->trans('report::pays'); break; case 'societe': $field = $this->app->trans('report::societe'); break; case 'record_id': $field = $this->app->trans('report:: record id'); break; case 'final': $field = $this->app->trans('phraseanet:: sous definition'); break; case 'coll_id': $field = $this->app->trans('report:: collections'); break; case 'comment': $field = $this->app->trans('report:: commentaire'); break; case 'search': $field = $this->app->trans('report:: question'); break; default: $field = $filter['f']; break; } if ($filter['f'] == 'appli') { $value = implode(' ', phrasea::modulesName($this->app['translator'], @unserialize($value))); } elseif ($filter['f'] == "ddate") { $value = $this->app['date-formatter']->getPrettyString(new DateTime($value)); } $this->posting_filter[] = ['f' => $field, 'v' => $value]; } } return $this->posting_filter; }