merge commonLetterCompose() and commonCompose()
[civicrm-core.git] / CRM / Contact / Form / Task / PDFLetterCommon.php
index 7cfe3a757a9bc27116c28fa369abe63dd1957ef8..5fb7f55483529d53b1d3be1d4f528dcc7c2c6699 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | 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-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
 class CRM_Contact_Form_Task_PDFLetterCommon {
 
   /**
-   * Build all the data structures needed to build the form
+   * Build all the data structures needed to build the form.
    *
    * @param CRM_Core_Form $form
    *
    * @return void
    */
   public static function preProcess(&$form) {
-    $messageText    = array();
+    $messageText = array();
     $messageSubject = array();
-    $dao            = new CRM_Core_BAO_MessageTemplate();
+    $dao = new CRM_Core_BAO_MessageTemplate();
     $dao->is_active = 1;
     $dao->find();
     while ($dao->fetch()) {
@@ -73,7 +73,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * Build the form object
+   * Build the form object.
    *
    * @var CRM_Core_Form $form
    *
@@ -156,15 +156,17 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
     );
 
     $config = CRM_Core_Config::singleton();
+    /** CRM-15883 Suppressing Stationery path field until we switch from DOMPDF to a library that supports it.
     if ($config->wkhtmltopdfPath == FALSE) {
-      $form->add(
-        'text',
-        'stationery',
-        ts('Stationery (relative path to PDF you wish to use as the background)'),
-        array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"),
-        FALSE
-      );
+    $form->add(
+    'text',
+    'stationery',
+    ts('Stationery (relative path to PDF you wish to use as the background)'),
+    array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"),
+    FALSE
+    );
     }
+     */
     $form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template'));
     $form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)'));
 
@@ -172,7 +174,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
     $form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?'));
     $form->assign('totalSelectedContacts', count($form->_contactIds));
 
-    CRM_Mailing_BAO_Mailing::commonLetterCompose($form);
+    CRM_Mailing_BAO_Mailing::commonCompose($form);
 
     $buttons = array();
     if ($form->get('action') != CRM_Core_Action::VIEW) {
@@ -192,7 +194,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * Set default values
+   * Set default values.
    */
   public static function setDefaultValues() {
     $defaultFormat = CRM_Core_BAO_PdfFormat::getDefaultValues();
@@ -201,7 +203,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * Form rule
+   * Form rule.
    *
    * @param array $fields
    *   The input form values.
@@ -211,7 +213,6 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
    *
    * @return bool
    *   TRUE if no errors, else array of errors.
-   *
    */
   public static function formRule($fields, $dontCare, $self) {
     $errors = array();
@@ -237,12 +238,13 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * Part of the post process which prepare and extract information from the template
+   * Part of the post process which prepare and extract information from the template.
    *
    *
    * @param CRM_Core_Form $form
    *
-   * @return array( $categories, $html_message, $messageToken, $returnProperties )
+   * @return array
+   *   [$categories, $html_message, $messageToken, $returnProperties]
    */
   static protected function processMessageTemplate(&$form) {
     $formValues = $form->controller->exportValues($form->getName());
@@ -311,7 +313,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * Process the form after the input has been submitted and validated
+   * Process the form after the input has been submitted and validated.
    *
    *
    * @param CRM_Core_Form $form
@@ -371,10 +373,10 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
    */
   public static function createActivities($form, $html_message, $contactIds) {
     //Added for CRM-12682: Add activity subject and campaign fields
-    $formValues     = $form->controller->exportValues($form->getName());
+    $formValues = $form->controller->exportValues($form->getName());
 
-    $session        = CRM_Core_Session::singleton();
-    $userID         = $session->get('userID');
+    $session = CRM_Core_Session::singleton();
+    $userID = $session->get('userID');
     $activityTypeID = CRM_Core_OptionGroup::getValue(
       'activity_type',
       'Print PDF Letter',
@@ -393,6 +395,10 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
     }
     if ($form->_cid) {
       $activity = CRM_Activity_BAO_Activity::create($activityParams);
+      if (!empty($form->_caseId)) {
+        $caseActivityParams = array('activity_id' => $activity->id, 'case_id' => $form->_caseId);
+        CRM_Case_BAO_Case::processCaseActivity($caseActivityParams);
+      }
     }
     else {
       // create  Print PDF activity for each selected contact. CRM-6886
@@ -440,8 +446,8 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
         $matches = array();
         if (preg_match('/^( )+/', $msg, $matches)) {
           $spaceLen = strlen($matches[0]) / 6;
-          $trimMsg  = ltrim($msg, '  ');
-          $charLen  = strlen($trimMsg);
+          $trimMsg = ltrim($msg, '  ');
+          $charLen = strlen($trimMsg);
           $totalLen = $charLen + $spaceLen;
           if ($totalLen > 100) {
             $spacesCount = 10;
@@ -459,4 +465,5 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
     }
     $message = implode($newLineOperators['p']['oper'], $htmlMsg);
   }
+
 }