From 78b22ce9c130c19537eb3fa6b04725c5fe215ee6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 8 Nov 2017 07:44:57 -0500 Subject: [PATCH] CRM-21406 - Standalone export form ---------------------------------------- * CRM-21406: Create Standalone Export Form https://issues.civicrm.org/jira/browse/CRM-21406 --- CRM/Contact/Form/Task.php | 4 +- CRM/Contact/Task.php | 7 +- CRM/Core/xml/Menu/Misc.xml | 5 ++ CRM/Export/Controller/Standalone.php | 94 ++++++++++++++++++++++++++ CRM/Export/Form/Map.php | 2 +- CRM/Export/Form/Select.php | 58 +++++----------- CRM/Export/StateMachine/Standalone.php | 68 +++++++++++++++++++ 7 files changed, 193 insertions(+), 45 deletions(-) create mode 100644 CRM/Export/Controller/Standalone.php create mode 100644 CRM/Export/StateMachine/Standalone.php diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php index 8b8b9e2887..0d33c818c9 100644 --- a/CRM/Contact/Form/Task.php +++ b/CRM/Contact/Form/Task.php @@ -100,13 +100,13 @@ class CRM_Contact_Form_Task extends CRM_Core_Form { $form->_contactIds = array(); $form->_contactTypes = array(); - $isStandAlone = in_array('task', $form->urlPath); + $isStandAlone = in_array('task', $form->urlPath) || in_array('standalone', $form->urlPath); if ($isStandAlone) { list($form->_task, $title) = CRM_Contact_Task::getTaskAndTitleByClass(get_class($form)); if (!array_key_exists($form->_task, CRM_Contact_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()))) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } - $form->_contactIds = explode(',', CRM_Utils_Request::retrieve('cids', 'String', $form, TRUE)); + $form->_contactIds = explode(',', CRM_Utils_Request::retrieve('cids', 'CommaSeparatedIntegers', $form, TRUE)); if (empty($form->_contactIds)) { CRM_Core_Error::statusBounce(ts('No Contacts Selected')); } diff --git a/CRM/Contact/Task.php b/CRM/Contact/Task.php index d5afbac86d..99f3a790a5 100644 --- a/CRM/Contact/Task.php +++ b/CRM/Contact/Task.php @@ -77,6 +77,11 @@ class CRM_Contact_Task { */ static $_optionalTasks = NULL; + public static function tasks() { + self::initTasks(); + return self::$_tasks; + } + public static function initTasks() { if (!self::$_tasks) { self::$_tasks = array( @@ -398,7 +403,7 @@ class CRM_Contact_Task { self::initTasks(); foreach (self::$_tasks as $task => $value) { - if (!empty($value['url']) && ( + if ((!empty($value['url']) || $task == self::EXPORT_CONTACTS) && ( (is_array($value['class']) && in_array($className, $value['class'])) || ($value['class'] == $className) ) diff --git a/CRM/Core/xml/Menu/Misc.xml b/CRM/Core/xml/Menu/Misc.xml index ba07d574c2..4ac4add067 100644 --- a/CRM/Core/xml/Menu/Misc.xml +++ b/CRM/Core/xml/Menu/Misc.xml @@ -17,6 +17,11 @@ Export Contacts 0 + + civicrm/export/standalone + Export + CRM_Export_Controller_Standalone + civicrm/admin/options/acl_role ACL Roles diff --git a/CRM/Export/Controller/Standalone.php b/CRM/Export/Controller/Standalone.php new file mode 100644 index 0000000000..c2540dcd70 --- /dev/null +++ b/CRM/Export/Controller/Standalone.php @@ -0,0 +1,94 @@ +set('entity', $entity); + $id = explode(',', CRM_Utils_Request::retrieve('id', 'CommaSeparatedIntegers', $this, TRUE)); + + // Check permissions + $perm = civicrm_api3($entity, 'get', array( + 'return' => 'id', + 'options' => array('limit' => 0), + 'check_permissions' => 1, + 'id' => array('IN' => $id), + )); + + $this->set('id', implode(',', array_keys($perm['values']))); + if ($entity == 'Contact') { + $this->set('cids', implode(',', array_keys($perm['values']))); + } + + $this->_stateMachine = new CRM_Export_StateMachine_Standalone($this, $action); + + // create and instantiate the pages + $this->addPages($this->_stateMachine, $action); + + // add all the actions + $this->addActions(); + } + + /** + * + * + * @param string $pageName + * @return array + */ + public function exportValues($pageName = NULL) { + $values = parent::exportValues(); + $values['radio_ts'] = 'ts_sel'; + foreach (explode(',', $this->get('id')) as $id) { + if ($id) { + $values[CRM_Core_Form::CB_PREFIX . $id] = 1; + } + } + $className = 'CRM_' . $this->get('entity') . '_Task'; + foreach ($className::tasks() as $taskId => $task) { + $taskForm = (array) $task['class']; + if ($taskForm[0] == 'CRM_Export_Form_Select') { + $values['task'] = $taskId; + } + } + return $values; + } + +} diff --git a/CRM/Export/Form/Map.php b/CRM/Export/Form/Map.php index d9c35180d2..066401d568 100644 --- a/CRM/Export/Form/Map.php +++ b/CRM/Export/Form/Map.php @@ -237,7 +237,7 @@ class CRM_Export_Form_Map extends CRM_Core_Form { //get the csv file CRM_Export_BAO_Export::exportComponents($this->get('selectAll'), $this->get('componentIds'), - $this->get('queryParams'), + (array) $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), $mapperKeys, $this->get('returnProperties'), diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php index 72fff69296..d7f0c22f08 100644 --- a/CRM/Export/Form/Select.php +++ b/CRM/Export/Form/Select.php @@ -92,6 +92,10 @@ class CRM_Export_Form_Select extends CRM_Core_Form { $this->_componentIds = array(); $this->_componentClause = NULL; + $stateMachine = $this->controller->getStateMachine(); + $formName = CRM_Utils_System::getClassName($stateMachine); + $isStandalone = $formName == 'CRM_Export_StateMachine_Standalone'; + // get the submitted values based on search if ($this->_action == CRM_Core_Action::ADVANCED) { $values = $this->controller->exportValues('Advanced'); @@ -104,45 +108,17 @@ class CRM_Export_Form_Select extends CRM_Core_Form { } else { // we need to determine component export - $stateMachine = $this->controller->getStateMachine(); - - $formName = CRM_Utils_System::getClassName($stateMachine); $componentName = explode('_', $formName); $components = array('Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity'); - if (in_array($componentName[1], $components)) { - switch ($componentName[1]) { - case 'Contribute': - $this->_exportMode = self::CONTRIBUTE_EXPORT; - break; - - case 'Member': - $this->_exportMode = self::MEMBER_EXPORT; - break; - - case 'Event': - $this->_exportMode = self::EVENT_EXPORT; - break; - - case 'Pledge': - $this->_exportMode = self::PLEDGE_EXPORT; - break; - - case 'Case': - $this->_exportMode = self::CASE_EXPORT; - break; - - case 'Grant': - $this->_exportMode = self::GRANT_EXPORT; - break; - - case 'Activity': - $this->_exportMode = self::ACTIVITY_EXPORT; - break; - } + 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"; - $className::preProcessCommon($this, TRUE); + $className::preProcessCommon($this, !$isStandalone); $values = $this->controller->exportValues('Search'); } else { @@ -167,31 +143,31 @@ class CRM_Export_Form_Select extends CRM_Core_Form { $componentMode = $this->get('component_mode'); switch ($componentMode) { case 2: - CRM_Contribute_Form_Task::preProcessCommon($this, TRUE); + CRM_Contribute_Form_Task::preProcessCommon($this, !$isStandalone); $this->_exportMode = self::CONTRIBUTE_EXPORT; $componentName = array('', 'Contribute'); break; case 3: - CRM_Event_Form_Task::preProcessCommon($this, TRUE); + CRM_Event_Form_Task::preProcessCommon($this, !$isStandalone); $this->_exportMode = self::EVENT_EXPORT; $componentName = array('', 'Event'); break; case 4: - CRM_Activity_Form_Task::preProcessCommon($this, TRUE); + CRM_Activity_Form_Task::preProcessCommon($this, !$isStandalone); $this->_exportMode = self::ACTIVITY_EXPORT; $componentName = array('', 'Activity'); break; case 5: - CRM_Member_Form_Task::preProcessCommon($this, TRUE); + CRM_Member_Form_Task::preProcessCommon($this, !$isStandalone); $this->_exportMode = self::MEMBER_EXPORT; $componentName = array('', 'Member'); break; case 6: - CRM_Case_Form_Task::preProcessCommon($this, TRUE); + CRM_Case_Form_Task::preProcessCommon($this, !$isStandalone); $this->_exportMode = self::CASE_EXPORT; $componentName = array('', 'Case'); break; @@ -202,7 +178,7 @@ class CRM_Export_Form_Select extends CRM_Core_Form { $contactTasks = CRM_Contact_Task::taskTitles(); $taskName = $contactTasks[$this->_task]; $component = FALSE; - CRM_Contact_Form_Task::preProcessCommon($this, TRUE); + CRM_Contact_Form_Task::preProcessCommon($this, !$isStandalone); } else { $this->assign('taskName', "Export $componentName[1]"); @@ -420,7 +396,7 @@ FROM {$this->_componentTable} if ($exportOption == self::EXPORT_ALL) { CRM_Export_BAO_Export::exportComponents($this->_selectAll, $this->_componentIds, - $this->get('queryParams'), + (array) $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), NULL, $this->get('returnProperties'), diff --git a/CRM/Export/StateMachine/Standalone.php b/CRM/Export/StateMachine/Standalone.php new file mode 100644 index 0000000000..64d7d1a3c6 --- /dev/null +++ b/CRM/Export/StateMachine/Standalone.php @@ -0,0 +1,68 @@ +_pages = array( + 'CRM_Export_Form_Select' => NULL, + 'CRM_Export_Form_Map' => NULL, + ); + + $this->addSequentialPages($this->_pages, $action); + } + + /** + * @todo So far does nothing. + * + * @return string + */ + public function getTaskFormName() { + return ''; + } + + /** + * @todo not sure if this is needed + */ + public function shouldReset() { + return FALSE; + } + +} -- 2.25.1