3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 use Civi\Report\OutputHandlerInterface
;
13 use Civi\Report\OutputHandlerBase
;
16 * CSV Report Output Handler
18 class CRM_Report_OutputHandler_Csv
extends OutputHandlerBase
implements OutputHandlerInterface
{
21 * Are we a suitable output handler based on the given form?
23 * The class member $form isn't set yet at this point since we don't
24 * even know if we're in play yet, so the form is a parameter.
26 * @param CRM_Report_Form $form
30 public function isOutputHandlerFor(CRM_Report_Form
$form):bool {
31 return ($form->getOutputMode() === 'csv');
35 * Return the download filename. This should be the "clean" name, not
36 * a munged temporary filename.
40 public function getFileName():string {
41 return 'CiviReport.csv';
45 * Return the html body of the email.
49 public function getMailBody():string {
50 // @todo It would be nice if this was more end-user configurable, but
51 // keeping it the same as it was before for now.
52 $url = CRM_Utils_System
::url('civicrm/report/instance/' . $this->getForm()->getID(), 'reset=1', TRUE);
53 return $this->getForm()->getReportHeader() . '<p>' . ts('Report URL') .
54 ": {$url}</p>" . '<p>' .
55 ts('The report is attached as a CSV file.') . '</p>' .
56 $this->getForm()->getReportFooter();
60 * Return the report contents as a string, in this case the csv output.
64 public function getOutputString():string {
65 //@todo Hmm. See note in CRM_Report_Form::endPostProcess about $rows.
66 $rows = $this->getForm()->getTemplate()->get_template_vars('rows');
68 // avoid pass-by-ref warning
69 $form = $this->getForm();
71 return CRM_Report_Utils_Report
::makeCsv($form, $rows);
75 * Set headers as appropriate and send the output to the browser.
77 public function download() {
78 //@todo Hmm. See note in CRM_Report_Form::endPostProcess about $rows.
79 $rows = $this->getForm()->getTemplate()->get_template_vars('rows');
81 // avoid pass-by-ref warning
82 $form = $this->getForm();
84 CRM_Report_Utils_Report
::export2csv($form, $rows);
88 * Mime type of the attachment.
92 public function getMimeType():string {
97 * Charset of the attachment.
101 public function getCharset():string {