From 2beb47b8f1b7d4d32140d7bd335e2315c061d3e8 Mon Sep 17 00:00:00 2001 From: Bradley Taylor Date: Sat, 22 Jan 2022 12:04:54 +0000 Subject: [PATCH] Tidy up functions related to printing. Calls to setPrint updated to use constant, and inline documentation updated to reflect the values which are actually expected. setWord and setExcel methods deprectated as they are not in use, and they only support the older Microsoft Office formats (doc, not docx) --- CRM/Activity/Form/Task/Print.php | 2 +- CRM/Campaign/Form/Task/Print.php | 2 +- CRM/Case/Form/Task/Print.php | 2 +- CRM/Contact/Form/Task/Print.php | 2 +- CRM/Contribute/Form/Task/Print.php | 2 +- CRM/Core/Controller.php | 44 ++++++++++++++++----- CRM/Core/Page.php | 19 ++++++--- CRM/Core/Selector/Controller.php | 13 ++++-- CRM/Event/Form/Task/Print.php | 2 +- CRM/Mailing/Form/Task/Print.php | 2 +- CRM/Member/Form/Task/Print.php | 2 +- CRM/Pledge/Form/Task/Print.php | 2 +- ext/civigrant/CRM/Grant/Form/Task/Print.php | 2 +- 13 files changed, 67 insertions(+), 29 deletions(-) diff --git a/CRM/Activity/Form/Task/Print.php b/CRM/Activity/Form/Task/Print.php index 0a5e6025e4..8546c9b6aa 100644 --- a/CRM/Activity/Form/Task/Print.php +++ b/CRM/Activity/Form/Task/Print.php @@ -32,7 +32,7 @@ class CRM_Activity_Form_Task_Print extends CRM_Activity_Form_Task { parent::preprocess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); // get the formatted params $queryParams = $this->get('queryParams'); diff --git a/CRM/Campaign/Form/Task/Print.php b/CRM/Campaign/Form/Task/Print.php index 96d0171622..fb7af99b94 100644 --- a/CRM/Campaign/Form/Task/Print.php +++ b/CRM/Campaign/Form/Task/Print.php @@ -27,7 +27,7 @@ class CRM_Campaign_Form_Task_Print extends CRM_Campaign_Form_Task { parent::preprocess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); // get the formatted params $queryParams = $this->get('queryParams'); diff --git a/CRM/Case/Form/Task/Print.php b/CRM/Case/Form/Task/Print.php index 0c129c2c45..0fa3e68607 100644 --- a/CRM/Case/Form/Task/Print.php +++ b/CRM/Case/Form/Task/Print.php @@ -28,7 +28,7 @@ class CRM_Case_Form_Task_Print extends CRM_Case_Form_Task { parent::preProcess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); // get the formatted params $queryParams = $this->get('queryParams'); diff --git a/CRM/Contact/Form/Task/Print.php b/CRM/Contact/Form/Task/Print.php index 2869f520a1..4c7bfd7af0 100644 --- a/CRM/Contact/Form/Task/Print.php +++ b/CRM/Contact/Form/Task/Print.php @@ -28,7 +28,7 @@ class CRM_Contact_Form_Task_Print extends CRM_Contact_Form_Task { parent::preprocess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); $this->assign('id', $this->get('id')); $this->assign('pageTitle', ts('CiviCRM Contact Listing')); diff --git a/CRM/Contribute/Form/Task/Print.php b/CRM/Contribute/Form/Task/Print.php index b1dc6b658f..4a24fd9bde 100644 --- a/CRM/Contribute/Form/Task/Print.php +++ b/CRM/Contribute/Form/Task/Print.php @@ -27,7 +27,7 @@ class CRM_Contribute_Form_Task_Print extends CRM_Contribute_Form_Task { parent::preprocess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); // get the formatted params $queryParams = $this->get('queryParams'); diff --git a/CRM/Core/Controller.php b/CRM/Core/Controller.php index 3924aa4641..f31e5f963f 100644 --- a/CRM/Core/Controller.php +++ b/CRM/Core/Controller.php @@ -86,7 +86,9 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { * Are we in print mode? if so we need to modify the display * functionality to do a minimal display :) * - * @var bool + * @var int|string + * Should match a CRM_Core_Smarty::PRINT_* constant, + * or equal 0 if not in print mode */ public $_print = 0; @@ -668,9 +670,17 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { } /** - * @param null $fileName + * Output HTTP headers for Word document + * (note .doc, not the newer .docx format) + * + * @deprecated + * + * @param string|null $fileName + * @return void */ public function setWord($fileName = NULL) { + CRM_Core_Error::deprecatedFunctionWarning('no alternative'); + //Mark as a CSV file. CRM_Utils_System::setHttpHeader('Content-Type', 'application/vnd.ms-word'); @@ -682,9 +692,17 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { } /** - * @param null $fileName + * Output HTTP headers for Excel document + * (note .xls, not the newer .xlsx format) + * + * @deprecated + * + * @param string|null $fileName + * @return void */ public function setExcel($fileName = NULL) { + CRM_Core_Error::deprecatedFunctionWarning('no alternative'); + //Mark as an excel file. CRM_Utils_System::setHttpHeader('Content-Type', 'application/vnd.ms-excel'); @@ -699,13 +717,20 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { /** * Setter for print. * - * @param bool $print + * Historically the $print argument has also accepted a string (xls or doc), + * but this usage is now deprecated. + * + * @param int|string $print + * Should match a CRM_Core_Smarty::PRINT_* constant, + * or equal 0 if not in print mode + * + * @return void */ public function setPrint($print) { - if ($print == "xls") { + if ($print === "xls") { $this->setExcel(); } - elseif ($print == "doc") { + elseif ($print === "doc") { $this->setWord(); } $this->_print = $print; @@ -714,8 +739,9 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { /** * Getter for print. * - * @return bool - * return the print value + * @return int|string + * Value matching a CRM_Core_Smarty::PRINT_* constant, + * or 0 if not in print mode */ public function getPrint() { return $this->_print; @@ -729,7 +755,7 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { if ($this->_print == CRM_Core_Smarty::PRINT_PAGE) { return 'CRM/common/print.tpl'; } - elseif ($this->_print == 'xls' || $this->_print == 'doc') { + elseif ($this->_print === 'xls' || $this->_print === 'doc') { return 'CRM/Contact/Form/Task/Excel.tpl'; } else { diff --git a/CRM/Core/Page.php b/CRM/Core/Page.php index 99742ac99c..81adf5441b 100644 --- a/CRM/Core/Page.php +++ b/CRM/Core/Page.php @@ -59,7 +59,9 @@ class CRM_Core_Page { * Are we in print mode? if so we need to modify the display * functionality to do a minimal display :) * - * @var bool + * @var int|string + * Should match a CRM_Core_Smarty::PRINT_* constant, + * or equal 0 if not in print mode */ protected $_print = FALSE; @@ -215,10 +217,10 @@ class CRM_Core_Page { //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); - if ($this->_print == CRM_Core_Smarty::PRINT_PDF) { + if ($this->_print === CRM_Core_Smarty::PRINT_PDF) { CRM_Utils_PDF_Utils::html2pdf($content, "{$this->_name}.pdf", FALSE); } - elseif ($this->_print == CRM_Core_Smarty::PRINT_JSON) { + elseif ($this->_print === CRM_Core_Smarty::PRINT_JSON) { $this->ajaxResponse['content'] = $content; CRM_Core_Page_AJAX::returnJsonResponse($this->ajaxResponse); } @@ -386,7 +388,11 @@ class CRM_Core_Page { /** * Setter for print. * - * @param bool $print + * @param int|string $print + * Should match a CRM_Core_Smarty::PRINT_* constant, + * or equal 0 if not in print mode + * + * @return void */ public function setPrint($print) { $this->_print = $print; @@ -395,8 +401,9 @@ class CRM_Core_Page { /** * Getter for print. * - * @return bool - * return the print value + * @return int|string + * Value matching a CRM_Core_Smarty::PRINT_* constant, + * or 0 if not in print mode */ public function getPrint() { return $this->_print; diff --git a/CRM/Core/Selector/Controller.php b/CRM/Core/Selector/Controller.php index 66dd528f0b..05e1e09a90 100644 --- a/CRM/Core/Selector/Controller.php +++ b/CRM/Core/Selector/Controller.php @@ -110,7 +110,9 @@ class CRM_Core_Selector_Controller { * Are we in print mode? if so we need to modify the display * functionality to do a minimal display :) * - * @var bool + * @var int|string + * Should match a CRM_Core_Smarty::PRINT_* constant, + * or equal 0 if not in print mode */ protected $_print = FALSE; @@ -516,7 +518,9 @@ class CRM_Core_Selector_Controller { /** * Setter for print. * - * @param bool $print + * @param int|string $print + * Should match a CRM_Core_Smarty::PRINT_* constant, + * or equal 0 if not in print mode * * @return void */ @@ -527,8 +531,9 @@ class CRM_Core_Selector_Controller { /** * Getter for print. * - * @return bool - * return the print value + * @return int|string + * Value matching a CRM_Core_Smarty::PRINT_* constant, + * or 0 if not in print mode */ public function getPrint() { return $this->_print; diff --git a/CRM/Event/Form/Task/Print.php b/CRM/Event/Form/Task/Print.php index c64e92f9b1..6f5c9a6669 100644 --- a/CRM/Event/Form/Task/Print.php +++ b/CRM/Event/Form/Task/Print.php @@ -29,7 +29,7 @@ class CRM_Event_Form_Task_Print extends CRM_Event_Form_Task { parent::preprocess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); // get the formatted params $queryParams = $this->get('queryParams'); diff --git a/CRM/Mailing/Form/Task/Print.php b/CRM/Mailing/Form/Task/Print.php index 217d4cf67f..6cc8f2eb2d 100644 --- a/CRM/Mailing/Form/Task/Print.php +++ b/CRM/Mailing/Form/Task/Print.php @@ -27,7 +27,7 @@ class CRM_Mailing_Form_Task_Print extends CRM_Mailing_Form_Task { parent::preprocess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); // get the formatted params $queryParams = $this->get('queryParams'); diff --git a/CRM/Member/Form/Task/Print.php b/CRM/Member/Form/Task/Print.php index 665561e3ee..eda7243290 100644 --- a/CRM/Member/Form/Task/Print.php +++ b/CRM/Member/Form/Task/Print.php @@ -29,7 +29,7 @@ class CRM_Member_Form_Task_Print extends CRM_Member_Form_Task { parent::preprocess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); // get the formatted params $queryParams = $this->get('queryParams'); diff --git a/CRM/Pledge/Form/Task/Print.php b/CRM/Pledge/Form/Task/Print.php index 06b0602270..8ce25f435a 100644 --- a/CRM/Pledge/Form/Task/Print.php +++ b/CRM/Pledge/Form/Task/Print.php @@ -28,7 +28,7 @@ class CRM_Pledge_Form_Task_Print extends CRM_Pledge_Form_Task { parent::preprocess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); // get the formatted params $queryParams = $this->get('queryParams'); diff --git a/ext/civigrant/CRM/Grant/Form/Task/Print.php b/ext/civigrant/CRM/Grant/Form/Task/Print.php index 70dcd64936..1a6b240e2f 100644 --- a/ext/civigrant/CRM/Grant/Form/Task/Print.php +++ b/ext/civigrant/CRM/Grant/Form/Task/Print.php @@ -29,7 +29,7 @@ class CRM_Grant_Form_Task_Print extends CRM_Grant_Form_Task { parent::preprocess(); // set print view, so that print templates are called - $this->controller->setPrint(1); + $this->controller->setPrint(CRM_Core_Smarty::PRINT_PAGE); // get the formatted params $queryParams = $this->get('queryParams'); -- 2.25.1