Files
Phraseanet/lib/classes/module/report/sqldownload.php
Nicolas Le Goff 9f38823f27 Merge branch '3.8'
Conflicts:
	composer.lock
	lib/Alchemy/Phrasea/Application.php
	lib/Alchemy/Phrasea/Command/Setup/H264MappingGenerator.php
	lib/Alchemy/Phrasea/Controller/AbstractDelivery.php
	lib/Alchemy/Phrasea/Controller/Prod/DoDownload.php
	lib/Alchemy/Phrasea/Controller/Prod/Edit.php
	lib/Alchemy/Phrasea/Controller/Prod/Story.php
	lib/Alchemy/Phrasea/Controller/Prod/Upload.php
	lib/Alchemy/Phrasea/Controller/Report/Activity.php
	lib/Alchemy/Phrasea/Controller/Report/Root.php
	lib/Alchemy/Phrasea/Controller/Root/Account.php
	lib/Alchemy/Phrasea/Core/PhraseaEvents.php
	lib/Alchemy/Phrasea/Core/Version.php
	lib/classes/API/V1/adapter.php
	lib/classes/User/Adapter.php
	lib/classes/databox.php
	lib/classes/media/subdef.php
	lib/classes/module/report.php
	lib/classes/module/report/activity.php
	lib/classes/module/report/connexion.php
	lib/classes/module/report/download.php
	lib/classes/module/report/nav.php
	lib/classes/module/report/question.php
	lib/classes/module/report/sqlaction.php
	lib/classes/module/report/sqlconnexion.php
	lib/classes/module/report/sqldownload.php
	lib/classes/module/report/sqlfilter.php
	lib/classes/task/abstract.php
	locale/de_DE/LC_MESSAGES/phraseanet.mo
	locale/de_DE/LC_MESSAGES/phraseanet.po
	locale/en_GB/LC_MESSAGES/phraseanet.mo
	locale/en_GB/LC_MESSAGES/phraseanet.po
	locale/fr_FR/LC_MESSAGES/phraseanet.mo
	locale/fr_FR/LC_MESSAGES/phraseanet.po
	locale/nl_NL/LC_MESSAGES/phraseanet.mo
	locale/nl_NL/LC_MESSAGES/phraseanet.po
	locale/phraseanet.pot
	templates/web/prod/index.html.twig
	tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php
	tests/classes/api/v1/api_v1_adapterTest.php
	tests/classes/report/activityTest.php
	tests/classes/report/editTest.php
2014-12-09 13:59:29 +01:00

167 lines
7.5 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
class module_report_sqldownload extends module_report_sql implements module_report_sqlReportInterface
{
protected $restrict = false;
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);
if ($report->isInformative()) {
$this->restrict = true;
}
}
public function buildSql()
{
<<<<<<< HEAD
$customFieldMap = [];
=======
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
$customFieldMap = array();
>>>>>>> 3.8
$filter = $this->filter->getReportFilter() ? : ['params' => [], 'sql' => false];
$this->params = array_merge([], $filter['params']);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
if ($this->groupby == false) {
/*
$this->sql = "
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
FROM log_docs
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 (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)
LEFT JOIN subdef ON (log_docs.record_id = subdef.record_id)
WHERE (" .$filter['sql'] . ")
AND !ISNULL(usrid)
AND (log_docs.action = 'download' OR log_docs.action = 'mail')
AND (log_docs.final = 'preview' OR log_docs.final = 'document')";
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
} else {
$name = $this->groupby;
$field = $this->getTransQuery($this->groupby);
if ($name == 'record_id' && $this->on == 'DOC') {
$this->sql = '
SELECT ' . $name . ', SUM(1) AS telechargement, tt.comment, tt.size, tt.file, tt.mime, tt.final
FROM (
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)
INNER JOIN log_docs ON (log.id = log_docs.log_id)
LEFT JOIN record ON (log_docs.record_id = record.record_id)
LEFT JOIN subdef ON (log_docs.record_id = subdef.record_id)';
$customFieldMap = [
$field => $name,
'log_docs.comment' => 'tt.comment',
'subdef.size' => 'tt.size',
'subdef.file' => 'tt.file',
'subdef.mime' => 'tt.mime',
'log_docs.final' => 'tt.final',
<<<<<<< HEAD
];
=======
);
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
>>>>>>> 3.8
} elseif ($this->on == 'DOC') {
$this->sql = '
SELECT ' . $name . ', SUM(1) AS telechargement
FROM (
SELECT DISTINCT(log.id), TRIM(' . $field . ') AS ' . $name . '
FROM log FORCE INDEX (date_site)
INNER JOIN log_docs ON (log.id = log_docs.log_id)
LEFT JOIN record ON (log_docs.record_id = record.record_id)
LEFT 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 {
$this->sql = '
SELECT ' . $name . ', SUM(1) AS nombre
FROM (
SELECT DISTINCT(log.id), TRIM( ' . $this->getTransQuery($this->groupby) . ') AS ' . $name . '
FROM log FORCE INDEX (date_site)
INNER JOIN log_docs ON (log.id = log_docs.log_id)
LEFT JOIN record ON (log_docs.record_id = record.record_id)
LEFT 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 ' . $filter['sql'] . ' ';
$this->sql .= 'AND ( log_docs.action = \'download\' OR log_docs.action = \'mail\') ';
$this->sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\' ' : '';
$this->sql .= ') as tt';
$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->execute($this->params);
$this->total_row = $stmt->rowCount();
$stmt->closeCursor();
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
if (count($customFieldMap) > 0) {
$this->sql .= $this->filter->getOrderFilter($customFieldMap) ? : '';
} else {
$this->sql .= $this->filter->getOrderFilter() ? : '';
}
if ($this->enable_limit) {
$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;
}
public function sqlDistinctValByField($field)
{
$filter = $this->filter->getReportFilter() ? : ['params' => [], 'sql' => false];
$this->params = array_merge([], $filter['params']);
$this->sql = '
SELECT DISTINCT(tt.val)
FROM (
SELECT DISTINCT(log.id), ' . $this->getTransQuery($field) . ' AS val
FROM log FORCE INDEX (date_site)
INNER JOIN log_docs ON (log.id = log_docs.log_id)
LEFT JOIN record ON (log_docs.record_id = record.record_id)
LEFT JOIN subdef ON (log_docs.record_id = subdef.record_id)
WHERE (' . $filter['sql'] . ')
AND (log_docs.action = "download" OR log_docs.action = "mail")' .
($this->on == 'DOC' ? ' AND subdef.name = "document"' : '') .
') AS tt';
$this->sql .= $this->filter->getOrderFilter() ? : '';
$this->sql .= $this->filter->getLimitFilter() ? : '';
return ['sql' => $this->sql, 'params' => $this->params];
}
}