diff --git a/lib/Alchemy/Phrasea/Controller/Report/Activity.php b/lib/Alchemy/Phrasea/Controller/Report/Activity.php
index c4c93ef05e..20e41c6f56 100644
--- a/lib/Alchemy/Phrasea/Controller/Report/Activity.php
+++ b/lib/Alchemy/Phrasea/Controller/Report/Activity.php
@@ -58,6 +58,9 @@ class Activity implements ControllerProviderInterface
$controllers->post('/documents/validated', $this->call('doReportValidatedDocuments'))
->bind('report_activity_documents_validated');
+ $controllers->post('/documents/sent', $this->call('doReportSentDocuments'))
+ ->bind('report_activity_documents_sent');
+
return $controllers;
}
@@ -680,6 +683,72 @@ class Activity implements ControllerProviderInterface
));
}
+ /**
+ * Display report about documents sent by mail
+ *
+ * @param Application $app
+ * @param Request $request
+ * @return JsonResponse
+ */
+ public function doReportSentDocuments(Application $app, Request $request)
+ {
+ $conf = array(
+ 'user' => array('', 1, 0, 1, 1),
+ 'date' => array('', 1, 0, 1, 1),
+ 'record_id' => array('', 1, 1, 1, 1),
+ 'file' => array('', 1, 0, 1, 1),
+ 'mime' => array('', 1, 0, 1, 1),
+ 'comment' => array(_('Receiver'), 1, 0, 1, 1),
+ );
+
+ $activity = new \module_report_sent(
+ $app,
+ $request->request->get('dmin'),
+ $request->request->get('dmax'),
+ $request->request->get('sbasid'),
+ $request->request->get('collection')
+ );
+
+ $activity->setConfig(false);
+
+ if ($request->request->get('printcsv') == 'on') {
+ $activity->setHasLimit(false);
+ $activity->setPrettyString(false);
+
+ try {
+ $csv = \format::arr_to_csv($activity->getResult(), $activity->getDisplay());
+ } catch (\Exception $e) {
+ $csv = '';
+ }
+
+ return $app->json(array('rs' => $csv));
+ }
+
+ $report = $this->doReport($app, $request, $activity, $conf);
+
+ if ($report instanceof Response) {
+ return $report;
+ }
+
+ return $app->json(array(
+ 'rs' => $app['twig']->render('report/ajax_data_content.html.twig', array(
+ 'result' => isset($report['report']) ? $report['report'] : $report,
+ 'is_infouser' => false,
+ 'is_nav' => false,
+ 'is_groupby' => false,
+ 'is_plot' => false,
+ 'is_doc' => false
+ )),
+ 'display_nav' => $report['display_nav'], // do we display the prev and next button ?
+ 'next' => $report['next_page'], //Number of the next page
+ 'prev' => $report['previous_page'], //Number of the previoous page
+ 'page' => $report['page'], //The current page
+ 'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
+ 'col' => $report['active_column'], //all the columns where a filter is applied
+ 'limit' => $report['nb_record']
+ ));
+ }
+
/**
* Set Report configuration according to request parameters
*
diff --git a/lib/classes/module/report.php b/lib/classes/module/report.php
index d8eeb0163f..6adbc9bfd2 100644
--- a/lib/classes/module/report.php
+++ b/lib/classes/module/report.php
@@ -780,26 +780,24 @@ class module_report
foreach ($tab as $column => $row) {
foreach ($row as $ind => $value) {
- $def = false;
+ $title_text = "";
if (array_key_exists($column, $this->cor)) {
$title_text = $this->cor[$column];
- $def = true;
}
- empty($row[0]) ? $title = $column : $title = $row[0];
+
+ $title = empty($row[0]) ? "" : $row[0];
$sort = $row[1];
- array_key_exists($column, $this->bound) ?
- $bound = $this->bound[$column] : $bound = $row[2];
+ $bound = array_key_exists($column, $this->bound) ? $this->bound[$column] : $row[2];
$filter = (isset($row[3]) ? $row[3] : 0);
$groupby = $row[4];
$config = array(
- 'title' => $title,
+ 'title' => empty($title) ? (empty($title_text) ? $column : $title_text) : $title,
'sort' => $sort,
'bound' => $bound,
'filter' => $filter,
'groupby' => $groupby
);
- $def ? $config['title'] = $title_text : "";
$this->display[$column] = $config;
}
diff --git a/lib/classes/module/report/sent.php b/lib/classes/module/report/sent.php
new file mode 100644
index 0000000000..519286fb54
--- /dev/null
+++ b/lib/classes/module/report/sent.php
@@ -0,0 +1,127 @@
+ 'log.user',
+ 'site' => 'log.site',
+ 'societe' => 'log.societe',
+ 'pays' => 'log.pays',
+ 'activite' => 'log.activite',
+ 'fonction' => 'log.fonction',
+ 'usrid' => 'log.usrid',
+ 'getter' => 'd.final',
+ 'date' => "DATE(d.date)",
+ 'id' => 'd.id',
+ 'log_id' => 'd.log_id',
+ 'record_id' => 'd.record_id',
+ 'final' => 'd.final',
+ 'comment' => 'd.comment',
+ 'size' => 's.size'
+ );
+
+ /**
+ * constructor
+ *
+ * @param Application $app
+ * @param string $arg1 start date of the report
+ * @param string $arg2 end date of the report
+ * @param integer $sbas_id id of the databox
+ * @param string $collist
+ */
+ public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
+ {
+ parent::__construct($app, $arg1, $arg2, $sbas_id, $collist);
+ $this->title = _('Sent documents (mail)');
+ }
+
+ /**
+ * @desc build the specified requete
+ * @param $obj $conn the current connection to databox
+ * @return string
+ */
+ protected function buildReq($groupby = false, $on = false)
+ {
+ $sqlBuilder = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
+ ->setAction('mail')->buildSql();
+ $this->req = $sqlBuilder->getSql();
+ $this->params = $sqlBuilder->getParams();
+ $this->total = $sqlBuilder->getTotalRows();
+ }
+
+ public function colFilter($field, $on = false)
+ {
+ $sqlBuilder = $this->sqlBuilder('action')->setAction('mail');
+ $var = $sqlBuilder->sqlDistinctValByField($field);
+ $sql = $var['sql'];
+ $params = $var['params'];
+
+ $stmt = $sqlBuilder->getConnBas()->prepare($sql);
+ $stmt->execute($params);
+ $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ $stmt->closeCursor();
+
+ $ret = array();
+
+ foreach ($rs as $row) {
+ $value = $row['val'];
+ $caption = $value;
+ if ($field == "getter") {
+ try {
+ $user = User_Adapter::getInstance($value, $this->app);
+ $caption = $user->get_display_name();
+ } catch (Exception $e) {
+
+ }
+ } elseif ($field == 'date') {
+ $caption = $this->app['date-formatter']->getPrettyString(new DateTime($value));
+ } elseif ($field == 'size') {
+ $caption = p4string::format_octets($value);
+ }
+
+ $ret[] = array('val' => $caption, 'value' => $value);
+ }
+
+ return $ret;
+ }
+
+ protected function buildResult(Application $app, $rs)
+ {
+ $i = 0;
+
+ foreach ($rs as $row) {
+ if ($i >= $this->nb_record)
+ break;
+ foreach ($this->champ as $key => $value) {
+ if ($row[$value]) {
+ if ($value == 'date') {
+ $this->result[$i][$value] = $this->pretty_string ?
+ $this->app['date-formatter']->getPrettyString(new DateTime($row[$value])) :
+ $row[$value];
+ } elseif ($value == 'size') {
+ $this->result[$i][$value] = p4string::format_octets($row[$value]);
+ } else
+ $this->result[$i][$value] = $row[$value];
+ } else {
+ if ($value == 'comment') {
+ $this->result[$i][$value] = ' ';
+ } else {
+ $this->result[$i][$value] = '' . _('report:: non-renseigne') . '';
+ }
+ }
+ }
+ $i ++;
+ }
+ }
+}
diff --git a/lib/classes/module/report/sqlaction.php b/lib/classes/module/report/sqlaction.php
index 4fd6d18e5c..b29a0273d1 100644
--- a/lib/classes/module/report/sqlaction.php
+++ b/lib/classes/module/report/sqlaction.php
@@ -22,7 +22,7 @@ class module_report_sqlaction extends module_report_sql implements module_report
public function setAction($action)
{
- $a = array('edit', 'add', 'push', 'validate');
+ $a = array('edit', 'add', 'push', 'validate', 'mail');
if (in_array($action, $a)) {
$this->action = $action;
@@ -45,9 +45,9 @@ class module_report_sqlaction extends module_report_sql implements module_report
if ($this->groupby == false) {
$this->sql = "
- SELECT tt.usrid, tt.user, tt.final AS getter, tt.record_id, tt.date, tt.mime, tt.file
+ SELECT tt.usrid, tt.user, tt.final AS getter, tt.record_id, tt.date, tt.mime, tt.file, tt.comment
FROM (
- SELECT DISTINCT(log.id), log.usrid, log.user, d.final, d.record_id, d.date, record.mime, record.originalname as file
+ SELECT DISTINCT(log.id), log.usrid, log.user, d.final, d.comment, d.record_id, d.date, record.mime, record.originalname as file
FROM (log_docs AS d)
INNER JOIN log FORCE INDEX (date_site) ON (log.id = d.log_id)
INNER JOIN log_colls FORCE INDEX (couple) ON (log.id = log_colls.log_id)
@@ -63,6 +63,7 @@ class module_report_sqlaction extends module_report_sql implements module_report
'd.date' => 'tt.date',
'record.mime' => 'tt.mime',
'file' => 'tt.file',
+ 'd.comment' => 'tt.comment'
);
$stmt = $this->getConnBas()->prepare($this->sql);
diff --git a/templates/web/report/report_layout_child.html.twig b/templates/web/report/report_layout_child.html.twig
index b3e86b489c..0516d1589c 100644
--- a/templates/web/report/report_layout_child.html.twig
+++ b/templates/web/report/report_layout_child.html.twig
@@ -179,6 +179,7 @@
+
diff --git a/tests/classes/report/sentTest.php b/tests/classes/report/sentTest.php
new file mode 100644
index 0000000000..4524232065
--- /dev/null
+++ b/tests/classes/report/sentTest.php
@@ -0,0 +1,166 @@
+dmax = $date->format("Y-m-d H:i:s");
+ $date->modify('-6 month');
+ $this->dmin = $date->format("Y-m-d H:i:s");
+ $databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes();
+ $this->ret = array();
+ foreach ($databoxes as $databox) {
+ $colls = $databox->get_collections();
+ $rett = array();
+ foreach ($colls as $coll) {
+ $rett[$coll->get_coll_id()] = $coll->get_coll_id();
+ }
+ $this->ret[$databox->get_sbas_id()] = implode(',', $rett);
+ }
+ }
+
+ public function ColFilter()
+ {
+ $ret = $this->report->colFilter('user');
+
+ $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $ret);
+ foreach ($ret as $result) {
+ $this->assertArrayHasKey('val', $result);
+ $this->assertArrayHasKey('value', $result);
+ }
+ }
+
+ public function testBuildReport()
+ {
+ $conf = array(
+ 'user' => array("", 1, 0, 1, 1),
+ 'date' => array("", 1, 0, 1, 1),
+ 'record_id' => array("", 1, 1, 1, 1),
+ 'file' => array("", 1, 0, 1, 1),
+ 'mime' => array("", 1, 0, 1, 1),
+ 'comment' => array("Receiver", 1, 0, 1, 1),
+ );
+
+ foreach ($this->ret as $sbasid => $collections) {
+ $this->report = new module_report_sent(
+ self::$DI['app'],
+ $this->dmin,
+ $this->dmax,
+ $sbasid,
+ $collections
+ );
+
+ $result = $this->report->buildReport($conf);
+
+ $this->reporttestPage($result);
+ if (count($result['result']) > 0)
+ $this->reporttestConf($conf);
+ if (count($result['result']) > 0)
+ $this->reporttestResult($result, $conf);
+
+ $this->ColFilter();
+ }
+
+ foreach ($this->ret as $sbasid => $collections) {
+ $this->report = new module_report_add(
+ self::$DI['app'],
+ $this->dmin,
+ $this->dmax,
+ $sbasid,
+ $collections
+ );
+
+ $this->ColFilter();
+
+ $result = $this->report->buildReport(false, 'user');
+ $this->reporttestPage($result);
+ if (count($result['result']) > 0)
+ $this->reporttestConf($conf, 'user');
+ if (count($result['result']) > 0)
+ $this->reporttestResult($result, $conf, 'user');
+ }
+ }
+
+ public function reporttestPage($report)
+ {
+ $this->assertLessThanOrEqual($this->report->getNbRecord(), count($report['result']));
+
+ $nbPage = $this->report->getTotal() / $this->report->getNbRecord();
+
+ if ($this->report->getTotal() > $this->report->getNbRecord())
+ $this->assertTrue($report['display_nav']);
+ else
+ $this->assertFalse($report['display_nav']);
+
+ if ($report['page'] == 1)
+ $this->assertFalse($report['previous_page']);
+ else
+ $this->assertEquals($report['page'] - 1, $report['previous_page']);
+
+ if (intval(ceil($nbPage)) == $report['page'] || intval(ceil($nbPage)) == 0)
+ $this->assertFalse($report['next_page']);
+ else
+ $this->assertEquals($report['page'] + 1, $report['next_page']);
+ }
+
+ public function reporttestConf($conf, $groupby = false)
+ {
+ if ($groupby)
+ $this->assertEquals(count($this->report->getDisplay()), 2);
+ else
+ $this->assertEquals(count($this->report->getDisplay()), count($conf));
+
+ if (! $groupby) {
+ foreach ($this->report->getDisplay() as $col => $colconf) {
+ $this->assertArrayHaskey($col, $conf);
+ $this->assertTrue(is_array($colconf));
+ $this->assertArrayHasKey('title', $colconf);
+ $this->assertArrayHasKey('sort', $colconf);
+ $this->assertArrayHasKey('bound', $colconf);
+ $this->assertArrayHasKey('filter', $colconf);
+ $this->assertArrayHasKey('groupby', $colconf);
+ $i = 0;
+ foreach ($colconf as $key => $value) {
+ if ($i == 1)
+ $this->assertEquals($conf[$col][$i], $value);
+ elseif ($i == 2)
+ $this->assertEquals($conf[$col][$i], $value);
+ elseif ($i == 3)
+ $this->assertEquals($conf[$col][$i], $value);
+ elseif ($i == 4)
+ $this->assertEquals($conf[$col][$i], $value);
+ $i ++;
+ }
+ }
+ } else {
+ $this->assertArrayHasKey($groupby, $this->report->getDisplay());
+ $this->assertArrayHasKey('nombre', $this->report->getDisplay());
+ }
+ }
+
+ public function reporttestResult($report, $conf, $groupby = false)
+ {
+ if (! $groupby) {
+ foreach ($report['result'] as $row) {
+ foreach ($conf as $key => $value) {
+
+ $this->assertArrayHasKey($key, $row);
+ $condition = is_string($row[$key]) || is_int($row[$key]);
+ $this->assertTrue($condition);
+ }
+ }
+ } else {
+ foreach ($report['result'] as $row) {
+ $this->assertArrayHasKey($groupby, $row);
+ $this->assertArrayHasKey('nombre', $row);
+ }
+ }
+ }
+}
diff --git a/www/skins/report/report.js b/www/skins/report/report.js
index 0e3a14f76f..4b87fe7cd5 100644
--- a/www/skins/report/report.js
+++ b/www/skins/report/report.js
@@ -169,9 +169,9 @@ function submiterAction(domSubmiter)
var form = domSubmiter.closest('form');
var container = domSubmiter.closest('.inside-container');
- data = form.serializeArray();
-
- data[data.length] = {name: "action", value: domSubmiter.data('action')};
+ var data = form.serializeArray();
+ var action = form.find('select.options option:selected');
+ data.push({name: "action", value: action.data('action')});
//check if a base is selected, pop an alert message if not
if(!isOneBaseSelected(form))