From: Matthew Wire Date: Mon, 7 May 2018 08:24:09 +0000 (+0100) Subject: Further fixes to export X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3b4adc92793dccfa446cf66f0740edb543f110d7;p=civicrm-core.git Further fixes to export --- diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php index ea0af70929..408aee39cc 100644 --- a/CRM/Export/Form/Select.php +++ b/CRM/Export/Form/Select.php @@ -112,6 +112,67 @@ class CRM_Export_Form_Select extends CRM_Core_Form { $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) { + case CRM_Contact_BAO_Query::MODE_CONTRIBUTE: + $entityShortname = 'Contribute'; + break; + + case CRM_Contact_BAO_Query::MODE_MEMBER: + $entityShortname = 'Member'; + $entityDAOName = 'Membership'; + break; + + case CRM_Contact_BAO_Query::MODE_EVENT: + $entityShortname = 'Event'; + break; + + case CRM_Contact_BAO_Query::MODE_PLEDGE: + $entityShortname = 'Pledge'; + break; + + case CRM_Contact_BAO_Query::MODE_CASE: + $entityShortname = 'Case'; + break; + + case CRM_Contact_BAO_Query::MODE_GRANT: + $entityShortname = 'Grant'; + break; + + case CRM_Contact_BAO_Query::MODE_ACTIVITY: + $entityShortname = 'Activity'; + break; + + default: + $entityShortname = $componentName[1]; // Contact + break; + } + + if (in_array($entityShortname, $components)) { + $this->_exportMode = constant('CRM_Export_Form_Select::' . strtoupper($entityShortname) . '_EXPORT'); + $formTaskClassName = "CRM_{$entityShortname}_Form_Task"; + $taskClassName = "CRM_{$entityShortname}_Task"; + if (isset($formTaskClassName::$entityShortname)) { + $this::$entityShortname = $formTaskClassName::$entityShortname; + if (isset($formTaskClassName::$tableName)) { + $this::$tableName = $formTaskClassName::$tableName; + } + } + else { + $this::$entityShortname = $entityShortname; + $this::$tableName = CRM_Core_DAO_AllCoreTables::getTableForClass(CRM_Core_DAO_AllCoreTables::getFullName($entityDAOName)); + } + } + // get the submitted values based on search if ($this->_action == CRM_Core_Action::ADVANCED) { $values = $this->controller->exportValues('Advanced'); @@ -123,20 +184,7 @@ class CRM_Export_Form_Select extends CRM_Core_Form { $values = $this->controller->exportValues('Custom'); } else { - // we need to determine component export - $componentName = explode('_', $formName); - $components = array('Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity'); - - if ($isStandalone) { - $componentName = array('CRM', $this->controller->get('entity')); - } - - if (in_array($componentName[1], $components)) { - $this->_exportMode = constant('CRM_Export_Form_Select::' . strtoupper($componentName[1]) . '_EXPORT'); - $className = "CRM_{$componentName[1]}_Form_Task"; - $this::$entityShortname = $className::$entityShortname; - $this::$tableName = $className::$tableName; - $className::preProcessCommon($this, !$isStandalone); + if (in_array($entityShortname, $components)) { $values = $this->controller->exportValues('Search'); } else { @@ -158,53 +206,17 @@ class CRM_Export_Form_Select extends CRM_Core_Form { } } - $componentMode = $this->get('component_mode'); - switch ($componentMode) { - case 2: - CRM_Contribute_Form_Task::preProcessCommon($this, !$isStandalone); - $this->_exportMode = self::CONTRIBUTE_EXPORT; - $componentName = array('', 'Contribute'); - break; - - case 3: - CRM_Event_Form_Task::preProcessCommon($this, !$isStandalone); - $this->_exportMode = self::EVENT_EXPORT; - $componentName = array('', 'Event'); - break; - - case 4: - CRM_Activity_Form_Task::preProcessCommon($this, !$isStandalone); - $this->_exportMode = self::ACTIVITY_EXPORT; - $componentName = array('', 'Activity'); - break; - - case 5: - CRM_Member_Form_Task::preProcessCommon($this, !$isStandalone); - $this->_exportMode = self::MEMBER_EXPORT; - $componentName = array('', 'Member'); - break; + $formTaskClassName::preProcessCommon($this, !$isStandalone); - case 6: - CRM_Case_Form_Task::preProcessCommon($this, !$isStandalone); - $this->_exportMode = self::CASE_EXPORT; - $componentName = array('', 'Case'); - break; - } + // $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; + $this->assign('component', $component); + // Set the task title + $componentTasks = $taskClassName::taskTitles(); $this->_task = $values['task']; - if ($this->_exportMode == self::CONTACT_EXPORT) { - $contactTasks = CRM_Contact_Task::taskTitles(); - $taskName = $contactTasks[$this->_task]; - $component = FALSE; - CRM_Contact_Form_Task::preProcessCommon($this, !$isStandalone); - } - else { - $this->assign('taskName', "Export $componentName[1]"); - $className = "CRM_{$componentName[1]}_Task"; - $componentTasks = $className::tasks(); - $taskName = $componentTasks[$this->_task]; - $component = TRUE; - } + $taskName = $componentTasks[$this->_task]; + $this->assign('taskName', $taskName); if ($this->_componentTable) { $query = " @@ -217,8 +229,7 @@ FROM {$this->_componentTable} $totalSelectedRecords = count($this->_componentIds); } $this->assign('totalSelectedRecords', $totalSelectedRecords); - $this->assign('taskName', $taskName); - $this->assign('component', $component); + // all records actions = save a search if (($values['radio_ts'] == 'ts_all') || ($this->_task == CRM_Contact_Task::SAVE_SEARCH)) { $this->_selectAll = TRUE;