From a017474338693116bd03b3f8b0c09fadb3848915 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Fri, 15 Jun 2018 10:23:33 +0100 Subject: [PATCH] Non functional changes towards shared functions in Core_Form_Task --- CRM/Case/Form/Task.php | 16 ++++++++------ CRM/Contact/Form/Task.php | 2 ++ CRM/Core/Form/Task.php | 21 ++++++++++-------- CRM/Export/Form/Select.php | 44 ++++++++++++++++++++++---------------- 4 files changed, 49 insertions(+), 34 deletions(-) diff --git a/CRM/Case/Form/Task.php b/CRM/Case/Form/Task.php index 398cdffd044d..513ee62e0502 100644 --- a/CRM/Case/Form/Task.php +++ b/CRM/Case/Form/Task.php @@ -40,13 +40,6 @@ 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 */ @@ -56,4 +49,13 @@ public function setContactIDs() { ); } + /** + * Get the query mode (eg. CRM_Core_BAO_Query::MODE_CASE) + * + * @return int + */ + public function getQueryMode() { + return CRM_Contact_BAO_Query::MODE_CASE; + } + } diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php index 2ccf1552eb88..493bd759cbac 100644 --- a/CRM/Contact/Form/Task.php +++ b/CRM/Contact/Form/Task.php @@ -94,6 +94,8 @@ public function preProcess() { * Common pre-processing function. * * @param CRM_Core_Form $form + * + * @throws \CRM_Core_Exception */ public static function preProcessCommon(&$form) { $form->_contactIds = array(); diff --git a/CRM/Core/Form/Task.php b/CRM/Core/Form/Task.php index d842232921ad..41a8912ba2c8 100644 --- a/CRM/Core/Form/Task.php +++ b/CRM/Core/Form/Task.php @@ -84,13 +84,6 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form { */ 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. * @@ -103,7 +96,7 @@ public function preProcess() { /** * Common pre-processing function. * - * @param CRM_Core_Form $form + * @param CRM_Core_Form_Task $form * * @throws \CRM_Core_Exception */ @@ -132,7 +125,7 @@ public static function preProcessCommon(&$form) { $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); } - $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, $form::$queryMode); + $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, $form->getQueryMode()); $query->_distinctComponentClause = " ( " . $form::$tableName . ".id )"; $query->_groupByComponentClause = " GROUP BY " . $form::$tableName . ".id "; $result = $query->searchQuery(0, 0, $sortOrder); @@ -210,4 +203,14 @@ public function addDefaultButtons($title, $nextType = 'next', $backType = 'back' ); } + /** + * Get the query mode (eg. CRM_Core_BAO_Query::MODE_CASE) + * Should be overridden by child classes in most cases + * + * @return int + */ + public function getQueryMode() { + return CRM_Contact_BAO_Query::MODE_CONTACTS; + } + } diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php index 64998a52c708..a44149c66649 100644 --- a/CRM/Export/Form/Select.php +++ b/CRM/Export/Form/Select.php @@ -94,23 +94,14 @@ public function preProcess() { $this->_componentIds = array(); $this->_componentClause = NULL; - $stateMachine = $this->controller->getStateMachine(); - $formName = CRM_Utils_System::getClassName($stateMachine); - $isStandalone = $formName == 'CRM_Export_StateMachine_Standalone'; - // we need to determine component export - $componentName = explode('_', $formName); $components = array('Contact', 'Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity'); - if ($isStandalone) { - $componentName = array('CRM', $this->controller->get('entity')); - } - - $componentMode = $this->controller->get('component_mode'); // FIXME: This should use a modified version of CRM_Contact_Form_Search::getModeValue but it doesn't have all the contexts - switch ($componentMode) { + switch ($this->getQueryMode()) { case CRM_Contact_BAO_Query::MODE_CONTRIBUTE: $entityShortname = 'Contribute'; + $entityDAOName = $entityShortname; break; case CRM_Contact_BAO_Query::MODE_MEMBER: @@ -120,33 +111,41 @@ public function preProcess() { case CRM_Contact_BAO_Query::MODE_EVENT: $entityShortname = 'Event'; + $entityDAOName = $entityShortname; break; case CRM_Contact_BAO_Query::MODE_PLEDGE: $entityShortname = 'Pledge'; + $entityDAOName = $entityShortname; break; case CRM_Contact_BAO_Query::MODE_CASE: $entityShortname = 'Case'; + $entityDAOName = $entityShortname; break; case CRM_Contact_BAO_Query::MODE_GRANT: $entityShortname = 'Grant'; + $entityDAOName = $entityShortname; break; case CRM_Contact_BAO_Query::MODE_ACTIVITY: $entityShortname = 'Activity'; + $entityDAOName = $entityShortname; break; default: + // FIXME: Code cleanup, we may not need to do this $componentName code here. + $formName = CRM_Utils_System::getClassName($this->controller->getStateMachine()); + $componentName = explode('_', $formName); + if ($formName == 'CRM_Export_StateMachine_Standalone') { + $componentName = array('CRM', $this->controller->get('entity')); + } $entityShortname = $componentName[1]; // Contact + $entityDAOName = $entityShortname; break; } - if (empty($entityDAOName)) { - $entityDAOName = $entityShortname; - } - if (in_array($entityShortname, $components)) { $this->_exportMode = constant('CRM_Export_Form_Select::' . strtoupper($entityShortname) . '_EXPORT'); $formTaskClassName = "CRM_{$entityShortname}_Form_Task"; @@ -196,7 +195,7 @@ public function preProcess() { } } - $formTaskClassName::preProcessCommon($this, !$isStandalone); + $formTaskClassName::preProcessCommon($this); // $component is used on CRM/Export/Form/Select.tpl to display extra information for contact export ($this->_exportMode == self::CONTACT_EXPORT) ? $component = FALSE : $component = TRUE; @@ -344,7 +343,7 @@ public function buildQuickForm() { * @return bool|array * mixed true or array of errors */ - static public function formRule($params, $files, $self) { + public static function formRule($params, $files, $self) { $errors = array(); if (CRM_Utils_Array::value('mergeOption', $params) == self::EXPORT_MERGE_SAME_ADDRESS && @@ -372,7 +371,7 @@ static public function formRule($params, $files, $self) { /** * Process the uploaded file. * - * @return void + * @throws \CRM_Core_Exception */ public function postProcess() { $params = $this->controller->exportValues($this->_name); @@ -521,4 +520,13 @@ public static function getGreetingOptions() { return $options; } + /** + * Get the query mode (eg. CRM_Core_BAO_Query::MODE_CASE) + * + * @return int + */ + public function getQueryMode() { + return (int) $this->controller->get('component_mode'); + } + }