Fix Case form task regressions (export/print not working) since we switched to using...
authorMatthew Wire <devel@mrwire.co.uk>
Wed, 4 Apr 2018 11:51:12 +0000 (12:51 +0100)
committerMatthew Wire <devel@mrwire.co.uk>
Mon, 7 May 2018 06:07:12 +0000 (07:07 +0100)
CRM/Case/Form/Task.php
CRM/Case/Form/Task/Delete.php
CRM/Case/Form/Task/PDF.php
CRM/Case/Form/Task/Restore.php
CRM/Case/Form/Task/SearchTaskHookSample.php
CRM/Core/DAO.php
CRM/Core/Form/Task.php

index bba76dc1e6ac67c922a6718770b65efb6b8e867d..b9d05e68758cb3a7419117fcbc53d5b20386617e 100644 (file)
@@ -40,80 +40,6 @@ class CRM_Case_Form_Task extends CRM_Core_Form_Task {
   // Must be set to entity shortname (eg. event)
   static $entityShortname = 'case';
 
-  /**
-   * Deprecated copy of $_entityIds
-   *
-   * @var array
-   * @deprecated
-   */
-  public $_caseIds;
-
-  /**
-   * Build all the data structures needed to build the form.
-   */
-  public function preProcess() {
-    self::preProcessCommon($this);
-  }
-
-  /**
-   * @param CRM_Core_Form $form
-   */
-  public static function preProcessCommon(&$form) {
-    $form->_caseIds = array();
-
-    $values = $form->controller->exportValues($form->get('searchFormName'));
-
-    $form->_task = $values['task'];
-    $caseTasks = CRM_Case_Task::tasks();
-    $form->assign('taskName', $caseTasks[$form->_task]);
-
-    $ids = array();
-    if ($values['radio_ts'] == 'ts_sel') {
-      foreach ($values as $name => $value) {
-        if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
-          $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
-        }
-      }
-    }
-    else {
-      $queryParams = $form->get('queryParams');
-      $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
-        CRM_Contact_BAO_Query::MODE_CASE
-      );
-      $query->_distinctComponentClause = " ( civicrm_case.id )";
-      $query->_groupByComponentClause = " GROUP BY civicrm_case.id ";
-      $result = $query->searchQuery(0, 0, NULL);
-      while ($result->fetch()) {
-        $ids[] = $result->case_id;
-      }
-    }
-
-    if (!empty($ids)) {
-      $form->_componentClause = ' civicrm_case.id IN ( ' . implode(',', $ids) . ' ) ';
-      $form->assign('totalSelectedCases', count($ids));
-    }
-
-    $form->_caseIds = $form->_entityIds = $form->_componentIds = $ids;
-
-    //set the context for redirection for any task actions
-    $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
-    $urlParams = 'force=1';
-    if (CRM_Utils_Rule::qfKey($qfKey)) {
-      $urlParams .= "&qfKey=$qfKey";
-    }
-
-    $session = CRM_Core_Session::singleton();
-    $searchFormName = strtolower($form->get('searchFormName'));
-    if ($searchFormName == 'search') {
-      $session->replaceUserContext(CRM_Utils_System::url('civicrm/case/search', $urlParams));
-    }
-    else {
-      $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/$searchFormName",
-        $urlParams
-      ));
-    }
-  }
-
   /**
    * @inheritDoc
    */
