-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PDF letter functionality for Activities using new token processor
Create CRM_Actvity_Form_Task_PDFLetterCommon extending CRM_Core_Form_Task_PDFLetterCommon CRM_Activity_Tokens: add source, target and assignee tokens Eg: {activity.target_N_display_name} - N can be substituted for a number to show the details of the nth activity target contact eg: {activity.target_1_display_name} is the display name of the first target For ease of use, contacts are numbered from 1. If the literal N is used or is replaced by 0, it is treated as 1. Slim down alterActionScheduleQuery() and move most data fetching to prefetch() Add tests for Activity PDF Letter
- Loading branch information
Showing
8 changed files
with
608 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 5 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2019 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM 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 and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC (c) 2004-2019 | ||
*/ | ||
|
||
/** | ||
* This class provides the functionality to create PDF/Word letters for activities. | ||
*/ | ||
class CRM_Activity_Form_Task_PDF extends CRM_Activity_Form_Task { | ||
/** | ||
* Build all the data structures needed to build the form. | ||
*/ | ||
public function preProcess() { | ||
parent::preProcess(); | ||
CRM_Activity_Form_Task_PDFLetterCommon::preProcess($this); | ||
} | ||
|
||
/** | ||
* Set defaults for the pdf. | ||
* | ||
* @return array | ||
*/ | ||
public function setDefaultValues() { | ||
return CRM_Activity_Form_Task_PDFLetterCommon::setDefaultValues(); | ||
} | ||
|
||
/** | ||
* Build the form object. | ||
*/ | ||
public function buildQuickForm() { | ||
CRM_Activity_Form_Task_PDFLetterCommon::buildQuickForm($this); | ||
} | ||
|
||
/** | ||
* Process the form after the input has been submitted and validated. | ||
*/ | ||
public function postProcess() { | ||
CRM_Activity_Form_Task_PDFLetterCommon::postProcess($this); | ||
} | ||
|
||
/** | ||
* List available tokens for this form. | ||
* | ||
* @return array | ||
*/ | ||
public function listTokens() { | ||
return CRM_Activity_Form_Task_PDFLetterCommon::listTokens(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 5 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2019 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM 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 and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
use Civi\Token\TokenProcessor; | ||
|
||
/** | ||
* This class provides the common functionality for creating PDF letter for | ||
* activities. | ||
* | ||
*/ | ||
class CRM_Activity_Form_Task_PDFLetterCommon extends CRM_Core_Form_Task_PDFLetterCommon { | ||
|
||
/** | ||
* Process the form after the input has been submitted and validated. | ||
* | ||
* @param CRM_Core_Form $form | ||
* @param $activityIds | ||
* | ||
* @return void | ||
*/ | ||
public static function postProcess(&$form) { | ||
$activityIds = $form->_activityHolderIds; | ||
$formValues = $form->controller->exportValues($form->getName()); | ||
$html_message = self::processTemplate($formValues); | ||
|
||
// Do the rest in another function to make testing easier | ||
self::createDocument($activityIds, $html_message, $formValues); | ||
|
||
$form->postProcessHook(); | ||
|
||
CRM_Utils_System::civiExit(1); | ||
} | ||
|
||
/** | ||
* Produce the document from the activities | ||
* This uses the new token processor | ||
* | ||
* @param array $activityIds array of activity ids | ||
* @param string $html_message message text with tokens | ||
* @param array $formValues formValues from the form | ||
* @return void | ||
*/ | ||
public static function createDocument($activityIds, $html_message, $formValues) { | ||
$tp = self::createTokenProcessor(); | ||
$tp->addMessage('body_html', $html_message, 'text/html'); | ||
|
||
foreach ($activityIds as $activityId) { | ||
$tp->addRow()->context('activityId', $activityId); | ||
} | ||
$tp->evaluate(); | ||
|
||
return self::renderFromRows($tp->getRows(), 'body_html', $formValues); | ||
} | ||
|
||
/** | ||
* Create a token processor | ||
*/ | ||
public static function createTokenProcessor() { | ||
return new TokenProcessor(\Civi::dispatcher(), array( | ||
'controller' => get_class(), | ||
'smarty' => FALSE, | ||
'schema' => ['activityId'], | ||
)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.