CRM-17606 - Create multiple documents from Find Cases search result
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Mon, 23 May 2016 11:22:54 +0000 (16:52 +0530)
committerColeman Watts <coleman@civicrm.org>
Wed, 20 Jul 2016 00:01:48 +0000 (20:01 -0400)
CRM/Case/Form/Task.php
CRM/Case/Form/Task/ExportDocument.php [new file with mode: 0644]
CRM/Case/Task.php
CRM/Contact/Form/Task/PDFLetterCommon.php
templates/CRM/Case/Form/Task/ExportDocument.tpl [new file with mode: 0644]

index 6deaed3f38917e1b59b8ae9d2a51e36e2e92d8bf..69ba68394e7e0360e1c7c162382878ab8ed1e6f2 100644 (file)
@@ -62,7 +62,7 @@ class CRM_Case_Form_Task extends CRM_Core_Form {
    *
    * @var array
    */
-  protected $_caseIds;
+  public $_caseIds;
 
   /**
    * Build all the data structures needed to build the form.
@@ -137,7 +137,7 @@ class CRM_Case_Form_Task extends CRM_Core_Form {
    */
   public function setContactIDs() {
     $this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_caseIds,
-      'civicrm_case'
+      'civicrm_case_contact'
     );
   }
 
diff --git a/CRM/Case/Form/Task/ExportDocument.php b/CRM/Case/Form/Task/ExportDocument.php
new file mode 100644 (file)
index 0000000..db4b862
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
+ +--------------------------------------------------------------------+
+ | 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-2016
+ */
+
+/**
+ * This class provides the functionality to create PDF letter for a group of contacts.
+ */
+class CRM_Case_Form_Task_ExportDocument extends CRM_Case_Form_Task {
+  /**
+   * All the existing templates in the system.
+   *
+   * @var array
+   */
+  public $_templates = NULL;
+
+  public $_single = NULL;
+
+  public $_cid = NULL;
+
+  /**
+   * Build all the data structures needed to build the form.
+   */
+  public function preProcess() {
+    $this->skipOnHold = $this->skipDeceased = FALSE;
+    parent::preProcess();
+    $this->setContactIDs();
+    CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
+  }
+
+  public function setDefaultValues() {
+    return CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
+  }
+
+  /**
+   * Build the form object.
+   */
+  public function buildQuickForm() {
+    CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
+  }
+
+  /**
+   * Process the form after the input has been submitted and validated.
+   */
+  public function postProcess() {
+    CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
+  }
+
+  /**
+   * List available tokens for this form.
+   *
+   * @return array
+   */
+  public function listTokens() {
+    $tokens = CRM_Core_SelectValues::contactTokens();
+    foreach ($this->_caseIds as $key => $caseId) {
+      $caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'case_type_id');
+      $tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
+    }
+    return $tokens;
+  }
+
+}
index 789b4fd2bec596d0e5aabf81842f6edf4f463708..a6fea66ef3a032680665d1a91e9ed9f1c2f38bd7 100644 (file)
@@ -86,6 +86,11 @@ class CRM_Case_Task {
           'class' => 'CRM_Case_Form_Task_Restore',
           'result' => FALSE,
         ),
+        5 => array(
+          'title' => ts('Export Document'),
+          'class' => 'CRM_Case_Form_Task_ExportDocument',
+          'result' => FALSE,
+        ),
       );
       //CRM-4418, check for delete
       if (!CRM_Core_Permission::check('delete in CiviCase')) {
index 9f45d26ae7b67a9293c23c1c4cbf4a4cd0243a5c..4a4677f2d6ed6f29ec6a213cfc7b9c43d7e0dfcf 100644 (file)
@@ -350,6 +350,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
     }
 
     foreach ($form->_contactIds as $item => $contactId) {
+      $caseId = NULL;
       $params = array('contact_id' => $contactId);
 
       list($contact) = CRM_Utils_Token::getTokenDetails($params,
@@ -368,7 +369,13 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
 
       $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
       if (!empty($form->_caseId)) {
-        $tokenHtml = CRM_Utils_Token::replaceCaseTokens($form->_caseId, $html_message, $messageToken);
+        $caseId = $form->_caseId;
+      }
+      if (empty($caseId) && !empty($form->_caseIds[$item])) {
+        $caseId = $form->_caseIds[$item];
+      }
+      if ($caseId) {
+        $tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenHtml, $messageToken);
       }
       $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE);
 
diff --git a/templates/CRM/Case/Form/Task/ExportDocument.tpl b/templates/CRM/Case/Form/Task/ExportDocument.tpl
new file mode 100644 (file)
index 0000000..6e6ea5a
--- /dev/null
@@ -0,0 +1,30 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+*}
+<div class="crm-form-block crm-block crm-contact-task-pdf-form-block">
+<div class="messages status no-popup">{include file="CRM/Case/Form/Task.tpl"}</div>
+{include file="CRM/Contact/Form/Task/PDFLetterCommon.tpl"}
+<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+</div>