Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#71 Add functionality to create PDF/Word docs from Activity searches #12012

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions CRM/Activity/Form/Task/PDF.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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();
}

}
90 changes: 90 additions & 0 deletions CRM/Activity/Form/Task/PDFLetterCommon.php
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'],
));
}

}
5 changes: 5 additions & 0 deletions CRM/Activity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public static function tasks() {
],
'result' => FALSE,
],
self::PDF_LETTER => [
'title' => ts('Print/merge Document'),
'class' => 'CRM_Activity_Form_Task_PDF',
'result' => FALSE,
],
self::TASK_SMS => [
'title' => ts('SMS - send reply'),
'class' => 'CRM_Activity_Form_Task_SMS',
Expand Down
Loading