mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 09:53:15 +00:00
PHRAS-2327_report_refacto_41
This commit is contained in:
@@ -65,8 +65,6 @@ class RouteLoader
|
||||
'/prod/upload/' => Providers\Prod\Upload::class,
|
||||
'/prod/WorkZone' => Providers\Prod\WorkZone::class,
|
||||
'/prod/' => Providers\Prod\Root::class,
|
||||
'/report/activity' => Providers\Report\Activity::class,
|
||||
'/report/informations' => Providers\Report\Information::class,
|
||||
'/report/' => Providers\Report\Root::class,
|
||||
'/session/' => Providers\Root\Session::class,
|
||||
'/setup' => Providers\Setup::class,
|
||||
|
@@ -1,802 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Alchemy\Phrasea\Controller\Report;
|
||||
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Core\Response\CSVFileResponse;
|
||||
use Goodby\CSV\Export\Standard\Collection\CallbackCollection;
|
||||
use Goodby\CSV\Export\Standard\Exporter;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ActivityController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display connexions report group by user
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportConnexionsByUsers(Request $request)
|
||||
{
|
||||
$activity = new \module_report_activity(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$activity->setConfig(false);
|
||||
$activity->setBound("user", true);
|
||||
|
||||
//set Limit
|
||||
if ($activity->getEnableLimit()
|
||||
&& ('' !== $page = $request->request->get('page', ''))
|
||||
&& ('' !== $limit = $request->request->get('limit', ''))) {
|
||||
$activity->setLimit($page, $limit);
|
||||
} else {
|
||||
$activity->setLimit(false, false);
|
||||
}
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$activity->setHasLimit(false);
|
||||
$activity->getConnexionBase(false, $request->request->get('on', 'user'));
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_connection_base');
|
||||
}
|
||||
|
||||
$report = $activity->getConnexionBase(false, $request->request->get('on', 'user'));
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($report['report']) ? $report['report'] : $report,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false,
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display download report group by user
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportDownloadsByUsers(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'user' => [$this->app->trans('report:: utilisateur'), 0, 1, 0, 0],
|
||||
'nbdoc' => [$this->app->trans('report:: nombre de documents'), 0, 0, 0, 0],
|
||||
'nbprev' => [$this->app->trans('report:: nombre de preview'), 0, 0, 0, 0],
|
||||
];
|
||||
|
||||
$activity = new \module_report_activity(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$activity->setConfig(false);
|
||||
|
||||
//set Limit
|
||||
if ($activity->getEnableLimit()
|
||||
&& ('' !== $page = $request->request->get('page', ''))
|
||||
&& ('' !== $limit = $request->request->get('limit', ''))) {
|
||||
$activity->setLimit($page, $limit);
|
||||
} else {
|
||||
$activity->setLimit(false, false);
|
||||
}
|
||||
|
||||
$report = $activity->getDetailDownload($conf, $request->request->get('on'));
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$activity->setHasLimit(false);
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_detail_download');
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($report['report']) ? $report['report'] : $report,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false,
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the most asked question
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportBestOfQuestions(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'search' => [$this->app->trans('report:: question'), 0, 0, 0, 0],
|
||||
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
|
||||
'nb_rep' => [$this->app->trans('report:: nombre de reponses'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
$activity = new \module_report_activity(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$activity->setLimit(1, $request->request->get('limit', 20));
|
||||
$activity->setTop(20);
|
||||
$activity->setConfig(false);
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$activity->setHasLimit(false);
|
||||
$activity->setPrettyString(false);
|
||||
|
||||
$activity->getTopQuestion($conf);
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_questions_best_of');
|
||||
}
|
||||
|
||||
$report = $activity->getTopQuestion($conf);
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($report['report']) ? $report['report'] : $report,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => false
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display report about questions that return no result
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportNoBestOfQuestions(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'search' => [$this->app->trans('report:: question'), 0, 0, 0, 0],
|
||||
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
|
||||
'nb_rep' => [$this->app->trans('report:: nombre de reponses'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
$activity = new \module_report_activity(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
//set Limit
|
||||
if ($activity->getEnableLimit()
|
||||
&& ('' !== $page = $request->request->get('page', ''))
|
||||
&& ('' !== $limit = $request->request->get('limit', ''))) {
|
||||
$activity->setLimit($page, $limit);
|
||||
} else {
|
||||
$activity->setLimit(false, false);
|
||||
}
|
||||
|
||||
$activity->setConfig(false);
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$activity->setHasLimit(false);
|
||||
$activity->setPrettyString(false);
|
||||
|
||||
$activity->getTopQuestion($conf, true);
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_top_ten_questions');
|
||||
}
|
||||
|
||||
$report = $activity->getTopQuestion($conf, true);
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($report['report']) ? $report['report'] : $report,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => false
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an overview of connexion among hours of the da
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportSiteActiviyPerHours(Request $request)
|
||||
{
|
||||
$activity = new \module_report_activity(
|
||||
$this->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);
|
||||
|
||||
$activity->getActivityPerHours();
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_per_hours');
|
||||
}
|
||||
|
||||
$report = $activity->getActivityPerHours();
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($report['report']) ? $report['report'] : $report,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => true,
|
||||
'is_doc' => false
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => false
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an overview of downloaded document grouped by day
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportSiteActivityPerDays(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'ddate' => [$this->app->trans('report:: jour'), 0, 0, 0, 0],
|
||||
'total' => [$this->app->trans('report:: total des telechargements'), 0, 0, 0, 0],
|
||||
'preview' => [$this->app->trans('report:: preview'), 0, 0, 0, 0],
|
||||
'document' => [$this->app->trans('report:: document'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
$activity = new \module_report_activity(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
//set Limit
|
||||
if ($activity->getEnableLimit()
|
||||
&& ('' !== $page = $request->request->get('page', ''))
|
||||
&& ('' !== $limit = $request->request->get('limit', ''))) {
|
||||
$activity->setLimit($page, $limit);
|
||||
} else {
|
||||
$activity->setLimit(false, false);
|
||||
}
|
||||
|
||||
$activity->setConfig(false);
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$activity->setHasLimit(false);
|
||||
$activity->setPrettyString(false);
|
||||
|
||||
$activity->getDownloadByBaseByDay($conf);
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_db_by_base_by_day');
|
||||
}
|
||||
|
||||
$report = $activity->getDownloadByBaseByDay($conf);
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($report['report']) ? $report['report'] : $report,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false,
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display report about pushed documents
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportPushedDocuments(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'user' => ['', 1, 0, 1, 1],
|
||||
'getter' => ["Destinataire", 1, 0, 1, 1],
|
||||
'date' => ['', 1, 0, 1, 1],
|
||||
'record_id' => ['', 1, 1, 1, 1],
|
||||
'file' => ['', 1, 0, 1, 1],
|
||||
'mime' => ['', 1, 0, 1, 1],
|
||||
];
|
||||
|
||||
$activity = new \module_report_push(
|
||||
$this->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);
|
||||
|
||||
$this->doReport($request, $activity, $conf);
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_pushed_documents');
|
||||
}
|
||||
|
||||
$report = $this->doReport($request, $activity, $conf);
|
||||
|
||||
if ($report instanceof Response) {
|
||||
return $report;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'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'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display report about added documents
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportAddedDocuments(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'user' => ['', 1, 0, 1, 1],
|
||||
'date' => ['', 1, 0, 1, 1],
|
||||
'record_id' => ['', 1, 1, 1, 1],
|
||||
'file' => ['', 1, 0, 1, 1],
|
||||
'mime' => ['', 1, 0, 1, 1],
|
||||
];
|
||||
|
||||
$activity = new \module_report_add(
|
||||
$this->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);
|
||||
|
||||
$this->doReport($request, $activity, $conf);
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_added_documents');
|
||||
}
|
||||
|
||||
$report = $this->doReport($request, $activity, $conf);
|
||||
|
||||
if ($report instanceof Response) {
|
||||
return $report;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'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'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display report about edited documents
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportEditedDocuments(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'user' => ['', 1, 0, 1, 1],
|
||||
'date' => ['', 1, 0, 1, 1],
|
||||
'record_id' => ['', 1, 1, 1, 1],
|
||||
'file' => ['', 1, 0, 1, 1],
|
||||
'mime' => ['', 1, 0, 1, 1],
|
||||
];
|
||||
|
||||
$activity = new \module_report_edit(
|
||||
$this->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);
|
||||
|
||||
$this->doReport($request, $activity, $conf);
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_edited_documents');
|
||||
}
|
||||
|
||||
$report = $this->doReport($request, $activity, $conf);
|
||||
|
||||
if ($report instanceof Response) {
|
||||
return $report;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'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'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display report about validated documents
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportValidatedDocuments(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'user' => ['', 1, 0, 1, 1],
|
||||
'getter' => ["Destinataire", 1, 0, 1, 1],
|
||||
'date' => ['', 1, 0, 1, 1],
|
||||
'record_id' => ['', 1, 1, 1, 1],
|
||||
'file' => ['', 1, 0, 1, 1],
|
||||
'mime' => ['', 1, 0, 1, 1],
|
||||
];
|
||||
|
||||
$activity = new \module_report_validate(
|
||||
$this->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);
|
||||
|
||||
$this->doReport($request, $activity, $conf);
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_validated_documents');
|
||||
}
|
||||
|
||||
$report = $this->doReport($request, $activity, $conf);
|
||||
|
||||
if ($report instanceof Response) {
|
||||
return $report;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'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'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display report about documents sent by mail
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportSentDocuments(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'user' => ['', 1, 0, 1, 1],
|
||||
'date' => ['', 1, 0, 1, 1],
|
||||
'record_id' => ['', 1, 1, 1, 1],
|
||||
'file' => ['', 1, 0, 1, 1],
|
||||
'mime' => ['', 1, 0, 1, 1],
|
||||
'comment' => [$this->app->trans('Receiver'), 1, 0, 1, 1],
|
||||
];
|
||||
|
||||
$activity = new \module_report_sent(
|
||||
$this->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);
|
||||
|
||||
$this->doReport($request, $activity, $conf);
|
||||
|
||||
return $this->getCSVResponse($activity, 'activity_send_documents');
|
||||
}
|
||||
|
||||
$report = $this->doReport($request, $activity, $conf);
|
||||
|
||||
if ($report instanceof Response) {
|
||||
return $report;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'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
|
||||
*
|
||||
* @param Request $request A request instance
|
||||
* @param \module_report $report A report instance
|
||||
* @param Array $conf A report column configuration
|
||||
* @param Boolean $what Whether to group on a particular field or not
|
||||
* @return Array
|
||||
*/
|
||||
private function doReport(Request $request, \module_report $report, $conf, $what = false)
|
||||
{
|
||||
if ($this->getConf()->get(['registry', 'modules', 'anonymous-report'])) {
|
||||
if (isset($conf['user'])) {
|
||||
unset($conf['user']);
|
||||
}
|
||||
|
||||
if (isset($conf['ip'])) {
|
||||
unset($conf['ip']);
|
||||
}
|
||||
}
|
||||
//save initial conf
|
||||
$base_conf = $conf;
|
||||
//format conf according user preferences
|
||||
if ('' !== $columnsList = $request->request->get('list_column', '')) {
|
||||
$new_conf = $conf;
|
||||
$columns = explode(",", $columnsList);
|
||||
|
||||
foreach (array_keys($conf) as $col) {
|
||||
if (!in_array($col, $columns)) {
|
||||
unset($new_conf[$col]);
|
||||
}
|
||||
}
|
||||
|
||||
$conf = $new_conf;
|
||||
}
|
||||
|
||||
//display content of a table column when user click on it
|
||||
if ($request->request->get('conf') == 'on') {
|
||||
return $this->app->json(['liste' => $this->render('report/listColumn.html.twig', [
|
||||
'conf' => $base_conf
|
||||
]), "title" => $this->app->trans("configuration")]);
|
||||
}
|
||||
|
||||
//set order
|
||||
if (('' !== $order = $request->request->get('order', '')) && ('' !== $field = $request->request->get('champ', ''))) {
|
||||
$report->setOrder($field, $order);
|
||||
}
|
||||
|
||||
//work on filters
|
||||
$mapColumnTitleToSqlField = $report->getTransQueryString();
|
||||
|
||||
$currentfilter = [];
|
||||
|
||||
if ('' !== $serializedFilter = $request->request->get('liste_filter', '')) {
|
||||
$currentfilter = @unserialize(urldecode($serializedFilter));
|
||||
}
|
||||
|
||||
$filter = new \module_report_filter($this->app, $currentfilter, $mapColumnTitleToSqlField);
|
||||
|
||||
if ('' !== $filterColumn = $request->request->get('filter_column', '')) {
|
||||
$field = current(explode(' ', $filterColumn));
|
||||
$value = $request->request->get('filter_value', '');
|
||||
|
||||
if ($request->request->get('liste') == 'on') {
|
||||
return $this->app->json(['diag' => $this->render('report/colFilter.html.twig', [
|
||||
'result' => $report->colFilter($field),
|
||||
'field' => $field
|
||||
]), "title" => $this->app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])]);
|
||||
}
|
||||
|
||||
if ($field === $value) {
|
||||
$filter->removeFilter($field);
|
||||
} else {
|
||||
$filter->addFilter($field, '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
//set new request filter if user asking for them
|
||||
if ($request->request->get('precise') == 1) {
|
||||
$filter->addFilter('xml', 'LIKE', $request->request->get('word', ''));
|
||||
} elseif ($request->request->get('precise') == 2) {
|
||||
$filter->addFilter('record_id', '=', $request->request->get('word', ''));
|
||||
}
|
||||
|
||||
//set filters to current report
|
||||
$report->setFilter($filter->getTabFilter());
|
||||
$report->setActiveColumn($filter->getActiveColumn());
|
||||
$report->setPostingFilter($filter->getPostingFilter());
|
||||
|
||||
// display a new arraywhere results are group
|
||||
if ('' !== $groupby = $request->request->get('groupby', '')) {
|
||||
$report->setConfig(false);
|
||||
$groupby = current(explode(' ', $groupby));
|
||||
|
||||
$reportArray = $report->buildReport(false, $groupby);
|
||||
|
||||
if (count($reportArray['allChamps']) > 0 && count($reportArray['display']) > 0) {
|
||||
$groupField = isset($reportArray['display'][$reportArray['allChamps'][0]]['title']) ? $reportArray['display'][$reportArray['allChamps'][0]]['title'] : '';
|
||||
} else {
|
||||
$groupField = isset($conf[strtolower($groupby)]['title']) ? $conf[strtolower($groupby)]['title'] : '';
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => true,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false,
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => $this->app->trans('Groupement des resultats sur le champ %name%', ['%name%' => $groupField]),
|
||||
]);
|
||||
}
|
||||
|
||||
//set Limit
|
||||
if ($report->getEnableLimit()
|
||||
&& ('' !== $page = $request->request->get('page', ''))
|
||||
&& ('' !== $limit = $request->request->get('limit', ''))) {
|
||||
$report->setLimit($page, $limit);
|
||||
} else {
|
||||
$report->setLimit(false, false);
|
||||
}
|
||||
|
||||
//time to build our report
|
||||
if (false === $what) {
|
||||
$reportArray = $report->buildReport($conf);
|
||||
} else {
|
||||
$reportArray = $report->buildReport($conf, $what, $request->request->get('tbl', false));
|
||||
}
|
||||
|
||||
return $reportArray;
|
||||
}
|
||||
|
||||
private function getCSVResponse(\module_report $report, $type)
|
||||
{
|
||||
// set headers
|
||||
$headers = [];
|
||||
foreach (array_keys($report->getDisplay()) as $k) {
|
||||
$headers[$k] = $k;
|
||||
}
|
||||
// set headers as first row
|
||||
$result = $report->getResult();
|
||||
array_unshift($result, $headers);
|
||||
|
||||
$collection = new CallbackCollection($result, function ($row) use ($report) {
|
||||
// restrict to displayed fields
|
||||
return array_map('strip_tags', array_intersect_key($row, $report->getDisplay()));
|
||||
});
|
||||
|
||||
$filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
|
||||
/** @var Exporter $exporter */
|
||||
$exporter = $this->app['csv.exporter'];
|
||||
$response = new CSVFileResponse($filename, function () use ($exporter, $collection) {
|
||||
$exporter->export('php://output', $collection);
|
||||
});
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@@ -1,502 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Alchemy\Phrasea\Controller\Report;
|
||||
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Core\Response\CSVFileResponse;
|
||||
use Goodby\CSV\Export\Standard\Collection\CallbackCollection;
|
||||
use Goodby\CSV\Export\Standard\Exporter;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class InformationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display information about a user
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportInformationUser(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'config' => [
|
||||
'photo' => [$this->app->trans('report:: document'), 0, 0, 0, 0],
|
||||
'record_id' => [$this->app->trans('report:: record id'), 0, 0, 0, 0],
|
||||
'date' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
|
||||
'type' => [$this->app->trans('phrseanet:: sous definition'), 0, 0, 0, 0],
|
||||
'titre' => [$this->app->trans('report:: titre'), 0, 0, 0, 0],
|
||||
'taille' => [$this->app->trans('report:: poids'), 0, 0, 0, 0]
|
||||
],
|
||||
'conf' => [
|
||||
'identifiant' => [$this->app->trans('report:: identifiant'), 0, 0, 0, 0],
|
||||
'nom' => [$this->app->trans('report:: nom'), 0, 0, 0, 0],
|
||||
'mail' => [$this->app->trans('report:: email'), 0, 0, 0, 0],
|
||||
'adresse' => [$this->app->trans('report:: adresse'), 0, 0, 0, 0],
|
||||
'tel' => [$this->app->trans('report:: telephone'), 0, 0, 0, 0]
|
||||
],
|
||||
'config_cnx' => [
|
||||
'ddate' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
|
||||
'appli' => [$this->app->trans('report:: modules'), 0, 0, 0, 0],
|
||||
],
|
||||
'config_dl' => [
|
||||
'ddate' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
|
||||
'record_id' => [$this->app->trans('report:: record id'), 0, 1, 0, 0],
|
||||
'final' => [$this->app->trans('phrseanet:: sous definition'), 0, 0, 0, 0],
|
||||
'coll_id' => [$this->app->trans('report:: collections'), 0, 0, 0, 0],
|
||||
'comment' => [$this->app->trans('report:: commentaire'), 0, 0, 0, 0],
|
||||
],
|
||||
'config_ask' => [
|
||||
'search' => [$this->app->trans('report:: question'), 0, 0, 0, 0],
|
||||
'ddate' => [$this->app->trans('report:: date'), 0, 0, 0, 0]
|
||||
]
|
||||
];
|
||||
|
||||
$report = null;
|
||||
$html = $html_info = '';
|
||||
$from = $request->request->get('from', '');
|
||||
$on = $request->request->get('on', '');
|
||||
$selectValue = $request->request->get('user', '');
|
||||
|
||||
if ('' === $selectValue) {
|
||||
$this->app->abort(400);
|
||||
}
|
||||
|
||||
if ('' !== $on && $this->getConf()->get(['registry', 'modules', 'anonymous-report']) == true) {
|
||||
$conf['conf'] = [
|
||||
$on => [$on, 0, 0, 0, 0],
|
||||
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0]
|
||||
];
|
||||
}
|
||||
|
||||
if ($from == 'CNXU' || $from == 'CNX') {
|
||||
$report = new \module_report_connexion(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
$conf_array = $conf['config_cnx'];
|
||||
$title = $this->app->trans('report:: historique des connexions');
|
||||
} elseif ($from == 'USR' || $from == 'GEN') {
|
||||
$report = new \module_report_download(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
$conf_array = $conf['config_dl'];
|
||||
$title = $this->app->trans('report:: historique des telechargements');
|
||||
} elseif ($from == 'ASK') {
|
||||
$report = new \module_report_question(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
$conf_array = $conf['config_ask'];
|
||||
$title = $this->app->trans('report:: historique des questions');
|
||||
}
|
||||
|
||||
if ($report) {
|
||||
$mapColumnTitleToSqlField = $report->getTransQueryString();
|
||||
|
||||
$currentfilter = [];
|
||||
|
||||
if ('' !== $serializedFilter = $request->request->get('liste_filter', '')) {
|
||||
$currentfilter = @unserialize(urldecode($serializedFilter));
|
||||
}
|
||||
|
||||
$filter = new \module_report_filter($this->app, $currentfilter, $mapColumnTitleToSqlField);
|
||||
|
||||
if ('' !== $filterColumn = $request->request->get('filter_column', '')) {
|
||||
$field = current(explode(' ', $filterColumn));
|
||||
$value = $request->request->get('filter_value', '');
|
||||
|
||||
if ($request->request->get('liste') == 'on') {
|
||||
return $this->app->json([
|
||||
'diag' => $this->render('report/colFilter.html.twig', [
|
||||
'result' => $report->colFilter($field),
|
||||
'field' => $field
|
||||
]),
|
||||
'title' => $this->app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])]);
|
||||
}
|
||||
|
||||
if ($field === $value) {
|
||||
$filter->removeFilter($field);
|
||||
} else {
|
||||
$filter->addFilter($field, '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
if ('' !== $selectValue && '' !== $from) {
|
||||
$filter->addfilter('usrid', '=', $selectValue);
|
||||
} elseif ('' !== $on && '' !== $selectValue) {
|
||||
$filter->addfilter($on, '=', $selectValue);
|
||||
}
|
||||
|
||||
if ($report instanceof \module_report_download) {
|
||||
$report->setIsInformative(true);
|
||||
}
|
||||
|
||||
$report->setFilter($filter->getTabFilter());
|
||||
$report->setOrder('ddate', 'DESC');
|
||||
$report->setConfig(false);
|
||||
$report->setTitle($title);
|
||||
$report->setHasLimit(false);
|
||||
|
||||
$reportArray = $report->buildReport($conf_array);
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$report->setPrettyString(false);
|
||||
|
||||
return $this->getCSVResponse($report, 'info_user');
|
||||
}
|
||||
|
||||
$html = $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
|
||||
'is_infouser' => $report instanceof \module_report_download,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]);
|
||||
}
|
||||
|
||||
$info = new \module_report_nav(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$info->setPeriode('');
|
||||
$info->setCsv(false);
|
||||
|
||||
$infoArray = $info->buildTabGrpInfo(
|
||||
null !== $report ? $report->getReq() : '',
|
||||
null !== $report ? $report->getParams() : [],
|
||||
$selectValue,
|
||||
$conf['conf'],
|
||||
$on
|
||||
);
|
||||
|
||||
if (false == $this->app['conf']->get(['registry', 'modules', 'anonymous-report'])) {
|
||||
$html_info = $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($infoArray['report']) ? $infoArray['report'] : $infoArray,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]);
|
||||
|
||||
$title = ('' === $on && isset($infoArray['result'])) ? $infoArray['result'][0]['identifiant'] : $selectValue;
|
||||
} else {
|
||||
$title = $selectValue;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => sprintf('%s%s', $html_info, $html),
|
||||
'display_nav' => false,
|
||||
'title' => $title
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a browser version
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportInformationBrowser(Request $request)
|
||||
{
|
||||
$conf = [
|
||||
'version' => [$this->app->trans('report::version'), 0, 0, 0, 0],
|
||||
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
$info = new \module_report_nav(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$info->setCsv(false);
|
||||
$info->setConfig(false);
|
||||
|
||||
if ('' === $browser = $request->request->get('user', '')) {
|
||||
$this->app->abort(400);
|
||||
}
|
||||
|
||||
$reportArray = $info->buildTabInfoNav($conf, $browser);
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => $browser
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display information about a document
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportInformationDocument(Request $request)
|
||||
{
|
||||
$config = [
|
||||
'photo' => [$this->app->trans('report:: document'), 0, 0, 0, 0],
|
||||
'record_id' => [$this->app->trans('report:: record id'), 0, 0, 0, 0],
|
||||
'date' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
|
||||
'type' => [$this->app->trans('phrseanet:: sous definition'), 0, 0, 0, 0],
|
||||
'titre' => [$this->app->trans('report:: titre'), 0, 0, 0, 0],
|
||||
'taille' => [$this->app->trans('report:: poids'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
$config_dl = [
|
||||
'ddate' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
|
||||
'user' => [$this->app->trans('report:: utilisateurs'), 0, 0, 0, 0],
|
||||
'final' => [$this->app->trans('phrseanet:: sous definition'), 0, 0, 0, 0],
|
||||
'coll_id' => [$this->app->trans('report:: collections'), 0, 0, 0, 0],
|
||||
'comment' => [$this->app->trans('report:: commentaire'), 0, 0, 0, 0],
|
||||
'fonction' => [$this->app->trans('report:: fonction'), 0, 0, 0, 0],
|
||||
'activite' => [$this->app->trans('report:: activite'), 0, 0, 0, 0],
|
||||
'pays' => [$this->app->trans('report:: pays'), 0, 0, 0, 0],
|
||||
'societe' => [$this->app->trans('report:: societe'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
//format conf according user preferences
|
||||
if ('' !== $columnsList = $request->request->get('list_column', '')) {
|
||||
$new_conf = $config_dl;
|
||||
$columns = explode(',', $columnsList);
|
||||
|
||||
foreach (array_keys($config_dl) as $col) {
|
||||
if (!in_array($col, $columns)) {
|
||||
unset($new_conf[$col]);
|
||||
}
|
||||
}
|
||||
|
||||
$config_dl = $new_conf;
|
||||
}
|
||||
|
||||
try {
|
||||
$record = new \record_adapter(
|
||||
$this->app,
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('rid')
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->app->abort(404);
|
||||
}
|
||||
|
||||
$what = new \module_report_nav(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$what->setPeriode('');
|
||||
$what->setCsv(false);
|
||||
$what->setPrint(false);
|
||||
|
||||
/** @var \record_adapter $record */
|
||||
$reportArray = $what->buildTabUserWhat(
|
||||
$record->getBaseId(),
|
||||
$record->getRecordId(),
|
||||
$config
|
||||
);
|
||||
|
||||
$title = $what->getTitle();
|
||||
|
||||
$html = $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]);
|
||||
|
||||
$from = $request->request->get('from', '');
|
||||
|
||||
if ('TOOL' === $from) {
|
||||
$what->setTitle('');
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $html,
|
||||
'display_nav' => false,
|
||||
'title' => $title
|
||||
]);
|
||||
}
|
||||
|
||||
if ('DASH' !== $from && 'PUSHDOC' !== $from) {
|
||||
$download = new \module_report_download(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$mapColumnTitleToSqlField = $download->getTransQueryString();
|
||||
|
||||
$currentfilter = [];
|
||||
|
||||
if ('' !== $serializedFilter = $request->request->get('liste_filter', '')) {
|
||||
$currentfilter = @unserialize(urldecode($serializedFilter));
|
||||
}
|
||||
|
||||
$filter = new \module_report_filter($this->app, $currentfilter, $mapColumnTitleToSqlField);
|
||||
|
||||
if ('' !== $filterColumn = $request->request->get('filter_column', '')) {
|
||||
$field = current(explode(' ', $filterColumn));
|
||||
$value = $request->request->get('filter_value', '');
|
||||
|
||||
if ($request->request->get('liste') == 'on') {
|
||||
return $this->app->json([
|
||||
'diag' => $this->render('report/colFilter.html.twig', [
|
||||
'result' => $download->colFilter($field),
|
||||
'field' => $field
|
||||
]),
|
||||
'title' => $this->app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])
|
||||
]);
|
||||
}
|
||||
|
||||
if ($field === $value) {
|
||||
$filter->removeFilter($field);
|
||||
} else {
|
||||
$filter->addFilter($field, '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
$filter->addfilter('record_id', '=', $record->getRecordId());
|
||||
|
||||
$download->setFilter($filter->getTabFilter());
|
||||
$download->setOrder('ddate', 'DESC');
|
||||
$download->setTitle($this->app->trans('report:: historique des telechargements'));
|
||||
$download->setConfig(false);
|
||||
|
||||
$reportArray = $download->buildReport($config_dl);
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$download->setPrettyString(false);
|
||||
|
||||
return $this->getCSVResponse($download, 'info_document');
|
||||
}
|
||||
|
||||
$html .= $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]);
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $html,
|
||||
'display_nav' => false,
|
||||
'title' => $title
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->getConf()->get(['registry', 'modules', 'anonymous-report']) == false && $from !== 'DOC' && $from !== 'DASH' && $from !== 'GEN' && $from !== 'PUSHDOC') {
|
||||
$conf = [
|
||||
'identifiant' => [$this->app->trans('report:: identifiant'), 0, 0, 0, 0],
|
||||
'nom' => [$this->app->trans('report:: nom'), 0, 0, 0, 0],
|
||||
'mail' => [$this->app->trans('report:: email'), 0, 0, 0, 0],
|
||||
'adresse' => [$this->app->trans('report:: adresse'), 0, 0, 0, 0],
|
||||
'tel' => [$this->app->trans('report:: telephone'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
$info = new \module_report_nav(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$info->setPeriode('');
|
||||
$info->setConfig(false);
|
||||
$info->setTitle($this->app->trans('report:: utilisateur'));
|
||||
|
||||
$reportArray = $info->buildTabGrpInfo(false, [], $request->request->get('user'), $conf, false);
|
||||
|
||||
if ($request->request->get('printcsv') == 'on' && isset($download)) {
|
||||
return $this->getCSVResponse($this->app, $info, 'info_user');
|
||||
}
|
||||
|
||||
$html .= $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]);
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $html,
|
||||
'display_nav' => false,
|
||||
'title' => $title
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $html,
|
||||
'display_nav' => false,
|
||||
'title' => $title
|
||||
]);
|
||||
}
|
||||
|
||||
private function getCSVResponse(\module_report $report, $type)
|
||||
{
|
||||
// set headers
|
||||
$headers = [];
|
||||
foreach (array_keys($report->getDisplay()) as $k) {
|
||||
$headers[$k] = $k;
|
||||
}
|
||||
// set headers as first row
|
||||
$result = $report->getResult();
|
||||
array_unshift($result, $headers);
|
||||
|
||||
$collection = new CallbackCollection($result, function ($row) use ($report) {
|
||||
// restrict fields to the displayed ones
|
||||
return array_map('strip_tags', array_intersect_key($row, $report->getDisplay()));
|
||||
});
|
||||
|
||||
/** @var Exporter $exporter */
|
||||
$exporter = $this->app['csv.exporter'];
|
||||
$filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
|
||||
$response = new CSVFileResponse($filename, function () use ($exporter, $collection) {
|
||||
$exporter->export('php://output', $collection);
|
||||
});
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@@ -10,12 +10,8 @@
|
||||
namespace Alchemy\Phrasea\Controller\Report;
|
||||
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Core\Response\CSVFileResponse;
|
||||
use Goodby\CSV\Export\Standard\Collection\CallbackCollection;
|
||||
use Goodby\CSV\Export\Standard\Exporter;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RootController extends Controller
|
||||
{
|
||||
@@ -53,22 +49,34 @@ class RootController extends Controller
|
||||
|
||||
$granted = [];
|
||||
|
||||
foreach ($this->getAclForUser()->get_granted_base([\ACL::CANREPORT]) as $collection) {
|
||||
if (!isset($granted[$collection->get_sbas_id()])) {
|
||||
$granted[$collection->get_sbas_id()] = [
|
||||
'id' => $collection->get_sbas_id(),
|
||||
'name' => $collection->get_databox()->get_viewname(),
|
||||
'collections' => []
|
||||
$acl = $this->getAclForUser();
|
||||
foreach ($acl->get_granted_base([\ACL::CANREPORT]) as $collection) {
|
||||
$sbas_id = $collection->get_sbas_id();
|
||||
if (!isset($granted[$sbas_id])) {
|
||||
$granted[$sbas_id] = [
|
||||
'id' => $sbas_id,
|
||||
'name' => $collection->get_databox()->get_viewname(),
|
||||
'collections' => [],
|
||||
'metas' => []
|
||||
];
|
||||
|
||||
foreach ($collection->get_databox()->get_meta_structure() as $meta) {
|
||||
// skip the fields that can't be reported
|
||||
if (!$meta->is_report() || ($meta->isBusiness() && !$acl->can_see_business_fields($collection->get_databox()))) {
|
||||
continue;
|
||||
}
|
||||
$granted[$sbas_id]['metas'][] = $meta->get_name();
|
||||
}
|
||||
}
|
||||
$granted[$collection->get_sbas_id()]['collections'][] = [
|
||||
'id' => $collection->get_coll_id(),
|
||||
$granted[$sbas_id]['collections'][] = [
|
||||
'id' => $collection->get_coll_id(),
|
||||
'base_id' => $collection->get_base_id(),
|
||||
'name' => $collection->get_name()
|
||||
'name' => $collection->get_name(),
|
||||
];
|
||||
}
|
||||
|
||||
$conf = $this->getConf();
|
||||
|
||||
return $this->render('report/report_layout_child.html.twig', [
|
||||
'ajax_dash' => true,
|
||||
'dashboard' => null,
|
||||
@@ -82,594 +90,4 @@ class RootController extends Controller
|
||||
'ajax_chart' => false
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets available collections where current user can see report and
|
||||
* format date
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function initReport(Request $request)
|
||||
{
|
||||
$popbases = $request->request->get('popbases', []);
|
||||
|
||||
if ('' === $dmin = $request->request->get('dmin', '')) {
|
||||
$dmin = date('Y') . '-' . date('m') . '-01';
|
||||
}
|
||||
|
||||
if ('' === $dmax = $request->request->get('dmax', '')) {
|
||||
$dmax = date('Y') . '-' . date('m') . '-' . date('d');
|
||||
}
|
||||
|
||||
$dmin = \DateTime::createFromFormat('Y-m-d H:i:s', sprintf('%s 00:00:00', $dmin));
|
||||
$dmax = \DateTime::createFromFormat('Y-m-d H:i:s', sprintf('%s 23:59:59', $dmax));
|
||||
|
||||
//get user's sbas & collections selection from popbases
|
||||
$selection = [];
|
||||
$liste = $id_sbas = '';
|
||||
$i = 0;
|
||||
foreach (array_fill_keys($popbases, 0) as $key => $val) {
|
||||
$exp = explode('_', $key);
|
||||
if ($exp[0] != $id_sbas && $i != 0) {
|
||||
$selection[$id_sbas]['liste'] = $liste;
|
||||
$liste = '';
|
||||
}
|
||||
$selection[$exp[0]][] = $exp[1];
|
||||
$liste .= (empty($liste) ? '' : ',') . $exp[1];
|
||||
$id_sbas = $exp[0];
|
||||
$i ++;
|
||||
}
|
||||
//fill the last entry
|
||||
$selection[$id_sbas]['liste'] = $liste;
|
||||
|
||||
return $this->render('report/ajax_report_content.html.twig', [
|
||||
'selection' => $selection,
|
||||
'anonymous' => $this->getConf()->get(['registry', 'modules', 'anonymous-report']),
|
||||
'ajax' => true,
|
||||
'dmin' => $dmin->format('Y-m-d H:i:s'),
|
||||
'dmax' => $dmax->format('Y-m-d H:i:s'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display instance connexion report
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportConnexions(Request $request)
|
||||
{
|
||||
$cnx = new \module_report_connexion(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$conf = [
|
||||
'user' => [$this->app->trans('phraseanet::utilisateurs'), 1, 1, 1, 1],
|
||||
'ddate' => [$this->app->trans('report:: date'), 1, 0, 1, 1],
|
||||
'ip' => [$this->app->trans('report:: IP'), 1, 0, 0, 0],
|
||||
'appli' => [$this->app->trans('report:: modules'), 1, 0, 0, 0],
|
||||
'fonction' => [$this->app->trans('report::fonction'), 1, 1, 1, 1],
|
||||
'activite' => [$this->app->trans('report::activite'), 1, 1, 1, 1],
|
||||
'pays' => [$this->app->trans('report::pays'), 1, 1, 1, 1],
|
||||
'societe' => [$this->app->trans('report::societe'), 1, 1, 1, 1]
|
||||
];
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$cnx->setHasLimit(false);
|
||||
$cnx->setPrettyString(false);
|
||||
|
||||
$this->doReport($request, $cnx, $conf);
|
||||
|
||||
return $this->getCSVResponse($cnx, 'connections');
|
||||
}
|
||||
|
||||
$report = $this->doReport($request, $cnx, $conf);
|
||||
|
||||
if ($report instanceof Response) {
|
||||
return $report;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'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']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display instance questions report
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportQuestions(Request $request)
|
||||
{
|
||||
$questions = new \module_report_question(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$conf = [
|
||||
'user' => [$this->app->trans('report:: utilisateur'), 1, 1, 1, 1],
|
||||
'search' => [$this->app->trans('report:: question'), 1, 0, 1, 1],
|
||||
'ddate' => [$this->app->trans('report:: date'), 1, 0, 1, 1],
|
||||
'fonction' => [$this->app->trans('report:: fonction'), 1, 1, 1, 1],
|
||||
'activite' => [$this->app->trans('report:: activite'), 1, 1, 1, 1],
|
||||
'pays' => [$this->app->trans('report:: pays'), 1, 1, 1, 1],
|
||||
'societe' => [$this->app->trans('report:: societe'), 1, 1, 1, 1]
|
||||
];
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$questions->setHasLimit(false);
|
||||
$questions->setPrettyString(false);
|
||||
|
||||
$this->doReport($request, $questions, $conf);
|
||||
|
||||
return $this->getCSVResponse($questions, 'questions');
|
||||
}
|
||||
|
||||
$report = $this->doReport($request, $questions, $conf);
|
||||
|
||||
if ($report instanceof Response) {
|
||||
return $report;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'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']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display instance download report
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportDownloads(Request $request)
|
||||
{
|
||||
$download = new \module_report_download(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$conf_pref = [];
|
||||
|
||||
foreach (\module_report::getPreff($this->app, $request->request->get('sbasid')) as $field) {
|
||||
$conf_pref[strtolower($field)] = [$field, 0, 0, 0, 0];
|
||||
}
|
||||
|
||||
$conf = array_merge([
|
||||
'user' => [$this->app->trans('report:: utilisateurs'), 1, 1, 1, 1],
|
||||
'ddate' => [$this->app->trans('report:: date'), 1, 0, 1, 1],
|
||||
'record_id' => [$this->app->trans('report:: record id'), 1, 1, 1, 1],
|
||||
'final' => [$this->app->trans('phrseanet:: sous definition'), 1, 0, 1, 1],
|
||||
'coll_id' => [$this->app->trans('report:: collections'), 1, 0, 1, 1],
|
||||
'comment' => [$this->app->trans('report:: commentaire'), 1, 0, 0, 0],
|
||||
'fonction' => [$this->app->trans('report:: fonction'), 1, 1, 1, 1],
|
||||
'activite' => [$this->app->trans('report:: activite'), 1, 1, 1, 1],
|
||||
'pays' => [$this->app->trans('report:: pays'), 1, 1, 1, 1],
|
||||
'societe' => [$this->app->trans('report:: societe'), 1, 1, 1, 1]
|
||||
], $conf_pref);
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$download->setHasLimit(false);
|
||||
$download->setPrettyString(false);
|
||||
|
||||
$this->doReport($request, $download, $conf);
|
||||
|
||||
$r = $this->getCSVResponse($download, 'download');
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
$report = $this->doReport($request, $download, $conf);
|
||||
|
||||
if ($report instanceof Response) {
|
||||
return $report;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'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']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display instance document report
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportDocuments(Request $request)
|
||||
{
|
||||
$document = new \module_report_download(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$conf_pref = [];
|
||||
|
||||
foreach (\module_report::getPreff($this->app, $request->request->get('sbasid')) as $field) {
|
||||
$conf_pref[$field] = array($field, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
$conf = array_merge([
|
||||
'telechargement' => [$this->app->trans('report:: telechargements'), 1, 0, 0, 0],
|
||||
'record_id' => [$this->app->trans('report:: record id'), 1, 1, 1, 0],
|
||||
'final' => [$this->app->trans('phraseanet:: sous definition'), 1, 0, 1, 1],
|
||||
'file' => [$this->app->trans('report:: fichier'), 1, 0, 0, 1],
|
||||
'mime' => [$this->app->trans('report:: type'), 1, 0, 1, 1],
|
||||
'size' => [$this->app->trans('report:: taille'), 1, 0, 1, 1]
|
||||
], $conf_pref);
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$document->setHasLimit(false);
|
||||
$document->setPrettyString(false);
|
||||
|
||||
$this->doReport($request, $document, $conf, 'record_id');
|
||||
|
||||
$r = $this->getCSVResponse($document, 'documents');
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
$report = $this->doReport($request, $document, $conf, 'record_id');
|
||||
|
||||
if ($report instanceof Response) {
|
||||
return $report;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($report['report']) ? $report['report'] : $report,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => true
|
||||
]),
|
||||
'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']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display information about client (browser, resolution etc ...)
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function doReportClients(Request $request)
|
||||
{
|
||||
$nav = new \module_report_nav(
|
||||
$this->app,
|
||||
$request->request->get('dmin'),
|
||||
$request->request->get('dmax'),
|
||||
$request->request->get('sbasid'),
|
||||
$request->request->get('collection')
|
||||
);
|
||||
|
||||
$conf_nav = [
|
||||
'nav' => [$this->app->trans('report:: navigateur'), 0, 1, 0, 0],
|
||||
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
|
||||
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
$conf_combo = [
|
||||
'combo' => [$this->app->trans('report:: navigateurs et plateforme'), 0, 0, 0, 0],
|
||||
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
|
||||
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
|
||||
];
|
||||
$conf_os = [
|
||||
'os' => [$this->app->trans('report:: plateforme'), 0, 0, 0, 0],
|
||||
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
|
||||
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
|
||||
];
|
||||
$conf_res = [
|
||||
'res' => [$this->app->trans('report:: resolution'), 0, 0, 0, 0],
|
||||
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
|
||||
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
|
||||
];
|
||||
$conf_mod = [
|
||||
'appli' => [$this->app->trans('report:: module'), 0, 0, 0, 0],
|
||||
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
|
||||
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
$report = [
|
||||
'nav' => $nav->buildTabNav($conf_nav),
|
||||
'os' => $nav->buildTabOs($conf_os),
|
||||
'res' => $nav->buildTabRes($conf_res),
|
||||
'mod' => $nav->buildTabModule($conf_mod),
|
||||
'combo' => $nav->buildTabCombo($conf_combo)
|
||||
];
|
||||
|
||||
if ($request->request->get('printcsv') == 'on') {
|
||||
$result = [];
|
||||
|
||||
$result[] = array_keys($conf_nav);
|
||||
foreach ($report['nav']['result'] as $row) {
|
||||
$result[] = array_values($row);
|
||||
};
|
||||
$result[] = array_keys($conf_os);
|
||||
foreach ($report['os']['result'] as $row) {
|
||||
$result[] = array_values($row);
|
||||
};
|
||||
$result[] = array_keys($conf_res);
|
||||
foreach ($report['res']['result'] as $row) {
|
||||
$result[] = array_values($row);
|
||||
};
|
||||
$result[] = array_keys($conf_mod);
|
||||
foreach ($report['mod']['result'] as $row) {
|
||||
$result[] = array_values($row);
|
||||
};
|
||||
$result[] = array_keys($conf_combo);
|
||||
foreach ($report['combo']['result'] as $row) {
|
||||
$result[] = array_values($row);
|
||||
};
|
||||
|
||||
/** @var Exporter $exporter */
|
||||
$exporter = $this->app['csv.exporter'];
|
||||
$filename = sprintf('report_export_info_%s.csv', date('Ymd'));
|
||||
$response = new CSVFileResponse($filename, function () use ($exporter, $result) {
|
||||
$exporter->export('php://output', $result);
|
||||
});
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($report['report']) ? $report['report'] : $report,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => true,
|
||||
'is_groupby' => false,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => false
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Report configuration according to request parameters
|
||||
*
|
||||
* @param Request $request A request instance
|
||||
* @param \module_report $report A report instance
|
||||
* @param Array $conf A report column configuration
|
||||
* @param Boolean $what Whether to group on a particular field or not
|
||||
* @return Array
|
||||
*/
|
||||
private function doReport(Request $request, \module_report $report, $conf, $what = false)
|
||||
{
|
||||
if ($this->getConf()->get(['registry', 'modules', 'anonymous-report']) == true) {
|
||||
if (isset($conf['user'])) {
|
||||
unset($conf['user']);
|
||||
}
|
||||
|
||||
if (isset($conf['ip'])) {
|
||||
unset($conf['ip']);
|
||||
}
|
||||
}
|
||||
|
||||
//save initial conf
|
||||
$base_conf = $conf;
|
||||
//format conf according user preferences
|
||||
if ('' !== $columnsList = $request->request->get('list_column', '')) {
|
||||
$new_conf = $conf;
|
||||
$columns = explode(',', $columnsList);
|
||||
|
||||
foreach (array_keys($conf) as $col) {
|
||||
if (!in_array($col, $columns)) {
|
||||
unset($new_conf[$col]);
|
||||
}
|
||||
}
|
||||
|
||||
$conf = $new_conf;
|
||||
}
|
||||
|
||||
//display content of a table column when user click on it
|
||||
if ($request->request->get('conf') == 'on') {
|
||||
return $this->app->json(['liste' => $this->render('report/listColumn.html.twig', [
|
||||
'conf' => $base_conf
|
||||
]), 'title' => $this->app->trans('configuration')]);
|
||||
}
|
||||
|
||||
//set order
|
||||
if (('' !== $order = $request->request->get('order', '')) && ('' !== $field = $request->request->get('champ', ''))) {
|
||||
$report->setOrder($field, $order);
|
||||
}
|
||||
|
||||
//work on filters
|
||||
$mapColumnTitleToSqlField = $report->getTransQueryString();
|
||||
|
||||
$currentfilter = [];
|
||||
|
||||
if ('' !== $serializedFilter = $request->request->get('liste_filter', '')) {
|
||||
$currentfilter = @unserialize(urldecode($serializedFilter));
|
||||
}
|
||||
|
||||
$filter = new \module_report_filter($this->app, $currentfilter, $mapColumnTitleToSqlField);
|
||||
|
||||
if ('' !== $filterColumn = $request->request->get('filter_column', '')) {
|
||||
$field = current(explode(' ', $filterColumn));
|
||||
$value = $request->request->get('filter_value', '');
|
||||
|
||||
if ($request->request->get('liste') == 'on') {
|
||||
return $this->app->json(['diag' => $this->render('report/colFilter.html.twig', [
|
||||
'result' => $report->colFilter($field),
|
||||
'field' => $field
|
||||
]), 'title' => $this->app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])]);
|
||||
}
|
||||
|
||||
if ($field === $value) {
|
||||
$filter->removeFilter($field);
|
||||
} else {
|
||||
$filter->addFilter($field, '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
//set new request filter if user asking for them
|
||||
if ($request->request->get('precise') == 1) {
|
||||
$filter->addFilter('xml', 'LIKE', $request->request->get('word', ''));
|
||||
} elseif ($request->request->get('precise') == 2) {
|
||||
$filter->addFilter('record_id', '=', $request->request->get('word', ''));
|
||||
}
|
||||
|
||||
//set filters to current report
|
||||
$report->setFilter($filter->getTabFilter());
|
||||
$report->setActiveColumn($filter->getActiveColumn());
|
||||
$report->setPostingFilter($filter->getPostingFilter());
|
||||
|
||||
// display a new arraywhere results are group
|
||||
if ('' !== $groupby = $request->request->get('groupby', '')) {
|
||||
|
||||
$report->setConfig(false);
|
||||
$groupby = current(explode(' ', $groupby));
|
||||
|
||||
$reportArray = $report->buildReport(false, $groupby);
|
||||
|
||||
if (count($reportArray['allChamps']) > 0 && count($reportArray['display']) > 0) {
|
||||
$groupField = isset($reportArray['display'][$reportArray['allChamps'][0]]['title']) ? $reportArray['display'][$reportArray['allChamps'][0]]['title'] : '';
|
||||
} else {
|
||||
$groupField = isset($conf[strtolower($groupby)]['title']) ? $conf[strtolower($groupby)]['title'] : '';
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
'rs' => $this->render('report/ajax_data_content.html.twig', [
|
||||
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
|
||||
'is_infouser' => false,
|
||||
'is_nav' => false,
|
||||
'is_groupby' => true,
|
||||
'is_plot' => false,
|
||||
'is_doc' => false
|
||||
]),
|
||||
'display_nav' => false,
|
||||
'title' => $this->app->trans('Groupement des resultats sur le champ %name%', ['%name%' => $groupField])
|
||||
]);
|
||||
}
|
||||
|
||||
//set Limit
|
||||
if ($report->getEnableLimit()
|
||||
&& ('' !== $page = $request->request->get('page', ''))
|
||||
&& ('' !== $limit = $request->request->get('limit', ''))) {
|
||||
$report->setLimit($page, $limit);
|
||||
} else {
|
||||
$report->setLimit(false, false);
|
||||
}
|
||||
|
||||
//time to build our report
|
||||
if (false === $what) {
|
||||
$reportArray = $report->buildReport($conf);
|
||||
} else {
|
||||
$reportArray = $report->buildReport($conf, $what, $request->request->get('tbl', false));
|
||||
}
|
||||
|
||||
return $reportArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefix the method to call with the controller class name
|
||||
*
|
||||
* @param string $method The method to call
|
||||
* @return string
|
||||
*/
|
||||
private function call($method)
|
||||
{
|
||||
return sprintf('%s::%s', __CLASS__, $method);
|
||||
}
|
||||
|
||||
private function getCSVResponse(\module_report $report, $type)
|
||||
{
|
||||
// set headers
|
||||
$headers = [];
|
||||
foreach (array_keys($report->getDisplay()) as $k) {
|
||||
$headers[$k] = $k;
|
||||
}
|
||||
// set headers as first row
|
||||
$result = $report->getResult();
|
||||
|
||||
array_unshift($result, $headers);
|
||||
|
||||
$collection = new CallbackCollection($result, function ($row) use ($headers) {
|
||||
// restrict fields to the displayed ones
|
||||
// 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'));
|
||||
|
||||
/** @var Exporter $exporter */
|
||||
$exporter = $this->app['csv.exporter'];
|
||||
$cb = function () use ($exporter, $collection) {
|
||||
$exporter->export('php://output', $collection);
|
||||
};
|
||||
|
||||
$response = new CSVFileResponse($filename, $cb);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@@ -88,8 +88,6 @@ class ControllerProviderServiceProvider implements ServiceProviderInterface
|
||||
Prod\Upload::class => [],
|
||||
Prod\UsrLists::class => [],
|
||||
Prod\WorkZone::class => [],
|
||||
Report\Activity::class => [],
|
||||
Report\Information::class => [],
|
||||
Report\Root::class => [],
|
||||
Root\Account::class => [],
|
||||
Root\Developers::class => [],
|
||||
|
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\ControllerProvider\Report;
|
||||
|
||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||
use Alchemy\Phrasea\Controller\Report\ActivityController;
|
||||
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ServiceProviderInterface;
|
||||
|
||||
class Activity implements ControllerProviderInterface, ServiceProviderInterface
|
||||
{
|
||||
use ControllerProviderTrait;
|
||||
|
||||
public function register(Application $app)
|
||||
{
|
||||
$app['controller.report.activity'] = $app->share(function (PhraseaApplication $app) {
|
||||
return new ActivityController($app);
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(Application $app)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = $this->createAuthenticatedCollection($app);
|
||||
$firewall = $this->getFirewall($app);
|
||||
|
||||
$controllers->before(function () use ($firewall) {
|
||||
$firewall->requireAccessToModule('report');
|
||||
});
|
||||
|
||||
$controllers->post('/users/connexions', 'controller.report.activity:doReportConnexionsByUsers')
|
||||
->bind('report_activity_users_connexions');
|
||||
|
||||
$controllers->post('/users/downloads', 'controller.report.activity:doReportDownloadsByUsers')
|
||||
->bind('report_activity_users_downloads');;
|
||||
|
||||
$controllers->post('/questions/best-of', 'controller.report.activity:doReportBestOfQuestions')
|
||||
->bind('report_activity_questions_bestof');
|
||||
|
||||
$controllers->post('/questions/no-best-of', 'controller.report.activity:doReportNoBestOfQuestions')
|
||||
->bind('report_activity_questions_nobestof');
|
||||
|
||||
$controllers->post('/instance/hours', 'controller.report.activity:doReportSiteActiviyPerHours')
|
||||
->bind('report_activity_instance_hours');
|
||||
|
||||
$controllers->post('/instance/days', 'controller.report.activity:doReportSiteActivityPerDays')
|
||||
->bind('report_activity_instance_days');
|
||||
|
||||
$controllers->post('/documents/pushed', 'controller.report.activity:doReportPushedDocuments')
|
||||
->bind('report_activity_documents_pushed');
|
||||
|
||||
$controllers->post('/documents/added', 'controller.report.activity:doReportAddedDocuments')
|
||||
->bind('report_activity_documents_added');
|
||||
|
||||
$controllers->post('/documents/edited', 'controller.report.activity:doReportEditedDocuments')
|
||||
->bind('report_activity_documents_edited');
|
||||
|
||||
$controllers->post('/documents/validated', 'controller.report.activity:doReportValidatedDocuments')
|
||||
->bind('report_activity_documents_validated');
|
||||
|
||||
$controllers->post('/documents/sent', 'controller.report.activity:doReportSentDocuments')
|
||||
->bind('report_activity_documents_sent');
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\ControllerProvider\Report;
|
||||
|
||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||
use Alchemy\Phrasea\Controller\Report\InformationController;
|
||||
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ServiceProviderInterface;
|
||||
|
||||
class Information implements ControllerProviderInterface, ServiceProviderInterface
|
||||
{
|
||||
use ControllerProviderTrait;
|
||||
|
||||
public function register(Application $app)
|
||||
{
|
||||
$app['controller.report.information'] = $app->share(function (PhraseaApplication $app) {
|
||||
return new InformationController($app);
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(Application $app)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = $this->createAuthenticatedCollection($app);
|
||||
$firewall = $this->getFirewall($app);
|
||||
|
||||
$controllers->before(function () use ($firewall) {
|
||||
$firewall->requireAccessToModule('report');
|
||||
});
|
||||
|
||||
$controllers->post('/user', 'controller.report.information:doReportInformationUser')
|
||||
->bind('report_infomations_user');
|
||||
|
||||
$controllers->post('/browser', 'controller.report.information:doReportInformationBrowser')
|
||||
->bind('report_infomations_browser');
|
||||
|
||||
$controllers->post('/document', 'controller.report.information:doReportInformationDocument')
|
||||
->bind('report_infomations_document');
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
}
|
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
namespace Alchemy\Phrasea\Report\Controller;
|
||||
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Report\Report;
|
||||
use Alchemy\Phrasea\Report\ReportConnections;
|
||||
use Alchemy\Phrasea\Report\ReportDownloads;
|
||||
@@ -16,10 +17,11 @@ use Alchemy\Phrasea\Report\ReportFactory;
|
||||
use Alchemy\Phrasea\Report\ReportRecords;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
|
||||
class ProdReportController
|
||||
class ProdReportController extends Controller
|
||||
{
|
||||
private static $mapFromExtension = [
|
||||
'csv' => [
|
||||
@@ -55,6 +57,19 @@ class ProdReportController
|
||||
$this->acl = $acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* route prod/report/connections
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function indexAction(Request $request)
|
||||
{
|
||||
return new Response($this->render('prod/report/index.html.twig', [
|
||||
'truc' => "hello"
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* route prod/report/connections
|
||||
*
|
||||
|
@@ -58,20 +58,27 @@ class ProdReportControllerProvider implements ControllerProviderInterface, Servi
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = $this->createAuthenticatedCollection($app);
|
||||
|
||||
$controllers
|
||||
->get('/', 'controller.prod.report:indexAction')
|
||||
;
|
||||
|
||||
$controllers
|
||||
->get('/connections/{sbasId}/', 'controller.prod.report:connectionsAction')
|
||||
->assert('sbasId', '\d+')
|
||||
->bind('report2_connections')
|
||||
;
|
||||
|
||||
$controllers
|
||||
->get('/downloads/{sbasId}/', 'controller.prod.report:downloadsAction')
|
||||
->assert('sbasId', '\d+')
|
||||
->bind('report2_downloads')
|
||||
;
|
||||
|
||||
$controllers
|
||||
->get('/records/{sbasId}/', 'controller.prod.report:recordsAction')
|
||||
->assert('sbasId', '\d+')
|
||||
->bind('report2_records')
|
||||
;
|
||||
|
||||
return $controllers;
|
||||
|
@@ -72,8 +72,6 @@ class ReportRecords extends Report
|
||||
. " AND r.record_id >= " . $row['from'] . " AND r.record_id <= " . $row['to'] . "\n"
|
||||
. "GROUP BY `record_id`\n";
|
||||
|
||||
// file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export($sql, true)), FILE_APPEND);
|
||||
|
||||
$stmt = $this->databox->get_connection()->executeQuery($sql, []);
|
||||
$rows = $stmt->fetchAll();
|
||||
$stmt->closeCursor();
|
||||
|
Reference in New Issue
Block a user