From fe841bdf359f426b314b7410866933050fcbd465 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Fri, 1 Jun 2018 11:53:16 +0100 Subject: [PATCH] NFC code cleanup to core task class --- CRM/Case/Form/Task.php | 7 ++++++ CRM/Core/Form/Task.php | 49 ++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/CRM/Case/Form/Task.php b/CRM/Case/Form/Task.php index b9d05e68758c..398cdffd044d 100644 --- a/CRM/Case/Form/Task.php +++ b/CRM/Case/Form/Task.php @@ -40,6 +40,13 @@ class CRM_Case_Form_Task extends CRM_Core_Form_Task { // Must be set to entity shortname (eg. event) static $entityShortname = 'case'; + /** + * Must be set to queryMode + * + * @var int + */ + static $queryMode = CRM_Contact_BAO_Query::MODE_CASE; + /** * @inheritDoc */ diff --git a/CRM/Core/Form/Task.php b/CRM/Core/Form/Task.php index 2a487ba70f1d..d842232921ad 100644 --- a/CRM/Core/Form/Task.php +++ b/CRM/Core/Form/Task.php @@ -70,11 +70,27 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form { */ public $_contactIds; - // Must be set to entity table name (eg. civicrm_participant) by child class + /** + * Must be set to entity table name (eg. civicrm_participant) by child class + * + * @var string + */ static $tableName = NULL; - // Must be set to entity shortname (eg. event) + + /** + * Must be set to entity shortname (eg. event) + * + * @var string + */ static $entityShortname = NULL; + /** + * Must be set to queryMode + * + * @var int + */ + static $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS; + /** * Build all the data structures needed to build the form. * @@ -88,25 +104,24 @@ public function preProcess() { * 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) { + public static function preProcessCommon(&$form) { $form->_entityIds = array(); - $values = $form->controller->exportValues($form->get('searchFormName')); + $searchFormValues = $form->controller->exportValues($form->get('searchFormName')); - $form->_task = $values['task']; + $form->_task = $searchFormValues['task']; $className = 'CRM_' . ucfirst($form::$entityShortname) . '_Task'; $entityTasks = $className::tasks(); $form->assign('taskName', $entityTasks[$form->_task]); - $ids = array(); - if ($values['radio_ts'] == 'ts_sel') { - foreach ($values as $name => $value) { + $entityIds = array(); + if ($searchFormValues['radio_ts'] == 'ts_sel') { + foreach ($searchFormValues 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); + $entityIds[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } @@ -117,24 +132,22 @@ public static function preProcessCommon(&$form, $useTable = FALSE) { $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 = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, $form::$queryMode); $query->_distinctComponentClause = " ( " . $form::$tableName . ".id )"; $query->_groupByComponentClause = " GROUP BY " . $form::$tableName . ".id "; $result = $query->searchQuery(0, 0, $sortOrder); $selector = $form::$entityShortname . '_id'; while ($result->fetch()) { - $ids[] = $result->$selector; + $entityIds[] = $result->$selector; } } - if (!empty($ids)) { - $form->_componentClause = ' ' . $form::$tableName . '.id IN ( ' . implode(',', $ids) . ' ) '; - $form->assign('totalSelected' . ucfirst($form::$entityShortname) . 's', count($ids)); + if (!empty($entityIds)) { + $form->_componentClause = ' ' . $form::$tableName . '.id IN ( ' . implode(',', $entityIds) . ' ) '; + $form->assign('totalSelected' . ucfirst($form::$entityShortname) . 's', count($entityIds)); } - $form->_entityIds = $form->_componentIds = $ids; + $form->_entityIds = $form->_componentIds = $entityIds; // Some functions (eg. PDF letter tokens) rely on Ids being in specific fields rather than the generic $form->_entityIds // So we set that specific field here (eg. for cases $form->_caseIds = $form->_entityIds).