Report-VU : fix collection selection, date selectors, csv, ...

disabled log
This commit is contained in:
Jean-Yves Gaulier
2014-10-30 18:53:22 +01:00
parent 7706d7ca10
commit 6a1e161701
14 changed files with 499 additions and 147 deletions

View File

@@ -299,6 +299,10 @@ class Root implements ControllerProviderInterface
*/ */
public function doReportDownloads(Application $app, Request $request) public function doReportDownloads(Application $app, Request $request)
{ {
// no_// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$download = new \module_report_download( $download = new \module_report_download(
$app, $app,
$request->request->get('dmin'), $request->request->get('dmin'),
@@ -307,12 +311,19 @@ class Root implements ControllerProviderInterface
$request->request->get('collection') $request->request->get('collection')
); );
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$conf_pref = array(); $conf_pref = array();
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
foreach (\module_report::getPreff($app, $request->request->get('sbasid')) as $field) { foreach (\module_report::getPreff($app, $request->request->get('sbasid')) as $field) {
$conf_pref[strtolower($field)] = array($field, 0, 0, 0, 0); // $conf_pref[strtolower($field)] = array($field, 0, 0, 0, 0);
$conf_pref[$field] = array($field, 0, 0, 0, 0);
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$conf = array_merge(array( $conf = array_merge(array(
'user' => array(_('report:: utilisateurs'), 1, 1, 1, 1), 'user' => array(_('report:: utilisateurs'), 1, 1, 1, 1),
'ddate' => array(_('report:: date'), 1, 0, 1, 1), 'ddate' => array(_('report:: date'), 1, 0, 1, 1),
@@ -326,21 +337,36 @@ class Root implements ControllerProviderInterface
'societe' => array(_('report:: societe'), 1, 1, 1, 1) 'societe' => array(_('report:: societe'), 1, 1, 1, 1)
), $conf_pref); ), $conf_pref);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
if ($request->request->get('printcsv') == 'on') { if ($request->request->get('printcsv') == 'on') {
$download->setHasLimit(false); $download->setHasLimit(false);
$download->setPrettyString(false); $download->setPrettyString(false);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$this->doReport($app, $request, $download, $conf); $this->doReport($app, $request, $download, $conf);
return $this->getCSVResponse($app, $download, 'download'); $r = $this->getCSVResponse($app, $download, 'download');
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, var_export($r, true)), FILE_APPEND);
return $r;
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$report = $this->doReport($app, $request, $download, $conf); $report = $this->doReport($app, $request, $download, $conf);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
if ($report instanceof Response) { if ($report instanceof Response) {
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
return $report; return $report;
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
return $app->json(array( return $app->json(array(
'rs' => $app['twig']->render('report/ajax_data_content.html.twig', array( 'rs' => $app['twig']->render('report/ajax_data_content.html.twig', array(
'result' => isset($report['report']) ? $report['report'] : $report, 'result' => isset($report['report']) ? $report['report'] : $report,
@@ -380,7 +406,8 @@ class Root implements ControllerProviderInterface
$conf_pref = array(); $conf_pref = array();
foreach (\module_report::getPreff($app, $request->request->get('sbasid')) as $field) { foreach (\module_report::getPreff($app, $request->request->get('sbasid')) as $field) {
$conf_pref[strtolower($field)] = array($field, 0, 0, 0, 0); // $conf_pref[strtolower($field)] = array($field, 0, 0, 0, 0);
$conf_pref[$field] = array($field, 0, 0, 0, 0);
} }
$conf = array_merge(array( $conf = array_merge(array(
@@ -398,7 +425,11 @@ class Root implements ControllerProviderInterface
$this->doReport($app, $request, $document, $conf, 'record_id'); $this->doReport($app, $request, $document, $conf, 'record_id');
return $this->getCSVResponse($app, $document, 'documents'); $r = $this->getCSVResponse($app, $document, 'documents');
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, var_export($r, true)), FILE_APPEND);
return $r;
} }
$report = $this->doReport($app, $request, $document, $conf, 'record_id'); $report = $this->doReport($app, $request, $document, $conf, 'record_id');
@@ -506,6 +537,7 @@ class Root implements ControllerProviderInterface
$response = new CSVFileResponse($filename, function () use ($app, $result) { $response = new CSVFileResponse($filename, function () use ($app, $result) {
$app['csv.exporter']->export('php://output', $result); $app['csv.exporter']->export('php://output', $result);
}); });
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
return $response; return $response;
} }
@@ -545,6 +577,7 @@ class Root implements ControllerProviderInterface
unset($conf['ip']); unset($conf['ip']);
} }
} }
//save initial conf //save initial conf
$base_conf = $conf; $base_conf = $conf;
//format conf according user preferences //format conf according user preferences
@@ -609,13 +642,20 @@ class Root implements ControllerProviderInterface
$filter->addFilter('record_id', '=', $request->request->get('word', '')); $filter->addFilter('record_id', '=', $request->request->get('word', ''));
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
//set filters to current report //set filters to current report
$report->setFilter($filter->getTabFilter()); $report->setFilter($filter->getTabFilter());
$report->setActiveColumn($filter->getActiveColumn()); $report->setActiveColumn($filter->getActiveColumn());
$report->setPostingFilter($filter->getPostingFilter()); $report->setPostingFilter($filter->getPostingFilter());
// display a new arraywhere results are group // display a new arraywhere results are group
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
if ('' !== $groupby = $request->request->get('groupby', '')) { if ('' !== $groupby = $request->request->get('groupby', '')) {
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$report->setConfig(false); $report->setConfig(false);
$groupby = current(explode(' ', $groupby)); $groupby = current(explode(' ', $groupby));
@@ -627,6 +667,8 @@ class Root implements ControllerProviderInterface
$groupField = isset($conf[strtolower($groupby)]['title']) ? $conf[strtolower($groupby)]['title'] : ''; $groupField = isset($conf[strtolower($groupby)]['title']) ? $conf[strtolower($groupby)]['title'] : '';
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
return $app->json(array( return $app->json(array(
'rs' => $app['twig']->render('report/ajax_data_content.html.twig', array( 'rs' => $app['twig']->render('report/ajax_data_content.html.twig', array(
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray, 'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
@@ -641,6 +683,8 @@ class Root implements ControllerProviderInterface
)); ));
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
//set Limit //set Limit
if ($report->getEnableLimit() if ($report->getEnableLimit()
&& ('' !== $page = $request->request->get('page', '')) && ('' !== $page = $request->request->get('page', ''))
@@ -650,6 +694,8 @@ class Root implements ControllerProviderInterface
$report->setLimit(false, false); $report->setLimit(false, false);
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
//time to build our report //time to build our report
if (false === $what) { if (false === $what) {
$reportArray = $report->buildReport($conf); $reportArray = $report->buildReport($conf);
@@ -657,6 +703,8 @@ class Root implements ControllerProviderInterface
$reportArray = $report->buildReport($conf, $what, $request->request->get('tbl', false)); $reportArray = $report->buildReport($conf, $what, $request->request->get('tbl', false));
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
return $reportArray; return $reportArray;
} }
@@ -678,19 +726,33 @@ class Root implements ControllerProviderInterface
foreach (array_keys($report->getDisplay()) as $k) { foreach (array_keys($report->getDisplay()) as $k) {
$headers[$k] = $k; $headers[$k] = $k;
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s \n\n", __FILE__, __LINE__, var_export($headers, true)), FILE_APPEND);
// set headers as first row // set headers as first row
$result = $report->getResult(); $result = $report->getResult();
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s \n\n", __FILE__, __LINE__, var_export($result[0], true)), FILE_APPEND);
array_unshift($result, $headers); array_unshift($result, $headers);
$collection = new CallbackCollection($result, function ($row) use ($report) { $collection = new CallbackCollection($result, function ($row) use ($headers) {
// restrict fields to the displayed ones // restrict fields to the displayed ones
return array_map('strip_tags', array_intersect_key($row, $report->getDisplay())); // return array_map("strip_tags", array_intersect_key($row, $report->getDisplay()));
$ret = array();
foreach($headers as $f) {
$ret[$f] = array_key_exists($f, $row) ? strip_tags($row[$f]) : '';
}
return $ret;
}); });
$filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd')); $filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
$response = new CSVFileResponse($filename, function () use ($app, $collection) {
$cb = function () use ($app, $collection) {
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, var_export($collection, true)), FILE_APPEND);
$app['csv.exporter']->export('php://output', $collection); $app['csv.exporter']->export('php://output', $collection);
}); };
$response = new CSVFileResponse($filename, $cb);
return $response; return $response;
} }

View File

@@ -578,6 +578,7 @@ class module_report
return new module_report_sqlconnexion($this->app, $this); return new module_report_sqlconnexion($this->app, $this);
break; break;
case 'download' : case 'download' :
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
return new module_report_sqldownload($this->app, $this); return new module_report_sqldownload($this->app, $this);
break; break;
case 'question' : case 'question' :
@@ -777,7 +778,6 @@ class module_report
*/ */
protected function setConfigColumn($tab) protected function setConfigColumn($tab)
{ {
foreach ($tab as $column => $row) { foreach ($tab as $column => $row) {
foreach ($row as $ind => $value) { foreach ($row as $ind => $value) {
$title_text = ""; $title_text = "";
@@ -816,39 +816,59 @@ class module_report
*/ */
public function buildReport($tab = false, $groupby = false, $on = false) public function buildReport($tab = false, $groupby = false, $on = false)
{ {
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
if (sizeof($this->report) > 0) { if (sizeof($this->report) > 0) {
return $this->report; return $this->report;
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$conn = connection::getPDOConnection($this->app, $this->sbas_id); $conn = connection::getPDOConnection($this->app, $this->sbas_id);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$this->buildReq($groupby, $on); $this->buildReq($groupby, $on);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\nreq=%s\n\n", __FILE__, __LINE__, $this->req), FILE_APPEND);
try { try {
try { try {
$stmt = $conn->prepare($this->req); $stmt = $conn->prepare($this->req);
$stmt->execute($this->params); $stmt->execute($this->params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\ncount==%s\n\n", __FILE__, __LINE__, count($rs)), FILE_APPEND);
} catch (PDOException $e) { } catch (PDOException $e) {
echo $e->getMessage(); echo $e->getMessage();
return; return;
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, get_class($this)), FILE_APPEND);
//set request field //set request field
$this->setChamp($rs); $this->setChamp($rs);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
//set display //set display
$this->setDisplay($tab, $groupby); $this->setDisplay($tab, $groupby);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
//construct results //construct results
$this->buildResult($this->app, $rs); $this->buildResult($this->app, $rs);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
//calculate prev and next page //calculate prev and next page
$this->calculatePages($rs); $this->calculatePages($rs);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
//do we display navigator ? //do we display navigator ?
$this->setDisplayNav(); $this->setDisplayNav();
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
//assign all variables //assign all variables
$this->setReport(); $this->setReport();
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
return $this->report; return $this->report;
} catch (\Exception $e) { } catch (\Exception $e) {
echo $e->getMessage(); echo $e->getMessage();

View File

@@ -43,7 +43,8 @@ class module_report_activity extends module_report
public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist) public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
{ {
parent::__construct($app, $arg1, $arg2, $sbas_id, $collist); // parent::__construct($app, $arg1, $arg2, $sbas_id, $collist);
parent::__construct($app, $arg1, $arg2, $sbas_id, "");
} }
/** /**
@@ -84,6 +85,7 @@ class module_report_activity extends module_report
return $hours; return $hours;
} }
// ==================== Site activity : Site activity =====================
/** /**
* @desc get the site activity per hours * @desc get the site activity per hours
* @return array * @return array
@@ -99,15 +101,12 @@ class module_report_activity extends module_report
$params = array_merge(array(), $filter['params']); $params = array_merge(array(), $filter['params']);
$sql = " $sql = "
SELECT tt.heures, SUM(1) AS nb SELECT CAST(DATE_FORMAT(log.date, '%k') AS UNSIGNED) AS heures, COUNT(id) AS nb
FROM (
SELECT DISTINCT(log.id), DATE_FORMAT( log.date, '%k' ) AS heures
FROM log FORCE INDEX (date_site) FROM log FORCE INDEX (date_site)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE (" . $filter['sql'] . ") AND !ISNULL(usrid)
WHERE (" . $filter['sql'] . ") GROUP BY heures;";
) AS tt
GROUP BY tt.heures // no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
ORDER BY tt.heures ASC";
$stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt = $sqlBuilder->getConnBas()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -142,12 +141,14 @@ class module_report_activity extends module_report
return $this->report; return $this->report;
} }
// ===================== not called ? ====================
/** /**
* Get all questions by user * Get all questions by user
* *
* @param string $value * @param string $value
* @param string $what * @param string $what
*/ */
/*
public function getAllQuestionByUser($value, $what) public function getAllQuestionByUser($value, $what)
{ {
$result = array(); $result = array();
@@ -195,7 +196,9 @@ class module_report_activity extends module_report
return $this->result; return $this->result;
} }
*/
// ================== Site activity : Top questions (le second radio ...) ================
/** /**
* get the most asked question * get the most asked question
* @param array $tab config for html table * @param array $tab config for html table
@@ -213,19 +216,18 @@ class module_report_activity extends module_report
($no_answer) ? $this->title = _('report:: questions sans reponses') : $this->title = _('report:: questions les plus posees'); ($no_answer) ? $this->title = _('report:: questions sans reponses') : $this->title = _('report:: questions les plus posees');
$sql = " $sql = "
SELECT TRIM(tt.search) AS search, SUM(1) AS nb, ROUND(avg(tt.results)) AS nb_rep SELECT TRIM(log_search.search) AS search, COUNT(log_search.id) AS nb, ROUND(avg(results)) AS nb_rep
FROM (
SELECT DISTINCT(log.id), log_search.search AS search, results
FROM (log_search) FROM (log_search)
INNER JOIN log FORCE INDEX (date_site) ON (log_search.log_id = log.id) INNER JOIN log FORCE INDEX (date_site) ON (log_search.log_id = log.id)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE (" . $filter['sql'] . ") AND !ISNULL(usrid)
WHERE (" . $filter['sql'] . ")
AND log_search.search != 'all' " . AND log_search.search != 'all' " .
($no_answer ? ' AND log_search.results = 0 ' : '') . " ($no_answer ? ' AND log_search.results = 0 ' : '') . "
) AS tt
GROUP BY tt.search GROUP BY search
ORDER BY nb DESC"; ORDER BY nb DESC";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$sql .= !$no_answer ? ' LIMIT ' . $this->nb_top : ''; $sql .= !$no_answer ? ' LIMIT ' . $this->nb_top : '';
$stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt = $sqlBuilder->getConnBas()->prepare($sql);
@@ -260,12 +262,14 @@ class module_report_activity extends module_report
return $this->report; return $this->report;
} }
// =========================== not called ? =====================
/** /**
* @desc get all downloads from one specific user * @desc get all downloads from one specific user
* @param $usr user id * @param $usr user id
* @param array $config config for the html table * @param array $config config for the html table
* @return array * @return array
*/ */
/*
public function getAllDownloadByUserBase($usr, $config = false) public function getAllDownloadByUserBase($usr, $config = false)
{ {
$result = array(); $result = array();
@@ -319,7 +323,9 @@ class module_report_activity extends module_report
return $this->result; return $this->result;
} }
*/
// ============================ Downloads : Daily ==========================
/** /**
* @desc get all download by base by day * @desc get all download by base by day
* @param array $tab config for html table * @param array $tab config for html table
@@ -338,18 +344,19 @@ class module_report_activity extends module_report
FROM ( FROM (
SELECT DISTINCT(log.id), log_docs.date AS the_date, log_docs.final, log_docs.record_id SELECT DISTINCT(log.id), log_docs.date AS the_date, log_docs.final, log_docs.record_id
FROM (log_docs) FROM (log_docs)
INNER JOIN record ON (record.record_id = log_docs.record_id)
INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_docs.log_id) INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_docs.log_id)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE (" . $filter['sql'] . ") AND !ISNULL(usrid)
WHERE (" . $filter['sql'] . ")
AND (log_docs.action = 'download' OR log_docs.action = 'mail') AND (log_docs.action = 'download' OR log_docs.action = 'mail')
AND (log_docs.final = 'preview' OR log_docs.final = 'document') AND (log_docs.final = 'preview' OR log_docs.final = 'document')
) AS tt ) AS tt
INNER JOIN record ON (record.record_id = tt.record_id)
LEFT JOIN subdef AS s ON (s.record_id = tt.record_id) LEFT JOIN subdef AS s ON (s.record_id = tt.record_id)
WHERE s.name = tt.final WHERE s.name = tt.final
GROUP BY tt.final, ddate GROUP BY tt.final, ddate
ORDER BY tt.the_date DESC"; ORDER BY tt.the_date DESC";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt = $sqlBuilder->getConnBas()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -398,6 +405,16 @@ class module_report_activity extends module_report
$this->result[$nb_row]['preview'] = '<b>' . $total['tot_prev'] . '</b>'; $this->result[$nb_row]['preview'] = '<b>' . $total['tot_prev'] . '</b>';
$this->result[$nb_row]['total'] = '<b>' . $total['tot_dl'] . '</b>'; $this->result[$nb_row]['total'] = '<b>' . $total['tot_dl'] . '</b>';
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, var_export($this->result, true)), FILE_APPEND);
foreach($this->result as $k=>$row) {
$_row = array();
foreach($tab as $k2=>$f) {
$_row[$k2] = array_key_exists($k2, $row) ? $row[$k2] : '';
}
$this->result[$k] = $_row;
}
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, var_export($this->result, true)), FILE_APPEND);
$this->calculatePages($rs); $this->calculatePages($rs);
$this->setDisplayNav(); $this->setDisplayNav();
$this->setReport(); $this->setReport();
@@ -405,6 +422,7 @@ class module_report_activity extends module_report
return $this->report; return $this->report;
} }
// ==================== Connections: Per users =====================
/** /**
* @desc get nb connexion by user , fonction ,societe etc.. * @desc get nb connexion by user , fonction ,societe etc..
* @param array $tab config for html table * @param array $tab config for html table
@@ -423,25 +441,21 @@ class module_report_activity extends module_report
$params = array_merge(array(), $filter['params']); $params = array_merge(array(), $filter['params']);
$this->req = " $this->req = "
SELECT SUM(1) AS connexion, tt.user, tt.usrid FROM ( SELECT COUNT(id) AS connexion, log.user, log.usrid
SELECT
DISTINCT(log.id),
log." . $on . " AS " . $on . ",
log.usrid
FROM log FORCE INDEX (date_site) FROM log FORCE INDEX (date_site)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id)
WHERE log.user != 'API' WHERE log.user != 'API'
AND (" . $filter['sql'] . ") AND (" . $filter['sql'] . ") AND !ISNULL(usrid)
) AS tt GROUP BY usrid
GROUP BY tt.usrid
ORDER BY connexion DESC "; ORDER BY connexion DESC ";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->req), FILE_APPEND);
$stmt = $sqlBuilder->getConnBas()->prepare($this->req); $stmt = $sqlBuilder->getConnBas()->prepare($this->req);
$stmt->execute($params); $stmt->execute($params);
$sqlBuilder->setTotalrows($stmt->rowCount()); $sqlBuilder->setTotalrows($stmt->rowCount());
$stmt->closeCursor(); $stmt->closeCursor();
$this->enable_limit ? $this->req .= "LIMIT 0," . $this->nb_record : ""; $this->enable_limit ? $this->req .= " LIMIT 0," . $this->nb_record : "";
$stmt = $sqlBuilder->getConnBas()->prepare($this->req); $stmt = $sqlBuilder->getConnBas()->prepare($this->req);
$stmt->execute($params); $stmt->execute($params);
@@ -491,8 +505,9 @@ class module_report_activity extends module_report
return $this->report; return $this->report;
} }
// ========================= Downloads : Per users =====================
/** /**
* Get the deail of download by users * Get the detail of download by users
* *
* @param array $tab config for the html table * @param array $tab config for the html table
* @param String $on * @param String $on
@@ -516,16 +531,17 @@ class module_report_activity extends module_report
SELECT DISTINCT(log.id), TRIM(" . $on . ") AS " . $on . ", log_docs.record_id, log_docs.final, log.usrid SELECT DISTINCT(log.id), TRIM(" . $on . ") AS " . $on . ", log_docs.record_id, log_docs.final, log.usrid
FROM log_docs FROM log_docs
INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_docs.log_id) INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_docs.log_id)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE (" . $filter['sql'] . ") AND !ISNULL(usrid)
INNER JOIN record ON (record.record_id = log_docs.record_id)
WHERE (" . $filter['sql'] . ")
AND (log_docs.action = 'download' OR log_docs.action = 'mail') AND (log_docs.action = 'download' OR log_docs.action = 'mail')
) AS tt ) AS tt
INNER JOIN record ON (record.record_id = tt.record_id)
LEFT JOIN subdef FORCE INDEX (unicite) ON (tt.record_id = subdef.record_id) LEFT JOIN subdef FORCE INDEX (unicite) ON (tt.record_id = subdef.record_id)
WHERE subdef.name = tt.final WHERE subdef.name = tt.final
GROUP BY " . $on . ", usrid GROUP BY " . $on . ", usrid
ORDER BY nb DESC;"; ORDER BY nb DESC;";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt = $sqlBuilder->getConnBas()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -608,6 +624,18 @@ class module_report_activity extends module_report
$this->result[$nb_row]['poidprev'] = $this->result[$nb_row]['poidprev'] =
'<b>' . p4string::format_octets($total['poidprev']) . '</b>'; '<b>' . p4string::format_octets($total['poidprev']) . '</b>';
} }
foreach($this->result as $k=>$row) {
$_row = array();
foreach($tab as $k2=>$f) {
$_row[$k2] = array_key_exists($k2, $row) ? $row[$k2] : '';
}
$_row['usrid'] = array_key_exists('usrid', $row) ? $row['usrid'] : '';
$this->result[$k] = $_row;
}
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, var_export($this->result, true)), FILE_APPEND);
$this->total = sizeof($this->result); $this->total = sizeof($this->result);
$this->calculatePages($rs); $this->calculatePages($rs);
$this->setDisplayNav(); $this->setDisplayNav();
@@ -616,6 +644,7 @@ class module_report_activity extends module_report
return $this->report; return $this->report;
} }
// ========================== ???????????????? ===========================
public static function topTenUser(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function topTenUser(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $conn = connection::getPDOConnection($app, $sbas_id);
@@ -632,7 +661,7 @@ class module_report_activity extends module_report
$collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id); $collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id);
$params = array_merge($params, $collfilter['params']); $params = array_merge($params, $collfilter['params']);
/*
$sql = "SELECT tt.usrid, tt.user, tt.final, tt.record_id, SUM(1) AS nb, SUM(size) AS poid $sql = "SELECT tt.usrid, tt.user, tt.final, tt.record_id, SUM(1) AS nb, SUM(size) AS poid
FROM ( FROM (
SELECT DISTINCT(log.id), log.usrid, user, final, log_date.record_id SELECT DISTINCT(log.id), log.usrid, user, final, log_date.record_id
@@ -648,6 +677,22 @@ class module_report_activity extends module_report
LEFT JOIN subdef AS s ON (s.record_id = tt.record_id) LEFT JOIN subdef AS s ON (s.record_id = tt.record_id)
WHERE s.name = tt.final WHERE s.name = tt.final
GROUP BY tt.user, tt.final"; GROUP BY tt.user, tt.final";
*/
$sql = "SELECT tt.usrid, tt.user, tt.final, tt.record_id, SUM(1) AS nb, SUM(size) AS poid\n"
. " FROM (\n"
. " SELECT DISTINCT(log.id), log.usrid, user, final, log_date.record_id\n"
. " FROM (log_docs AS log_date)\n"
. " INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_date.log_id)\n"
. " WHERE log.site = :site_id\n"
. " AND log_date.action = 'download'\n"
. " AND (" . $datefilter['sql'] . ")\n"
. (('' !== $collfilter['sql']) ? " AND (" . $collfilter['sql'] . ")" : '') . "\n"
. ") AS tt\n"
. "LEFT JOIN subdef AS s ON (s.record_id = tt.record_id)\n"
. "WHERE s.name = tt.final\n"
. "GROUP BY tt.user, tt.final";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -699,6 +744,7 @@ class module_report_activity extends module_report
return $result; return $result;
} }
//============================= Dashboard =========================
public static function activity(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activity(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $conn = connection::getPDOConnection($app, $sbas_id);
@@ -710,7 +756,7 @@ class module_report_activity extends module_report
$params = array(':site_id' => $app['phraseanet.configuration']['main']['key']); $params = array(':site_id' => $app['phraseanet.configuration']['main']['key']);
$params = array_merge($params, $datefilter['params'], $collfilter['params']); $params = array_merge($params, $datefilter['params'], $collfilter['params']);
/*
$sql = " $sql = "
SELECT tt.id, HOUR(tt.heures) AS heures SELECT tt.id, HOUR(tt.heures) AS heures
FROM ( FROM (
@@ -721,6 +767,17 @@ class module_report_activity extends module_report
(('' !== $collfilter['sql']) ? "AND (" . $collfilter['sql'] . ")" : '') (('' !== $collfilter['sql']) ? "AND (" . $collfilter['sql'] . ")" : '')
. " AND log_date.site = :site_id . " AND log_date.site = :site_id
) AS tt"; ) AS tt";
*/
$sql = "SELECT tt.id, HOUR(tt.heures) AS heures\n"
. " FROM (\n"
. " SELECT DISTINCT(log_date.id), log_date.date AS heures\n"
. " FROM log AS log_date FORCE INDEX (date_site)\n"
. " WHERE " . $datefilter['sql'] . " AND !ISNULL(usrid)"
. (('' !== $collfilter['sql']) ? " AND (" . $collfilter['sql'] . ")" : '') . "\n"
. " AND log_date.site = :site_id\n"
. " ) AS tt";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -745,6 +802,7 @@ class module_report_activity extends module_report
return $res; return $res;
} }
//============================= Dashboard =========================
public static function activityDay(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activityDay(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $conn = connection::getPDOConnection($app, $sbas_id);
@@ -755,7 +813,7 @@ class module_report_activity extends module_report
$params = array(':site_id' => $app['phraseanet.configuration']['main']['key']); $params = array(':site_id' => $app['phraseanet.configuration']['main']['key']);
$params = array_merge($params, $datefilter['params'], $collfilter['params']); $params = array_merge($params, $datefilter['params'], $collfilter['params']);
/*
$sql = " $sql = "
SELECT tt.ddate, COUNT( DATE_FORMAT( tt.ddate, '%d' ) ) AS activity SELECT tt.ddate, COUNT( DATE_FORMAT( tt.ddate, '%d' ) ) AS activity
FROM ( FROM (
@@ -767,6 +825,19 @@ class module_report_activity extends module_report
. ") AS tt . ") AS tt
GROUP by tt.ddate GROUP by tt.ddate
ORDER BY tt.ddate ASC"; ORDER BY tt.ddate ASC";
*/
$sql = "SELECT tt.ddate, COUNT( DATE_FORMAT( tt.ddate, '%d' ) ) AS activity\n"
. " FROM (\n"
. " SELECT DISTINCT(log_date.id), DATE_FORMAT( log_date.date, '%Y-%m-%d' ) AS ddate\n"
. " FROM log AS log_date FORCE INDEX (date_site)\n"
. " WHERE " . $datefilter['sql'] . "\n"
. " AND log_date.site = :site_id AND !ISNULL(usrid)" .
(('' !== $collfilter['sql']) ? (" AND (" . $collfilter['sql'] . ")") : '') . "\n"
. ") AS tt\n"
. " GROUP by tt.ddate\n"
. " ORDER BY tt.ddate ASC";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -785,6 +856,7 @@ class module_report_activity extends module_report
return $res; return $res;
} }
//============================= Dashboard =========================
public static function activityQuestion(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activityQuestion(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $conn = connection::getPDOConnection($app, $sbas_id);
@@ -796,7 +868,7 @@ class module_report_activity extends module_report
$params = array(':site_id' => $app['phraseanet.configuration']['main']['key']); $params = array(':site_id' => $app['phraseanet.configuration']['main']['key']);
$params = array_merge($params, $datefilter['params'], $collfilter['params']); $params = array_merge($params, $datefilter['params'], $collfilter['params']);
/*
$sql = " $sql = "
SELECT tt.usrid, tt.user, sum(1) AS nb SELECT tt.usrid, tt.user, sum(1) AS nb
FROM ( FROM (
@@ -810,6 +882,20 @@ class module_report_activity extends module_report
. ") AS tt . ") AS tt
GROUP BY tt.usrid GROUP BY tt.usrid
ORDER BY nb DESC"; ORDER BY nb DESC";
*/
$sql = "SELECT tt.usrid, tt.user, sum(1) AS nb\n"
. " FROM (\n"
. " SELECT DISTINCT(log_date.id), log_date.usrid, log_date.user\n"
. " FROM (`log_search`)\n"
. " INNER JOIN log AS log_date FORCE INDEX (date_site) ON (log_search.log_id = log_date.id)\n"
. " WHERE " . $datefilter['sql'] . "\n"
. " AND log_date.site = :site_id" .
(('' !== $collfilter['sql']) ? " AND (" . $collfilter['sql'] . ")" : '') . "\n"
. ") AS tt\n"
. " GROUP BY tt.usrid\n"
. " ORDER BY nb DESC";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -825,6 +911,7 @@ class module_report_activity extends module_report
return $result; return $result;
} }
//============================= Dashboard =========================
public static function activiteTopQuestion(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteTopQuestion(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $conn = connection::getPDOConnection($app, $sbas_id);
@@ -836,7 +923,7 @@ class module_report_activity extends module_report
$params = array(':site_id' => $app['phraseanet.configuration']['main']['key']); $params = array(':site_id' => $app['phraseanet.configuration']['main']['key']);
$params = array_merge($params, $datefilter['params'], $collfilter['params']); $params = array_merge($params, $datefilter['params'], $collfilter['params']);
/*
$sql = " $sql = "
SELECT TRIM(tt.search) AS question, tt.usrid, tt.user, SUM(1) AS nb SELECT TRIM(tt.search) AS question, tt.usrid, tt.user, SUM(1) AS nb
FROM ( FROM (
@@ -850,6 +937,20 @@ class module_report_activity extends module_report
. ") AS tt . ") AS tt
GROUP BY tt.search GROUP BY tt.search
ORDER BY nb DESC"; ORDER BY nb DESC";
*/
$sql = "SELECT TRIM(tt.search) AS question, tt.usrid, tt.user, SUM(1) AS nb\n"
. " FROM (\n"
. " SELECT DISTINCT(log_date.id), log_search.search, log_date.usrid, log_date.user\n"
. " FROM (`log_search`)\n"
. " INNER JOIN log AS log_date FORCE INDEX (date_site) ON (log_search.log_id = log_date.id)\n"
. " WHERE " . $datefilter['sql'] . "\n"
. " AND log_date.site = :site_id" .
(('' !== $collfilter['sql']) ? " AND (" . $collfilter['sql'] . ")" : '') . "\n"
. ") AS tt\n"
. " GROUP BY tt.search\n"
. " ORDER BY nb DESC";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -868,6 +969,7 @@ class module_report_activity extends module_report
return $result; return $result;
} }
//============================= Dashboard =========================
public static function activiteTopTenSiteView(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteTopTenSiteView(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $conn = connection::getPDOConnection($app, $sbas_id);
@@ -877,7 +979,7 @@ class module_report_activity extends module_report
$params = array(); $params = array();
$params = array_merge($params, $datefilter['params'], $collfilter['params']); $params = array_merge($params, $datefilter['params'], $collfilter['params']);
/*
$sql = " $sql = "
SELECT tt.referrer, SUM(1) AS nb_view SELECT tt.referrer, SUM(1) AS nb_view
FROM ( FROM (
@@ -890,6 +992,19 @@ class module_report_activity extends module_report
. ") AS tt . ") AS tt
GROUP BY referrer GROUP BY referrer
ORDER BY nb_view DESC "; ORDER BY nb_view DESC ";
*/
$sql = "SELECT tt.referrer, SUM(1) AS nb_view\n"
. " FROM (\n"
. " SELECT DISTINCT(log_date.id), referrer\n"
. " FROM (log_view)\n"
. " INNER JOIN log AS log_date FORCE INDEX (date_site) ON (log_view.log_id = log_date.id)\n"
. " WHERE " . $datefilter['sql']
. (('' !== $collfilter['sql']) ? " AND (" . $collfilter['sql'] . ")" : '') . "\n"
. ") AS tt\n"
. " GROUP BY referrer\n"
. " ORDER BY nb_view DESC ";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -911,6 +1026,7 @@ class module_report_activity extends module_report
return $result; return $result;
} }
//============================= Dashboard =========================
public static function activiteAddedDocument(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteAddedDocument(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $conn = connection::getPDOConnection($app, $sbas_id);
@@ -920,7 +1036,7 @@ class module_report_activity extends module_report
$params = array(); $params = array();
$params = array_merge($params, $datefilter['params'], $collfilter['params']); $params = array_merge($params, $datefilter['params'], $collfilter['params']);
/*
$sql = " $sql = "
SELECT tt.ddate, COUNT( DATE_FORMAT( tt.ddate, '%d' ) ) AS activity SELECT tt.ddate, COUNT( DATE_FORMAT( tt.ddate, '%d' ) ) AS activity
FROM ( FROM (
@@ -934,6 +1050,19 @@ class module_report_activity extends module_report
) AS tt ) AS tt
GROUP BY tt.ddate GROUP BY tt.ddate
ORDER BY activity ASC "; ORDER BY activity ASC ";
*/
$sql = "SELECT tt.ddate, COUNT( DATE_FORMAT( tt.ddate, '%d' ) ) AS activity\n"
. " FROM (\n"
. " SELECT DISTINCT(log.id), DATE_FORMAT(log_date.date, '%Y-%m-%d') AS ddate\n"
. " FROM (log_docs AS log_date)\n"
. " INNER JOIN log FORCE INDEX (date_site) ON (log_date.log_id = log.id)\n"
. " WHERE " . $datefilter['sql'] . " AND log_date.action = 'add'"
. (('' !== $collfilter['sql']) ? " AND (" . $collfilter['sql'] . ")" : '') . "\n"
. " ) AS tt\n"
. " GROUP BY tt.ddate\n"
. " ORDER BY activity ASC ";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -947,6 +1076,7 @@ class module_report_activity extends module_report
return $result; return $result;
} }
//============================= Dashboard =========================
public static function activiteEditedDocument(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteEditedDocument(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $conn = connection::getPDOConnection($app, $sbas_id);
@@ -956,7 +1086,7 @@ class module_report_activity extends module_report
$params = array(); $params = array();
$params = array_merge($params, $datefilter['params'], $collfilter['params']); $params = array_merge($params, $datefilter['params'], $collfilter['params']);
/*
$sql = " $sql = "
SELECT tt.ddate, COUNT( DATE_FORMAT( tt.ddate, '%d' ) ) AS activity SELECT tt.ddate, COUNT( DATE_FORMAT( tt.ddate, '%d' ) ) AS activity
FROM ( FROM (
@@ -969,6 +1099,19 @@ class module_report_activity extends module_report
. ") AS tt . ") AS tt
GROUP BY tt.ddate GROUP BY tt.ddate
ORDER BY activity ASC "; ORDER BY activity ASC ";
*/
$sql = "SELECT tt.ddate, COUNT( DATE_FORMAT( tt.ddate, '%d' ) ) AS activity\n"
. " FROM (\n"
. " SELECT DISTINCT(log.id), DATE_FORMAT( log_date.date, '%Y-%m-%d') AS ddate\n"
. " FROM (log_docs AS log_date)\n"
. " INNER JOIN log FORCE INDEX (date_site) ON (log_date.log_id = log.id)\n"
. " WHERE " . $datefilter['sql'] . " AND log_date.action = 'edit'"
. (('' !== $collfilter['sql']) ? " AND (" . $collfilter['sql'] . ")" : '') . "\n"
. ") AS tt\n"
. " GROUP BY tt.ddate\n"
. " ORDER BY activity ASC ";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -983,6 +1126,7 @@ class module_report_activity extends module_report
return $result; return $result;
} }
//============================= Dashboard =========================
public static function activiteAddedTopTenUser(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteAddedTopTenUser(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $conn = connection::getPDOConnection($app, $sbas_id);
@@ -992,7 +1136,7 @@ class module_report_activity extends module_report
$params = array(); $params = array();
$params = array_merge($params, $datefilter['params'], $collfilter['params']); $params = array_merge($params, $datefilter['params'], $collfilter['params']);
/*
$sql = " $sql = "
SELECT tt.usrid, tt.user, sum( 1 ) AS nb SELECT tt.usrid, tt.user, sum( 1 ) AS nb
FROM ( FROM (
@@ -1005,6 +1149,20 @@ class module_report_activity extends module_report
. ") AS tt . ") AS tt
GROUP BY tt.usrid GROUP BY tt.usrid
ORDER BY nb ASC "; ORDER BY nb ASC ";
*/
$sql = ""
. " SELECT tt.usrid, tt.user, sum( 1 ) AS nb\n"
. " FROM (\n"
. " SELECT DISTINCT(log.id), log.usrid, log.user\n"
. " FROM (log_docs AS log_date)\n"
. " INNER JOIN log FORCE INDEX (date_site) ON (log_date.log_id = log.id)\n"
. " WHERE " . $datefilter['sql'] . " AND log_date.action = 'add'"
. (('' !== $collfilter['sql']) ? " AND (" . $collfilter['sql'] . ")" : '') . "\n"
. ") AS tt\n"
. " GROUP BY tt.usrid\n"
. " ORDER BY nb ASC ";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);

View File

@@ -38,7 +38,8 @@ class module_report_connexion extends module_report
*/ */
public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist) public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
{ {
parent::__construct($app, $arg1, $arg2, $sbas_id, $collist); // parent::__construct($app, $arg1, $arg2, $sbas_id, $collist);
parent::__construct($app, $arg1, $arg2, $sbas_id, "");
$this->title = _('report::Connexions'); $this->title = _('report::Connexions');
} }
@@ -150,11 +151,18 @@ class module_report_connexion extends module_report
$finalfilter = $datefilter['sql'] . ' AND '; $finalfilter = $datefilter['sql'] . ' AND ';
$finalfilter .= $collfilter['sql'] . ' AND '; $finalfilter .= $collfilter['sql'] . ' AND ';
$finalfilter .= 'log_date.site = :site_id'; $finalfilter .= 'log_date.site = :site_id';
/*
$sql = "SELECT COUNT(DISTINCT(log_date.id)) as nb $sql = "SELECT COUNT(DISTINCT(log_date.id)) as nb
FROM log as log_date FORCE INDEX (date_site) FROM log as log_date FORCE INDEX (date_site)
INNER JOIN log_colls FORCE INDEX (couple) ON (log_date.id = log_colls.log_id) INNER JOIN log_colls FORCE INDEX (couple) ON (log_date.id = log_colls.log_id)
WHERE " . $finalfilter; WHERE " . $finalfilter;
*/
$sql = "SELECT COUNT(DISTINCT(log_date.id)) as nb\n"
. " FROM log as log_date FORCE INDEX (date_site)\n"
. " INNER JOIN log_colls FORCE INDEX (couple) ON (log_date.id = log_colls.log_id)\n"
. " WHERE " . $finalfilter . "\n";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);

View File

@@ -44,7 +44,8 @@ class module_report_download extends module_report
*/ */
public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist) public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
{ {
parent::__construct($app, $arg1, $arg2, $sbas_id, $collist); // parent::__construct($app, $arg1, $arg2, $sbas_id, $collist);
parent::__construct($app, $arg1, $arg2, $sbas_id, "");
$this->title = _('report:: telechargements'); $this->title = _('report:: telechargements');
} }
@@ -55,9 +56,12 @@ class module_report_download extends module_report
*/ */
protected function buildReq($groupby = false, $on = false) protected function buildReq($groupby = false, $on = false)
{ {
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
ini_set('display_errors', true);
$sql = $this->sqlBuilder('download') $sql = $this->sqlBuilder('download')
->setOn($on)->setGroupBy($groupby)->buildSql(); ->setOn($on)->setGroupBy($groupby)->buildSql();
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$this->req = $sql->getSql(); $this->req = $sql->getSql();
$this->params = $sql->getParams(); $this->params = $sql->getParams();
$this->total = $sql->getTotalRows(); $this->total = $sql->getTotalRows();
@@ -102,6 +106,7 @@ class module_report_download extends module_report
{ {
$i = 0; $i = 0;
$pref = parent::getPreff($app, $this->sbas_id); $pref = parent::getPreff($app, $this->sbas_id);
//// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, var_export($rs, true)), FILE_APPEND);
foreach ($rs as $row) { foreach ($rs as $row) {
if ($this->enable_limit && ($i > $this->nb_record)) if ($this->enable_limit && ($i > $this->nb_record))
@@ -112,23 +117,28 @@ class module_report_download extends module_report
} }
if (array_key_exists('record_id', $row)) { if (array_key_exists('record_id', $row)) {
//// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, $row['record_id']), FILE_APPEND);
try { try {
$record = new \record_adapter($app, $this->sbas_id, $row['record_id']); $record = new \record_adapter($app, $this->sbas_id, $row['record_id']);
} catch (\Exception_Record_AdapterNotFound $e) { $caption = $record->get_caption();
continue;
}
foreach ($pref as $field) { foreach ($pref as $field) {
//// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, $field), FILE_APPEND);
try { try {
$this->result[$i][$field] = $record->get_caption() $this->result[$i][$field] = $caption
->get_field($field) ->get_field($field)
->get_serialized_values(); ->get_serialized_values();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->result[$i][$field] = ''; $this->result[$i][$field] = '';
} }
} }
} catch (\Exception_Record_AdapterNotFound $e) {
foreach ($pref as $field) {
$this->result[$i][$field] = '';
}
}
} }
$i ++; $i ++;
//// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
} }
} }
@@ -176,13 +186,14 @@ class module_report_download extends module_report
$params = array(':site_id' => $app['phraseanet.configuration']['main']['key']); $params = array(':site_id' => $app['phraseanet.configuration']['main']['key']);
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax); $datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
$collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id); // $collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id);
$params = array_merge($params, $datefilter['params'], $collfilter['params']); // $params = array_merge($params, $datefilter['params'], $collfilter['params']);
$params = array_merge($params, $datefilter['params']);
$finalfilter = $datefilter['sql'] . ' AND '; $finalfilter = $datefilter['sql'] . ' AND ';
$finalfilter .= $collfilter['sql'] . ' AND '; // $finalfilter .= $collfilter['sql'] . ' AND ';
$finalfilter .= 'log.site = :site_id'; $finalfilter .= 'log.site = :site_id';
/*
$sql = ' $sql = '
SELECT SUM(1) AS nb SELECT SUM(1) AS nb
FROM ( FROM (
@@ -197,6 +208,18 @@ class module_report_download extends module_report
) )
) AS tt ) AS tt
'; ';
*/
$sql = "SELECT SUM(1) AS nb\n"
. " FROM (\n"
. " SELECT DISTINCT(log.id)\n"
. " FROM log FORCE INDEX (date_site)\n"
. " INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id)\n"
. " WHERE " . $finalfilter . "\n"
. " AND ( log_date.action = 'download' OR log_date.action = 'mail' )\n"
. " ) AS tt";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -224,7 +247,7 @@ class module_report_download extends module_report
$finalfilter .= $datefilter['sql'] . ' AND '; $finalfilter .= $datefilter['sql'] . ' AND ';
$finalfilter .= $collfilter['sql'] . ' AND '; $finalfilter .= $collfilter['sql'] . ' AND ';
$finalfilter .= 'log.site = :site_id'; $finalfilter .= 'log.site = :site_id';
/*
$sql = ' $sql = '
SELECT tt.id, tt.name, SUM(1) AS nb SELECT tt.id, tt.name, SUM(1) AS nb
FROM ( FROM (
@@ -243,6 +266,20 @@ class module_report_download extends module_report
) AS tt ) AS tt
GROUP BY id, name GROUP BY id, name
'; ';
*/
$sql = "SELECT tt.id, tt.name, SUM(1) AS nb\n"
. " FROM (\n"
. " SELECT DISTINCT(log.id) AS log_id, log_date.record_id as id, subdef.name\n"
. " FROM ( log )\n"
. " INNER JOIN log_docs as log_date ON (log.id = log_date.log_id)\n"
. " INNER JOIN subdef ON (log_date.record_id = subdef.record_id)\n"
. " WHERE (" . $finalfilter . ")\n"
. " AND ( log_date.action = 'download' OR log_date.action = 'mail' )\n"
. " AND subdef.name = log_date.final\n"
. " ) AS tt\n"
. " GROUP BY id, name\n";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);

View File

@@ -48,7 +48,8 @@ class module_report_nav extends module_report
*/ */
public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist) public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
{ {
parent::__construct($app, $arg1, $arg2, $sbas_id, $collist); // parent::__construct($app, $arg1, $arg2, $sbas_id, $collist);
parent::__construct($app, $arg1, $arg2, $sbas_id, "");
} }
private function setTotalPourcent() private function setTotalPourcent()
@@ -60,12 +61,11 @@ class module_report_nav extends module_report
$params = array_merge(array(), $report_filter['params']); $params = array_merge(array(), $report_filter['params']);
$sql = ' $sql = '
SELECT SUM(1) AS total FROM ( SELECT COUNT(log.id) AS total
SELECT DISTINCT (log.id)
FROM log FORCE INDEX (date_site) FROM log FORCE INDEX (date_site)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE ' . $report_filter['sql'] . ' AND nav != "" AND !ISNULL(usrid)';
WHERE ' . $report_filter['sql'] . ' AND nav != ""
) AS tt'; // no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt = $sqlBuilder->getConnBas()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -112,16 +112,14 @@ class module_report_nav extends module_report
$params = array_merge(array(), $report_filter['params']); $params = array_merge(array(), $report_filter['params']);
$sql = ' $sql = '
SELECT tt.nav, SUM(1) AS nb, ROUND((SUM(1) / ' . $this->total_pourcent . ' * 100), 1) AS pourcent SELECT nav, SUM(1) AS nb, ROUND((SUM(1) / ' . $this->total_pourcent . ' * 100), 1) AS pourcent
FROM (
SELECT DISTINCT(log.id), nav
FROM log FORCE INDEX (date_site, nav) FROM log FORCE INDEX (date_site, nav)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE ' . $report_filter['sql'] . ' AND nav != "" AND !ISNULL(usrid)
WHERE ' . $report_filter['sql'] . ' AND nav != "" GROUP BY nav
) AS tt
GROUP BY tt.nav
ORDER BY nb DESC'; ORDER BY nb DESC';
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$this->initialize(); $this->initialize();
$stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt = $sqlBuilder->getConnBas()->prepare($sql);
@@ -171,16 +169,16 @@ class module_report_nav extends module_report
$params = array_merge(array(), $report_filter['params']); $params = array_merge(array(), $report_filter['params']);
$sql = ' $sql = '
SELECT tt.os, COUNT(os) AS nb, ROUND((COUNT(os)/' . $this->total_pourcent . '*100),1) AS pourcent SELECT os, COUNT(os) AS nb, ROUND((COUNT(os)/' . $this->total_pourcent . '*100),1) AS pourcent
FROM (
SELECT DISTINCT(log.id), os
FROM log FORCE INDEX (date_site, os) FROM log FORCE INDEX (date_site, os)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE '. $report_filter['sql'] . ' AND os != "" AND !ISNULL(usrid)
WHERE '. $report_filter['sql'] . ' AND os != ""
) AS tt GROUP BY os
GROUP BY tt.os
ORDER BY nb DESC'; ORDER BY nb DESC';
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$this->initialize(); $this->initialize();
$stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt = $sqlBuilder->getConnBas()->prepare($sql);
@@ -229,17 +227,17 @@ class module_report_nav extends module_report
$params = array_merge(array(), $report_filter['params']); $params = array_merge(array(), $report_filter['params']);
$sql = ' $sql = '
SELECT tt.res, COUNT(res) AS nb, ROUND((COUNT(res)/ ' . $this->total_pourcent . '*100),1) AS pourcent SELECT res, COUNT(res) AS nb, ROUND((COUNT(res)/ ' . $this->total_pourcent . '*100),1) AS pourcent
FROM (
SELECT DISTINCT(log.id), res
FROM log FORCE INDEX (date_site, res) FROM log FORCE INDEX (date_site, res)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE '. $report_filter['sql'] . ' AND res != "" AND !ISNULL(usrid)
WHERE '. $report_filter['sql'] . ' AND res != ""
) AS tt GROUP BY res
GROUP BY tt.res
ORDER BY nb DESC ORDER BY nb DESC
LIMIT 0, 10'; LIMIT 0, 10';
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$this->initialize(); $this->initialize();
$stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt = $sqlBuilder->getConnBas()->prepare($sql);
@@ -291,15 +289,16 @@ class module_report_nav extends module_report
$sql = " $sql = "
SELECT tt.combo, COUNT( tt.combo ) AS nb, ROUND((COUNT(tt.combo)/" . $this->total_pourcent . "*100), 1) AS pourcent SELECT tt.combo, COUNT( tt.combo ) AS nb, ROUND((COUNT(tt.combo)/" . $this->total_pourcent . "*100), 1) AS pourcent
FROM ( FROM (
SELECT DISTINCT(log.id), CONCAT( nav, '-', os ) AS combo SELECT CONCAT( nav, '-', os ) AS combo
FROM log FORCE INDEX (date_site, os_nav) FROM log FORCE INDEX (date_site, os_nav)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE ". $report_filter['sql'] ." AND nav != '' AND os != '' AND !ISNULL(usrid)
WHERE ". $report_filter['sql'] ." AND nav != '' AND os != ''
) AS tt ) AS tt
GROUP BY tt.combo GROUP BY tt.combo
ORDER BY nb DESC ORDER BY nb DESC
LIMIT 0 , 10"; LIMIT 0 , 10";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$this->initialize(); $this->initialize();
$stmt = $sqlBuilder->getConnBas()->prepare($sql); $stmt = $sqlBuilder->getConnBas()->prepare($sql);
@@ -351,14 +350,12 @@ class module_report_nav extends module_report
$params = array_merge(array(), $report_filter['params']); $params = array_merge(array(), $report_filter['params']);
$sql = ' $sql = '
SELECT tt.appli SELECT appli
FROM (
SELECT DISTINCT(log.id), appli
FROM log FORCE INDEX (date_site, 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:{}\' AND !ISNULL(usrid)
WHERE ' . $report_filter['sql'] . ' AND appli != \'a:0:{}\' GROUP BY appli';
) AS tt
GROUP BY tt.appli'; // no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$this->initialize(); $this->initialize();
@@ -452,6 +449,8 @@ class module_report_nav extends module_report
WHERE (usr_id = :value)'; WHERE (usr_id = :value)';
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$params2 = array(':value' => $val); $params2 = array(':value' => $val);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params2); $stmt->execute($params2);
@@ -556,6 +555,8 @@ class module_report_nav extends module_report
GROUP BY version GROUP BY version
ORDER BY nb DESC"; ORDER BY nb DESC";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);

View File

@@ -39,7 +39,8 @@ class module_report_question extends module_report
*/ */
public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist) public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
{ {
parent::__construct($app, $arg1, $arg2, $sbas_id, $collist); // parent::__construct($app, $arg1, $arg2, $sbas_id, $collist);
parent::__construct($app, $arg1, $arg2, $sbas_id, "");
$this->title = _('report:: question'); $this->title = _('report:: question');
} }

View File

@@ -55,6 +55,8 @@ class module_report_sqlaction extends module_report_sql implements module_report
WHERE (" . $filter['sql'] . ") AND (d.action = :action) WHERE (" . $filter['sql'] . ") AND (d.action = :action)
) AS tt"; ) AS tt";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
$customFieldMap = array( $customFieldMap = array(
'log.usrid' => 'tt.usrid', 'log.usrid' => 'tt.usrid',
'log.user' => 'tt.user', 'log.user' => 'tt.user',
@@ -89,6 +91,8 @@ class module_report_sqlaction extends module_report_sql implements module_report
GROUP BY " . $this->groupby . " GROUP BY " . $this->groupby . "
ORDER BY nombre"; ORDER BY nombre";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
$stmt = $this->getConnBas()->prepare($this->sql); $stmt = $this->getConnBas()->prepare($this->sql);
$stmt->execute($this->params); $stmt->execute($this->params);
$this->total_row = $stmt->rowCount(); $this->total_row = $stmt->rowCount();
@@ -116,6 +120,8 @@ class module_report_sqlaction extends module_report_sql implements module_report
AND (d.action = :action) AND (d.action = :action)
) AS tt " . ($this->filter->getOrderFilter() ? $this->filter->getOrderFilter() : ''); ) AS tt " . ($this->filter->getOrderFilter() ? $this->filter->getOrderFilter() : '');
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
return array('sql' => $this->sql, 'params' => $this->params); return array('sql' => $this->sql, 'params' => $this->params);
} }
} }

View File

@@ -27,7 +27,7 @@ class module_report_sqlconnexion extends module_report_sql implements module_rep
if ($this->groupby == false) { if ($this->groupby == false) {
$this->sql = " $this->sql = "
SELECT SELECT
DISTINCT(log_colls.log_id), log.id,
log.user, log.user,
log.usrid, log.usrid,
log.date as ddate, log.date as ddate,
@@ -40,8 +40,9 @@ class module_report_sqlconnexion extends module_report_sql implements module_rep
log.appli, log.appli,
log.ip log.ip
FROM log FORCE INDEX (date_site) FROM log FORCE INDEX (date_site)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE (" . $filter['sql'] .") AND !ISNULL(log.usrid)";
WHERE (" . $filter['sql'] .")";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
$stmt = $this->connbas->prepare($this->sql); $stmt = $this->connbas->prepare($this->sql);
$stmt->execute($this->params); $stmt->execute($this->params);
@@ -65,6 +66,8 @@ class module_report_sqlconnexion extends module_report_sql implements module_rep
GROUP BY " . $this->groupby. " GROUP BY " . $this->groupby. "
ORDER BY nb DESC"; ORDER BY nb DESC";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
$stmt = $this->connbas->prepare($this->sql); $stmt = $this->connbas->prepare($this->sql);
$stmt->execute($this->params); $stmt->execute($this->params);
$this->total_row = $stmt->rowCount(); $this->total_row = $stmt->rowCount();
@@ -88,6 +91,8 @@ class module_report_sqlconnexion extends module_report_sql implements module_rep
WHERE (' . $filter['sql'] . ') WHERE (' . $filter['sql'] . ')
) AS tt ORDER BY val ASC'; ) AS tt ORDER BY val ASC';
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
return array('sql' => $this->sql, 'params' => $this->params); return array('sql' => $this->sql, 'params' => $this->params);
} }
} }

View File

@@ -17,6 +17,7 @@ class module_report_sqldownload extends module_report_sql implements module_repo
public function __construct(Application $app, module_report $report) public function __construct(Application $app, module_report $report)
{ {
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
parent::__construct($app, $report); parent::__construct($app, $report);
if ($report->isInformative()) { if ($report->isInformative()) {
$this->restrict = true; $this->restrict = true;
@@ -25,12 +26,15 @@ class module_report_sqldownload extends module_report_sql implements module_repo
public function buildSql() public function buildSql()
{ {
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$customFieldMap = array(); $customFieldMap = array();
$filter = $this->filter->getReportFilter() ? : array('params' => array(), 'sql' => false); $filter = $this->filter->getReportFilter() ? : array('params' => array(), 'sql' => false);
$this->params = array_merge(array(), $filter['params']); $this->params = array_merge(array(), $filter['params']);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
if ($this->groupby == false) { if ($this->groupby == false) {
/*
$this->sql = " $this->sql = "
SELECT DISTINCT(log.id), log.user, log.societe, log.pays, log.activite, log_colls.coll_id, SELECT DISTINCT(log.id), log.user, log.societe, log.pays, log.activite, log_colls.coll_id,
log.fonction, log.usrid, log_docs.date AS ddate, log_docs.record_id, log_docs.final, log_docs.comment log.fonction, log.usrid, log_docs.date AS ddate, log_docs.record_id, log_docs.final, log_docs.comment
@@ -38,10 +42,24 @@ class module_report_sqldownload extends module_report_sql implements module_repo
INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_docs.log_id) INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_docs.log_id)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id)
WHERE (" .$filter['sql'] . ") AND (log_docs.action = 'download' OR log_docs.action = 'mail')"; WHERE (" .$filter['sql'] . ") AND (log_docs.action = 'download' OR log_docs.action = 'mail')";
*/
$this->sql = "
SELECT log.id, log.user, log.societe, log.pays, log.activite, record.coll_id,
log.fonction, log.usrid, log_docs.date AS ddate, log_docs.record_id, log_docs.final, log_docs.comment
FROM
(
log_docs
INNER JOIN
log FORCE INDEX (date_site) ON (log.id = log_docs.log_id)
)
LEFT JOIN
record ON (record.record_id=log_docs.record_id)
WHERE (" .$filter['sql'] . ") AND (log_docs.action = 'download' OR log_docs.action = 'mail')";
if ($this->restrict) { if ($this->restrict) {
$this->sql .= ' AND (log_docs.final = "document" OR log_docs.final = "preview")'; $this->sql .= ' AND (log_docs.final = "document" OR log_docs.final = "preview")';
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
} else { } else {
$name = $this->groupby; $name = $this->groupby;
$field = $this->getTransQuery($this->groupby); $field = $this->getTransQuery($this->groupby);
@@ -50,12 +68,12 @@ class module_report_sqldownload extends module_report_sql implements module_repo
$this->sql = ' $this->sql = '
SELECT ' . $name . ', SUM(1) AS telechargement, tt.comment, tt.size, tt.file, tt.mime, tt.final SELECT ' . $name . ', SUM(1) AS telechargement, tt.comment, tt.size, tt.file, tt.mime, tt.final
FROM ( FROM (
SELECT DISTINCT(log.id), TRIM( ' . $field . ' ) AS ' . $name . ', log_docs.comment, subdef.size, subdef.file, subdef.mime, log_docs.final SELECT log.id, TRIM( ' . $field . ' ) AS ' . $name . ', log_docs.comment, subdef.size, subdef.file, subdef.mime, log_docs.final
FROM log FORCE INDEX (date_site) FROM log FORCE INDEX (date_site)
INNER JOIN log_docs ON (log.id = log_docs.log_id) INNER JOIN log_docs ON (log.id = log_docs.log_id)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id)
INNER JOIN record ON (log_docs.record_id = record.record_id) LEFT JOIN record ON (log_docs.record_id = record.record_id)
INNER JOIN subdef ON (log_docs.record_id = subdef.record_id)'; LEFT JOIN subdef ON (log_docs.record_id = subdef.record_id)';
$customFieldMap = array( $customFieldMap = array(
$field => $name, $field => $name,
@@ -65,6 +83,7 @@ class module_report_sqldownload extends module_report_sql implements module_repo
'subdef.mime' => 'tt.mime', 'subdef.mime' => 'tt.mime',
'log_docs.final' => 'tt.final', 'log_docs.final' => 'tt.final',
); );
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
} elseif ($this->on == 'DOC') { } elseif ($this->on == 'DOC') {
$this->sql = ' $this->sql = '
@@ -76,6 +95,7 @@ class module_report_sqldownload extends module_report_sql implements module_repo
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id)
INNER JOIN record ON (log_docs.record_id = record.record_id) INNER JOIN record ON (log_docs.record_id = record.record_id)
INNER JOIN subdef ON ( log_docs.record_id = subdef.record_id)'; INNER JOIN subdef ON ( log_docs.record_id = subdef.record_id)';
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
} else { } else {
$this->sql = ' $this->sql = '
SELECT ' . $name . ', SUM(1) AS nombre SELECT ' . $name . ', SUM(1) AS nombre
@@ -86,6 +106,7 @@ class module_report_sqldownload extends module_report_sql implements module_repo
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id)
INNER JOIN record ON (log_docs.record_id = record.record_id) INNER JOIN record ON (log_docs.record_id = record.record_id)
INNER JOIN subdef ON (record.record_id = subdef.record_id)'; INNER JOIN subdef ON (record.record_id = subdef.record_id)';
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
} }
$this->sql .= ' WHERE (subdef.name = log_docs.final) AND ' . $filter['sql'] . ' '; $this->sql .= ' WHERE (subdef.name = log_docs.final) AND ' . $filter['sql'] . ' ';
@@ -93,12 +114,14 @@ class module_report_sqldownload extends module_report_sql implements module_repo
$this->sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\' ' : ''; $this->sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\' ' : '';
$this->sql .= ') as tt'; $this->sql .= ') as tt';
$this->sql .= ' GROUP BY ' . $name . ' ' . ($name == 'record_id' && $this->on == 'DOC' ? ', final' : ''); $this->sql .= ' GROUP BY ' . $name . ' ' . ($name == 'record_id' && $this->on == 'DOC' ? ', final' : '');
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
} }
$stmt = $this->connbas->prepare($this->sql); $stmt = $this->connbas->prepare($this->sql);
$stmt->execute($this->params); $stmt->execute($this->params);
$this->total_row = $stmt->rowCount(); $this->total_row = $stmt->rowCount();
$stmt->closeCursor(); $stmt->closeCursor();
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
if (count($customFieldMap) > 0) { if (count($customFieldMap) > 0) {
$this->sql .= $this->filter->getOrderFilter($customFieldMap) ? : ''; $this->sql .= $this->filter->getOrderFilter($customFieldMap) ? : '';
@@ -110,6 +133,8 @@ class module_report_sqldownload extends module_report_sql implements module_repo
$this->sql .= $this->filter->getLimitFilter() ? : ''; $this->sql .= $this->filter->getLimitFilter() ? : '';
} }
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
return $this; return $this;
} }

View File

@@ -66,40 +66,48 @@ class module_report_sqlfilter
public function getReportFilter() public function getReportFilter()
{ {
$finalfilter = ''; $sql = '';
/*
$params = array(':log_site' => $this->app['phraseanet.configuration']['main']['key']); $params = array(':log_site' => $this->app['phraseanet.configuration']['main']['key']);
*/
$params = array();
if ($this->filter['date'] && $this->filter['date']['sql'] !== '') { if ($this->filter['date'] && $this->filter['date']['sql'] !== '') {
$finalfilter .= $this->filter['date']['sql'] . ' AND '; $sql .= $this->filter['date']['sql'] . ' AND ';
$params = array_merge($params, $this->filter['date']['params']); $params = array_merge($params, $this->filter['date']['params']);
} }
if ($this->filter['user'] && $this->filter['user']['sql'] !== '') { if ($this->filter['user'] && $this->filter['user']['sql'] !== '') {
$finalfilter .= $this->filter['user']['sql'] . ' AND '; $sql .= $this->filter['user']['sql'] . ' AND ';
$params = array_merge($params, $this->filter['user']['params']); $params = array_merge($params, $this->filter['user']['params']);
} }
if ($this->filter['collection'] && $this->filter['collection']['sql'] !== '') { if ($this->filter['collection'] && $this->filter['collection']['sql'] !== '') {
$finalfilter .= $this->filter['collection']['sql'] . ' AND '; $sql .= $this->filter['collection']['sql'] . ' AND ';
$params = array_merge($params, $this->filter['collection']['params']); $params = array_merge($params, $this->filter['collection']['params']);
} }
$finalfilter .= ' log.site = :log_site'; /*
$sql .= ' log.site = :log_site';
*/
$sql .= ' log.site=' . $this->conn->quote($this->app['phraseanet.configuration']['main']['key']);
return array('sql' => $finalfilter, 'params' => $params); return array('sql' => $sql, 'params' => $params);
} }
public function getGvSitFilter() public function getGvSitFilter()
{ {
$params = array(); $params = array();
/*
$sql = 'log.site = :log_site_gv_filter'; $sql = 'log.site = :log_site_gv_filter';
$params[':log_site_gv_filter'] = $this->app['phraseanet.configuration']['main']['key']; $params[':log_site_gv_filter'] = $this->app['phraseanet.configuration']['main']['key'];
*/
$sql = "log.site=" . $this->conn->quote($this->app['phraseanet.configuration']['main']['key']);
return array('sql' => $sql, 'params' => $params); return array('sql' => $sql, 'params' => $params);
} }
public function getUserIdFilter($id) public function getUserIdFilter($id)
{ {
return array('sql' => "log.usrid = :usr_id_filter", 'params' => array(':usr_id_filter' => $id)); // return array('sql' => "log.usrid = :usr_id_filter", 'params' => array(':usr_id_filter' => $id));
return array('sql' => "log.usrid=" . (int)$id, 'params' => array());
} }
public function getDateFilter() public function getDateFilter()
@@ -139,6 +147,7 @@ class module_report_sqlfilter
private function dateFilter(module_report $report) private function dateFilter(module_report $report)
{ {
$this->filter['date'] = false; $this->filter['date'] = false;
/*
if ($report->getDmin() && $report->getDmax()) { if ($report->getDmin() && $report->getDmax()) {
$this->filter['date'] = array( $this->filter['date'] = array(
'sql' => ' (log.date > :date_min_f AND log.date < :date_max_f) ' 'sql' => ' (log.date > :date_min_f AND log.date < :date_max_f) '
@@ -148,6 +157,20 @@ class module_report_sqlfilter
) )
); );
} }
*/
$sql = "";
if($report->getDmin()) {
$sql = "log.date>=" . $this->conn->quote($report->getDmin());
}
if($report->getDmax()) {
if($sql != "") {
$sql .= " AND ";
}
$sql .= "log.date<=" . $this->conn->quote($report->getDmax());
}
$this->filter['date'] = array(
'sql' => $sql, 'params' => array()
);
return; return;
} }

View File

@@ -25,11 +25,12 @@ class module_report_sqlquestion extends module_report_sql implements module_repo
$this->params = array_merge(array(), $filter['params']); $this->params = array_merge(array(), $filter['params']);
if ($this->groupby == false) { if ($this->groupby == false) {
$this->sql =" $this->sql =" SELECT log.id, log_search.date ddate, log_search.search, log.usrid, log.user, log.pays, log.societe, log.activite, log.fonction
SELECT DISTINCT(log.id), log_search.date ddate, log_search.search, log.usrid, log.user, log.pays, log.societe, log.activite, log.fonction
FROM log_search FROM log_search
INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_search.log_id) INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_search.log_id) AND !ISNULL(usrid)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id) WHERE (" . $filter['sql'] .")"; WHERE (" . $filter['sql'] .")";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
$stmt = $this->connbas->prepare($this->sql); $stmt = $this->connbas->prepare($this->sql);
$stmt->execute($this->params); $stmt->execute($this->params);
@@ -54,6 +55,8 @@ class module_report_sqlquestion extends module_report_sql implements module_repo
GROUP BY " . $this->groupby ." GROUP BY " . $this->groupby ."
ORDER BY nb DESC"; ORDER BY nb DESC";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
$stmt = $this->connbas->prepare($this->sql); $stmt = $this->connbas->prepare($this->sql);
$stmt->execute($this->params); $stmt->execute($this->params);
$this->total_row = $stmt->rowCount(); $this->total_row = $stmt->rowCount();

View File

@@ -19,7 +19,7 @@
<div class="form_titre">{% trans "report:: 2 - Bases" %}</div> <div class="form_titre">{% trans "report:: 2 - Bases" %}</div>
<div id="select_one"> <div id="select_one">
<ul class="multiselect" style="max-height: 150px; overflow-y: auto; overflow-x: hidden;"> <ul class="multiselect" style="max-height: 150px; overflow-y: auto; overflow-x: hidden;">
<li> <li style="visibility: hidden">
<a href="javascript:void(0);" class="select-all"> <a href="javascript:void(0);" class="select-all">
{% trans %}Select all{% endtrans %} {% trans %}Select all{% endtrans %}
</a> </a>
@@ -30,7 +30,7 @@
{% for sbas_id,databox in granted_bases %} {% for sbas_id,databox in granted_bases %}
<li><label data-group-id="{{ loop.index }}" class="multiselect-group"><b>{{ databox.name }}</b></label></li> <li><label data-group-id="{{ loop.index }}" class="multiselect-group"><b>{{ databox.name }}</b></label></li>
{% for collection in databox.collections %} {% for collection in databox.collections %}
<li> <li style="visibility: hidden">
<a href="javascript:void(0);"> <a href="javascript:void(0);">
<label class="checkbox"> <label class="checkbox">
<input name="popbases[]" checked="checked" type="checkbox" class="coll-checkbox checkbox-{{ loop.parent.loop.index }}" value="{{ sbas_id }}_{{ collection.id }}"> <input name="popbases[]" checked="checked" type="checkbox" class="coll-checkbox checkbox-{{ loop.parent.loop.index }}" value="{{ sbas_id }}_{{ collection.id }}">

View File

@@ -64,7 +64,8 @@ function bindEvents() {
$('#dminDash, #dmaxDash').datepicker({ $('#dminDash, #dmaxDash').datepicker({
changeMonth: true, changeMonth: true,
changeYear: true, changeYear: true,
dateFormat: 'dd-mm-yy', // dateFormat: 'dd-mm-yy',
dateFormat: 'yy-mm-dd',
numberOfMonths: 1, numberOfMonths: 1,
maxDate: "-0d" maxDate: "-0d"
}); });
@@ -119,7 +120,8 @@ function reportDatePicker() {
defaultDate: -10, defaultDate: -10,
changeMonth: true, changeMonth: true,
changeYear: true, changeYear: true,
dateFormat: 'dd-mm-yy', // dateFormat: 'dd-mm-yy',
dateFormat: 'yy-mm-dd',
numberOfMonths: 3, numberOfMonths: 3,
maxDate: "-0d", maxDate: "-0d",
onSelect: function (selectedDate, instance) { onSelect: function (selectedDate, instance) {
@@ -136,7 +138,8 @@ function dashboardDatePicker() {
defaultDate: -3, defaultDate: -3,
changeMonth: true, changeMonth: true,
changeYear: true, changeYear: true,
dateFormat: 'dd-mm-yy', // dateFormat: 'dd-mm-yy',
dateFormat: 'yy-mm-dd',
numberOfMonths: 3, numberOfMonths: 3,
maxDate: "-0d" maxDate: "-0d"
}); });