mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 19:43:16 +00:00
Refactor reports into silex controllers
Refactor reports into silex controllers
This commit is contained in:
@@ -415,13 +415,6 @@ class module_report_nav extends module_report
|
||||
$filter_id_apbox = $filter_id_datbox = array();
|
||||
$conn = $this->app['phraseanet.appbox']->get_connection();
|
||||
|
||||
$datefilter = array();
|
||||
|
||||
if ($this->dmin && $this->dmax) {
|
||||
$params = array(':dmin' => $this->dmin, ':dmax' => $this->dmax);
|
||||
$datefilter = "date > :dmin AND date < :dmax";
|
||||
}
|
||||
|
||||
$this->title = sprintf(_('report:: Information sur les utilisateurs correspondant a %s'), $val);
|
||||
|
||||
if ($on) {
|
||||
@@ -446,7 +439,7 @@ class module_report_nav extends module_report
|
||||
usr_mail as mail,
|
||||
adresse, tel
|
||||
FROM usr
|
||||
WHERE $on = :value AND (" . $filter_id_apbox . ")";
|
||||
WHERE $on = :value " . (('' !== $filter_id_apbox) ? "AND (" . $filter_id_apbox . ")" : '');
|
||||
} else {
|
||||
$sql = '
|
||||
SELECT
|
||||
@@ -548,19 +541,19 @@ class module_report_nav extends module_report
|
||||
_('report:: Information sur le navigateur %s'), $navigator);
|
||||
$sqlBuilder = new module_report_sql($this->app, $this);
|
||||
$filter = $sqlBuilder->getFilters();
|
||||
$params = array(':browser' => $navigator);
|
||||
$report_filter = $filter->getReportFilter();
|
||||
$params = array_merge($report_filter['params'], array(':browser' => $navigator));
|
||||
|
||||
$sql = "
|
||||
SELECT DISTINCT(version), COUNT(version) as nb
|
||||
SELECT DISTINCT(tt.version), COUNT(tt.version) as nb
|
||||
FROM (
|
||||
SELECT DISTINCT (log.id)
|
||||
SELECT DISTINCT (log.id), version
|
||||
FROM log FORCE INDEX (date_site, nav, version)
|
||||
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id)
|
||||
WHERE ". $report_filter['sql'] . "
|
||||
WHERE nav = :browser
|
||||
AND ". $report_filter['sql'] . "
|
||||
) AS tt
|
||||
GROUP BY tt.version
|
||||
GROUP BY version
|
||||
ORDER BY nb DESC";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
|
@@ -38,6 +38,8 @@ class module_report_sqlaction extends module_report_sql implements module_report
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$customFieldMap = array();
|
||||
|
||||
$filter = $this->filter->getReportFilter() ? : array('params' => array(), 'sql' => false);
|
||||
$this->params = array_merge(array(':action' => $this->action), $filter['params']);
|
||||
|
||||
@@ -53,12 +55,22 @@ class module_report_sqlaction extends module_report_sql implements module_report
|
||||
WHERE (" . $filter['sql'] . ") AND (d.action = :action)
|
||||
) AS tt";
|
||||
|
||||
$customFieldMap = array(
|
||||
'log.usrid' => 'tt.usrid',
|
||||
'log.user' => 'tt.user',
|
||||
'd.final' => 'getter',
|
||||
'd.record_id' => 'tt.record_id',
|
||||
'd.date' => 'tt.date',
|
||||
'record.mime' => 'tt.mime',
|
||||
'file' => 'tt.file',
|
||||
);
|
||||
|
||||
$stmt = $this->getConnBas()->prepare($this->sql);
|
||||
$stmt->execute($this->params);
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getOrderFilter() ? : '';
|
||||
$this->sql .= $this->filter->getOrderFilter($customFieldMap) ? : '';
|
||||
$this->sql .= $this->filter->getLimitFilter() ? : '';
|
||||
} else {
|
||||
$this->sql = "
|
||||
|
@@ -25,6 +25,8 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$customFieldMap = array();
|
||||
|
||||
$filter = $this->filter->getReportFilter() ? : array('params' => array(), 'sql' => false);
|
||||
$this->params = array_merge(array(), $filter['params']);
|
||||
|
||||
@@ -54,6 +56,16 @@ 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 record ON (log_docs.record_id = record.record_id)
|
||||
INNER JOIN subdef ON (log_docs.record_id = subdef.record_id)';
|
||||
|
||||
$customFieldMap = array(
|
||||
$field => $name,
|
||||
'log_docs.comment' => 'tt.comment',
|
||||
'subdef.size' => 'tt.size',
|
||||
'subdef.file' => 'tt.file',
|
||||
'subdef.mime' => 'tt.mime',
|
||||
'log_docs.final' => 'tt.final',
|
||||
);
|
||||
|
||||
} elseif ($this->on == 'DOC') {
|
||||
$this->sql = '
|
||||
SELECT ' . $name . ', SUM(1) AS telechargement
|
||||
@@ -88,7 +100,12 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getOrderFilter() ? : '';
|
||||
if (count($customFieldMap) > 0) {
|
||||
$this->sql .= $this->filter->getOrderFilter($customFieldMap) ? : '';
|
||||
} else {
|
||||
$this->sql .= $this->filter->getOrderFilter() ? : '';
|
||||
}
|
||||
|
||||
$this->sql .= $this->filter->getLimitFilter() ? : '';
|
||||
|
||||
return $this;
|
||||
|
@@ -17,6 +17,7 @@ class module_report_sqlfilter
|
||||
private $filter;
|
||||
private $cor_query = array();
|
||||
private $app;
|
||||
private $report;
|
||||
|
||||
public function __construct(Application $app, module_report $report)
|
||||
{
|
||||
@@ -27,6 +28,8 @@ class module_report_sqlfilter
|
||||
$this->cor_query = $report->getTransQueryString();
|
||||
|
||||
$this->buildFilter($report);
|
||||
|
||||
$this->report = $report;
|
||||
}
|
||||
|
||||
public static function constructDateFilter($dmin, $dmax)
|
||||
@@ -123,9 +126,13 @@ class module_report_sqlfilter
|
||||
return $this->filter['limit'];
|
||||
}
|
||||
|
||||
public function getOrderFilter()
|
||||
public function getOrderFilter($customFieldMap = null)
|
||||
{
|
||||
return $this->filter['order'];
|
||||
if (null === $customFieldMap) {
|
||||
return $this->filter['order'];
|
||||
}
|
||||
|
||||
return $this->overrideOrderFilter($customFieldMap);
|
||||
}
|
||||
|
||||
private function dateFilter(module_report $report)
|
||||
@@ -259,4 +266,19 @@ class module_report_sqlfilter
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function overrideOrderFilter($customFieldMap)
|
||||
{
|
||||
if (sizeof($this->report->getOrder()) > 0) {
|
||||
if (!isset($customFieldMap[$this->cor_query[$this->report->getOrder('champ')]])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return " ORDER BY "
|
||||
. $customFieldMap[$this->cor_query[$this->report->getOrder('champ')]]
|
||||
. ' ' . $this->report->getOrder('order');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user