index ef6fbf7dc416b96b7a8889d5d1b7aaf2ced3c51d..df6a109fadfb8a9da2cf2493199e336d95948004 100644 (file)
@@ -73,7 +73,7 @@ class CRM_Case_Form_Task_Delete extends CRM_Case_Form_Task {
    */
   public function postProcess() {
     $deleted = $failed = 0;
-    foreach ($this->_caseIds as $caseId) {
+    foreach ($this->_entityIds as $caseId) {
       if (CRM_Case_BAO_Case::deleteCase($caseId, $this->_moveToTrash)) {
         $deleted++;
       }
index c2820d7b0a215286ad60ab79c53cccb3d098f4ce..71aa8ff65616829f41b4bebae8373640d17d89c6 100644 (file)
@@ -86,7 +86,7 @@ class CRM_Case_Form_Task_PDF extends CRM_Case_Form_Task {
    */
   public function listTokens() {
     $tokens = CRM_Core_SelectValues::contactTokens();
-    foreach ($this->_componentIds as $key => $caseId) {
+    foreach ($this->_entityIds as $key => $caseId) {
       $caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'case_type_id');
       $tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
     }
index 4d446003c7139ad5cc90a413900c009f948f48d8..1e7509156a149cdc3f1d46ce9cd5926519fb89a2 100644 (file)
@@ -63,7 +63,7 @@ class CRM_Case_Form_Task_Restore extends CRM_Case_Form_Task {
    */
   public function postProcess() {
     $restoredCases = $failed = 0;
-    foreach ($this->_caseIds as $caseId) {
+    foreach ($this->_entityIds as $caseId) {
       if (CRM_Case_BAO_Case::restoreCase($caseId)) {
         $restoredCases++;
       }
index 09822cd0750491f7b5f55b881903d3b88a50d12f..0cb7f7ac6782f406721842b18285f402abf49090 100644 (file)
@@ -44,7 +44,7 @@ class CRM_Case_Form_Task_SearchTaskHookSample extends CRM_Case_Form_Task {
     parent::preProcess();
     $rows = array();
     // display name and email of all contact ids
-    $caseIDs = implode(',', $this->_caseIds);
+    $caseIDs = implode(',', $this->_entityIds);
     $statusId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'case_status', 'id', 'name');
     $query = "
 SELECT ct.display_name as display_name,
index d7e148051eee208bbe99b1c10a186ed7acb79658..12af2b3c403a4c7456107c66905a9aea04a6d79d 100644 (file)
@@ -1686,6 +1686,7 @@ FROM   civicrm_domain
    * @param $componentIDs
    * @param string $tableName
    * @param string $idField
+   *
    * @return array
    */
   public static function getContactIDsFromComponent($componentIDs, $tableName, $idField = 'id') {
index 3e8c20552cb104fcfe5ef11c60558e3db0e328b2..b558193e95d8f16b1d9201c76248d59dd677f75e 100644 (file)
@@ -77,16 +77,30 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form {
 
   /**
    * Build all the data structures needed to build the form.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function preProcess() {
-    $this->_entityIds = array();
+    self::preProcessCommon($this);
+  }
+
+  /**
+   * Common pre-processing function.
+   *
+   * @param CRM_Core_Form $form
+   * @param bool $useTable FIXME This parameter could probably be deprecated as it's not used here
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public static function preProcessCommon(&$form, $useTable = FALSE) {
+    $form->_entityIds = array();
 
-    $values = $this->controller->exportValues($this->get('searchFormName'));
+    $values = $form->controller->exportValues($form->get('searchFormName'));
 
-    $this->_task = $values['task'];
-    $className = 'CRM_' . ucfirst($this::$entityShortname) . '_Task';
+    $form->_task = $values['task'];
+    $className = 'CRM_' . ucfirst($form::$entityShortname) . '_Task';
     $entityTasks = $className::tasks();
-    $this->assign('taskName', $entityTasks[$this->_task]);
+    $form->assign('taskName', $entityTasks[$form->_task]);
 
     $ids = array();
     if ($values['radio_ts'] == 'ts_sel') {
@@ -97,42 +111,42 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form {
       }
     }
     else {
-      $queryParams = $this->get('queryParams');
+      $queryParams = $form->get('queryParams');
       $sortOrder = NULL;
-      if ($this->get(CRM_Utils_Sort::SORT_ORDER)) {
-        $sortOrder = $this->get(CRM_Utils_Sort::SORT_ORDER);
+      if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
+        $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
       }
 
       $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
         CRM_Contact_BAO_Query::MODE_CASE
       );
-      $query->_distinctComponentClause = " ( " . $this::$tableName . ".id )";
-      $query->_groupByComponentClause = " GROUP BY " . $this::$tableName . ".id ";
+      $query->_distinctComponentClause = " ( " . $form::$tableName . ".id )";
+      $query->_groupByComponentClause = " GROUP BY " . $form::$tableName . ".id ";
       $result = $query->searchQuery(0, 0, $sortOrder);
-      $selector = $this::$entityShortname . '_id';
+      $selector = $form::$entityShortname . '_id';
       while ($result->fetch()) {
         $ids[] = $result->$selector;
       }
     }
 
     if (!empty($ids)) {
-      $this->_componentClause = ' ' . $this::$tableName . '.id IN ( ' . implode(',', $ids) . ' ) ';
-      $this->assign('totalSelected' . ucfirst($this::$entityShortname) . 's', count($ids));
+      $form->_componentClause = ' ' . $form::$tableName . '.id IN ( ' . implode(',', $ids) . ' ) ';
+      $form->assign('totalSelected' . ucfirst($form::$entityShortname) . 's', count($ids));
     }
 
-    $this->_entityIds = $this->_componentIds = $ids;
+    $form->_entityIds = $form->_componentIds = $ids;
 
     //set the context for redirection for any task actions
-    $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
+    $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
     $urlParams = 'force=1';
     if (CRM_Utils_Rule::qfKey($qfKey)) {
       $urlParams .= "&qfKey=$qfKey";
     }
 
     $session = CRM_Core_Session::singleton();
-    $searchFormName = strtolower($this->get('searchFormName'));
+    $searchFormName = strtolower($form->get('searchFormName'));
     if ($searchFormName == 'search') {
-      $session->replaceUserContext(CRM_Utils_System::url('civicrm/' . $this::$entityShortname . '/search', $urlParams));
+      $session->replaceUserContext(CRM_Utils_System::url('civicrm/' . $form::$entityShortname . '/search', $urlParams));
     }
     else {
       $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/$searchFormName",
@@ -142,8 +156,8 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form {
   }
 
   /**
-   * Given the signer id, compute the contact id
-   * since its used for things like send email
+   * Given the entity id, compute the contact id since its used for things like send email
+   * For example, for cases we need to override this function as the table name is civicrm_case_contact
    */
   public function setContactIDs() {
     $this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_entityIds,