mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 22:04:23 +00:00
Allowing export for reports
This commit is contained in:
parent
897a0361a8
commit
6ec0892ac6
@ -33,10 +33,12 @@ use Chill\ReportBundle\Form\ReportType;
|
||||
*/
|
||||
class ReportController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Lists all Report entities.
|
||||
* List all the report entities for a given person.
|
||||
*
|
||||
* @param integer $person_id The id of the person.
|
||||
* @param Request $request The request
|
||||
* @return Response The web page.
|
||||
*/
|
||||
public function listAction($person_id, Request $request)
|
||||
{
|
||||
@ -52,9 +54,12 @@ class ReportController extends Controller
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Select the type of the Report
|
||||
* Display a form for selecting which type of report to add for a given person
|
||||
*
|
||||
* @param integer $person_id The id of the person.
|
||||
* @param Request $request The request
|
||||
* @return Response The web page.
|
||||
*/
|
||||
public function selectReportTypeAction($person_id, Request $request)
|
||||
{
|
||||
@ -68,19 +73,15 @@ class ReportController extends Controller
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
|
||||
$cFGroups = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
|
||||
->findByEntity('Chill\ReportBundle\Entity\Report');
|
||||
|
||||
|
||||
if(count($cFGroups) === 1 ){
|
||||
return $this->redirect(
|
||||
$this->generateUrl('report_new',
|
||||
array('person_id' => $person_id, 'cf_group_id' => $cFGroups[0]->getId())));
|
||||
}
|
||||
|
||||
|
||||
$cFGroupsChoice = array();
|
||||
|
||||
foreach ($cFGroups as $cFGroup) {
|
||||
@ -97,6 +98,8 @@ class ReportController extends Controller
|
||||
))
|
||||
->getForm();
|
||||
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
|
||||
return $this->render('ChillReportBundle:Report:select_report_type.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'person' => $person
|
||||
@ -104,8 +107,87 @@ class ReportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to create a new Report entity.
|
||||
* Display a form for selecting which type of report to export
|
||||
* (a csv file with all the report of this type)
|
||||
*
|
||||
* @param Request $request The request
|
||||
* @return Response The web page.
|
||||
*/
|
||||
public function selectReportTypeForExportAction(Request $request)
|
||||
{
|
||||
$cFGroupId = $request->query->get('cFGroup');
|
||||
|
||||
if($cFGroupId) {
|
||||
return $this->redirect(
|
||||
$this->generateUrl('report_export_list',
|
||||
array('cf_group_id' => $cFGroupId)));
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$cFGroups = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
|
||||
->findByEntity('Chill\ReportBundle\Entity\Report');
|
||||
|
||||
if(count($cFGroups) === 1 ){
|
||||
return $this->redirect(
|
||||
$this->generateUrl('report_export_list',
|
||||
array('cf_group_id' => $cFGroups[0]->getId())));
|
||||
}
|
||||
|
||||
$cFGroupsChoice = array();
|
||||
|
||||
foreach ($cFGroups as $cFGroup) {
|
||||
$cFGroupsChoice[$cFGroup->getId()] = $cFGroup->getName($request->getLocale());
|
||||
}
|
||||
|
||||
$form = $this->get('form.factory')
|
||||
->createNamedBuilder(null, 'form', null, array(
|
||||
'method' => 'GET',
|
||||
'csrf_protection' => false
|
||||
))
|
||||
->add('cFGroup', 'choice', array(
|
||||
'choices' => $cFGroupsChoice
|
||||
))
|
||||
->getForm();
|
||||
|
||||
return $this->render('ChillReportBundle:Report:select_report_type_for_export.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'layout_name' => "ChillMainBundle::Export/layout.html.twig"
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a csv file with all the reports of a given type
|
||||
*
|
||||
* @param integer $cf_group_id The id of the report type to export
|
||||
* @param Request $request The request
|
||||
* @return A csv file with all the reports of the selected type
|
||||
*/
|
||||
public function exportAction($cf_group_id, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cf_group_id);
|
||||
$reports = $em->getRepository('ChillReportBundle:Report')->findByCFGroup($cFGroup);
|
||||
|
||||
|
||||
$response = $this->render('ChillReportBundle:Report:export.csv.twig', array(
|
||||
'reports' => $reports,
|
||||
'cf_group' => $cFGroup
|
||||
));
|
||||
|
||||
$response->headers->set('Content-Type', 'text/csv');
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="export.csv"');
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form for creating a new report for a given person and of a given type
|
||||
*
|
||||
* @param integer $person_id The id of the person.
|
||||
* @param integer $cf_group_id The id of the report type.
|
||||
* @param Request $request The request
|
||||
* @return Response The web page.
|
||||
*/
|
||||
public function newAction($person_id, $cf_group_id, Request $request)
|
||||
{
|
||||
@ -130,8 +212,12 @@ class ReportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Report entity.
|
||||
* Create a new report for a given person and of a given type
|
||||
*
|
||||
* @param integer $person_id The id of the person.
|
||||
* @param integer $cf_group_id The id of the report type.
|
||||
* @param Request $request The request containing the form data (from the newAction)
|
||||
* @return Response The web page.
|
||||
*/
|
||||
public function createAction($person_id, $cf_group_id, Request $request)
|
||||
{
|
||||
@ -183,6 +269,8 @@ class ReportController extends Controller
|
||||
* Creates a form to create a Report entity.
|
||||
*
|
||||
* @param Report $entity The entity
|
||||
* @param integer $person_id The id of the person.
|
||||
* @param integer $cf_group_id The id of the report type.
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
@ -200,8 +288,11 @@ class ReportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a Report entity.
|
||||
* Find and display a report.
|
||||
*
|
||||
* @param integer $report_id The id of the report.
|
||||
* @param integer $person_id The id of the person.
|
||||
* @return Response The web page.
|
||||
*/
|
||||
public function viewAction($report_id, $person_id)
|
||||
{
|
||||
@ -223,8 +314,11 @@ class ReportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing Report entity.
|
||||
* Display a form to edit an existing Report entity.
|
||||
*
|
||||
* @param integer $person_id The id of the person.
|
||||
* @param integer $report_id The id of the report.
|
||||
* @return Response The web page.
|
||||
*/
|
||||
public function editAction($person_id, $report_id, Request $request)
|
||||
{
|
||||
@ -255,8 +349,8 @@ class ReportController extends Controller
|
||||
/**
|
||||
* Creates a form to edit a Report entity.
|
||||
*
|
||||
* @param Report $entity The entity
|
||||
*
|
||||
* @param Report $entity The report to edit.
|
||||
* @param integer $person_id The id of the person.
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createEditForm(Report $entity, $person_id)
|
||||
@ -273,8 +367,11 @@ class ReportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits an existing Report entity.
|
||||
* Web page for editing an existing report.
|
||||
*
|
||||
* @param integer $person_id The id of the person.
|
||||
* @param integer $report_id The id of the report.
|
||||
* @return Response The web page.
|
||||
*/
|
||||
public function updateAction($person_id, $report_id, Request $request)
|
||||
{
|
||||
|
@ -34,4 +34,18 @@ report_edit:
|
||||
report_update:
|
||||
path: /{_locale}/person/{person_id}/report/{report_id}/update
|
||||
defaults: { _controller: "ChillReportBundle:Report:update" }
|
||||
requirements: { _method: post|put }
|
||||
requirements: { _method: post|put }
|
||||
|
||||
report_export_list:
|
||||
path: /{_locale}/export/report/cfgroup/{cf_group_id}
|
||||
defaults: { _controller: "ChillReportBundle:Report:export" }
|
||||
|
||||
|
||||
report_export_select_type:
|
||||
pattern: /{_locale}/export/report/select/type
|
||||
defaults: {_controller: "ChillReportBundle:Report:selectReportTypeForExport" }
|
||||
options:
|
||||
menus:
|
||||
export:
|
||||
order: 100
|
||||
label: Export reports
|
23
Resources/views/Report/export.csv.twig
Normal file
23
Resources/views/Report/export.csv.twig
Normal file
@ -0,0 +1,23 @@
|
||||
"{{ 'Person'|trans }}",{#
|
||||
#}"{{ 'Date'|trans }}",{#
|
||||
#}"{{ 'User'|trans }}",{#
|
||||
#}"{{ 'Report type'|trans }}",{#
|
||||
#}{% for customField in cf_group.customFields %}{#
|
||||
#}"{{ chill_custom_field_label(customField) }}"{% if not loop.last %},{% endif %}{#
|
||||
#}{% endfor %}
|
||||
|
||||
{% for report in reports %}{#
|
||||
#}"{{ report.person }}",{#
|
||||
#}"{{ report.date|localizeddate('long', 'none') }}",{#
|
||||
#}"{{ report.user }}",{#
|
||||
#}"{{ report.cFGroup.getName(app.request.locale) }}",{#
|
||||
#}{% for customField in report.cFGroup.customFields %}{#
|
||||
#}{% if customField.type == 'title' %}{#
|
||||
#}""{#
|
||||
#}{% else %}{#
|
||||
#}"{{ chill_custom_field_widget(report.cFData , customField, 'csv') }}"{#
|
||||
#}{% endif %}{#
|
||||
#}{% if not loop.last %},{% endif %}{#
|
||||
#}{% endfor %}
|
||||
|
||||
{% endfor %}
|
@ -22,7 +22,6 @@
|
||||
|
||||
{% block personcontent %}
|
||||
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form.cFGroup) }}
|
||||
<button class="sc-button green" type="submit">
|
||||
@ -30,6 +29,5 @@
|
||||
{{ 'Create a new report'|trans }}
|
||||
</button>
|
||||
{{ form_end(form) }}
|
||||
|
||||
|
||||
{% endblock %}
|
@ -0,0 +1,33 @@
|
||||
{#
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#}
|
||||
{% extends "ChillMainBundle::Export/layout.html.twig" %}
|
||||
|
||||
{% set activeRouteKey = 'report_export_list' %}
|
||||
|
||||
{% block title %}{{ 'Reports export'|trans() }}{% endblock title %}
|
||||
|
||||
{% block export_content %}
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form.cFGroup) }}
|
||||
<button class="sc-button green" type="submit">
|
||||
<i class="fa fa-upload"></i>
|
||||
{{ 'Export this kind of reports'|trans }}
|
||||
</button>
|
||||
{{ form_end(form) }}
|
||||
|
||||
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user