Ejemplo n.º 1
0
 /**
  * Basic test to ensure the exportComponents function can export selected fields for contribution.
  */
 public function testExportComponentsContribution()
 {
     $this->setUpContributionExportData();
     $selectedFields = array(array('Individual', 'first_name'), array('Individual', 'last_name'), array('Contribution', 'receive_date'), array('Contribution', 'contribution_source'), array('Individual', 'street_address', 1), array('Individual', 'city', 1), array('Individual', 'country', 1), array('Individual', 'email', 1), array('Contribution', 'trxn_id'));
     CRM_Export_BAO_Export::exportComponents(TRUE, $this->contributionIDs, array(), 'receive_date desc', $selectedFields, NULL, CRM_Export_Form_Select::CONTRIBUTE_EXPORT, 'civicrm_contribution.id IN ( ' . implode(',', $this->contributionIDs) . ')', NULL, FALSE, FALSE, array('exportOption' => CRM_Export_Form_Select::CONTRIBUTE_EXPORT, 'suppress_csv_for_testing' => TRUE));
 }
Ejemplo n.º 2
0
 /**
  * Process the uploaded file.
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $exportParams = $this->controller->exportValues('Select');
     $greetingOptions = CRM_Export_Form_Select::getGreetingOptions();
     if (!empty($greetingOptions)) {
         foreach ($greetingOptions as $key => $value) {
             if ($option = CRM_Utils_Array::value($key, $exportParams)) {
                 if ($greetingOptions[$key][$option] == ts('Other')) {
                     $exportParams[$key] = $exportParams["{$key}_other"];
                 } elseif ($greetingOptions[$key][$option] == ts('List of names')) {
                     $exportParams[$key] = '';
                 } else {
                     $exportParams[$key] = $greetingOptions[$key][$option];
                 }
             }
         }
     }
     $currentPath = CRM_Utils_System::currentPath();
     $urlParams = NULL;
     $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
     if (CRM_Utils_Rule::qfKey($qfKey)) {
         $urlParams = "&qfKey={$qfKey}";
     }
     //get the button name
     $buttonName = $this->controller->getButtonName('done');
     $buttonName1 = $this->controller->getButtonName('next');
     if ($buttonName == '_qf_Map_done') {
         $this->set('exportColumnCount', NULL);
         $this->controller->resetPage($this->_name);
         return CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, 'force=1' . $urlParams));
     }
     if ($this->controller->exportValue($this->_name, 'addMore')) {
         $this->set('exportColumnCount', $this->_exportColumnCount);
         return;
     }
     $mapperKeys = $params['mapper'][1];
     $checkEmpty = 0;
     foreach ($mapperKeys as $value) {
         if ($value[0]) {
             $checkEmpty++;
         }
     }
     if (!$checkEmpty) {
         $this->set('mappingId', NULL);
         CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, '_qf_Map_display=true' . $urlParams));
     }
     if ($buttonName1 == '_qf_Map_next') {
         if (!empty($params['updateMapping'])) {
             //save mapping fields
             CRM_Core_BAO_Mapping::saveMappingFields($params, $params['mappingId']);
         }
         if (!empty($params['saveMapping'])) {
             $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => $this->get('mappingTypeId'));
             $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
             //save mapping fields
             CRM_Core_BAO_Mapping::saveMappingFields($params, $saveMapping->id);
         }
     }
     //get the csv file
     CRM_Export_BAO_Export::exportComponents($this->get('selectAll'), $this->get('componentIds'), $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), $mapperKeys, $this->get('returnProperties'), $this->get('exportMode'), $this->get('componentClause'), $this->get('componentTable'), $this->get('mergeSameAddress'), $this->get('mergeSameHousehold'), $exportParams);
 }
Ejemplo n.º 3
0
 /**
  * Process the uploaded file
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $exportOption = $this->controller->exportValue($this->_name, 'exportOption');
     $merge_same_address = $this->controller->exportValue($this->_name, 'merge_same_address');
     $merge_same_household = $this->controller->exportValue($this->_name, 'merge_same_household');
     $mappingId = $this->controller->exportValue($this->_name, 'mapping');
     if ($mappingId) {
         $this->set('mappingId', $mappingId);
     } else {
         $this->set('mappingId', null);
     }
     $mergeSameAddress = $mergeSameHousehold = false;
     if ($merge_same_address['merge_same_address'] == 1) {
         $mergeSameAddress = true;
     }
     $this->set('mergeSameAddress', $mergeSameAddress);
     if ($merge_same_household['merge_same_household'] == 1) {
         $mergeSameHousehold = true;
     }
     $this->set('mergeSameHousehold', $mergeSameHousehold);
     if ($exportOption == self::EXPORT_ALL) {
         require_once "CRM/Export/BAO/Export.php";
         CRM_Export_BAO_Export::exportComponents($this->_selectAll, $this->_componentIds, $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), null, $this->get('returnProperties'), $this->_exportMode, $this->_componentClause, $this->_componentTable, $mergeSameAddress, $mergeSameHousehold);
     }
     //reset map page
     $this->controller->resetPage('Map');
 }
Ejemplo n.º 4
0
 /**
  * Process the uploaded file
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $exportOption = $this->controller->exportValue($this->_name, 'exportOption');
     $mappingId = $this->controller->exportValue($this->_name, 'mapping');
     if ($mappingId) {
         $this->set('mappingId', $mappingId);
     } else {
         $this->set('mappingId', null);
     }
     if ($exportOption == self::EXPORT_ALL) {
         require_once "CRM/Export/BAO/Export.php";
         CRM_Export_BAO_Export::exportComponents($this->_selectAll, $this->_componentIds, $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), null, $this->get('returnProperties'), $this->_exportMode, $this->_componentClause);
     }
     //reset map page
     $this->controller->resetPage('Map');
 }
Ejemplo n.º 5
0
 /**
  * Process the uploaded file
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $currentPath = CRM_Utils_System::currentPath();
     $urlParams = null;
     $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
     require_once 'CRM/Utils/Rule.php';
     if (CRM_Utils_Rule::qfKey($qfKey)) {
         $urlParams = "&qfKey={$qfKey}";
     }
     //get the button name
     $buttonName = $this->controller->getButtonName('done');
     $buttonName1 = $this->controller->getButtonName('next');
     if ($buttonName == '_qf_Map_done') {
         $this->set('exportColumnCount', null);
         $this->controller->resetPage($this->_name);
         return CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, 'force=1' . $urlParams));
     }
     if ($this->controller->exportValue($this->_name, 'addMore')) {
         $this->set('exportColumnCount', $this->_exportColumnCount);
         return;
     }
     $mapperKeys = $params['mapper'][1];
     $checkEmpty = 0;
     foreach ($mapperKeys as $value) {
         if ($value[0]) {
             $checkEmpty++;
         }
     }
     if (!$checkEmpty) {
         $this->set('mappingId', null);
         require_once 'CRM/Utils/System.php';
         CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, '_qf_Map_display=true' . $urlParams));
     }
     if ($buttonName1 == '_qf_Map_next') {
         if (CRM_Utils_Array::value('updateMapping', $params)) {
             //save mapping fields
             CRM_Core_BAO_Mapping::saveMappingFields($params, $params['mappingId']);
         }
         if (CRM_Utils_Array::value('saveMapping', $params)) {
             $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => $this->get('mappingTypeId'));
             $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
             //save mapping fields
             CRM_Core_BAO_Mapping::saveMappingFields($params, $saveMapping->id);
         }
     }
     //get the csv file
     require_once "CRM/Export/BAO/Export.php";
     CRM_Export_BAO_Export::exportComponents($this->get('selectAll'), $this->get('componentIds'), $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), $mapperKeys, $this->get('returnProperties'), $this->get('exportMode'), $this->get('componentClause'), $this->get('componentTable'), $this->get('mergeSameAddress'), $this->get('mergeSameHousehold'));
 }
Ejemplo n.º 6
0
 /**
  * Process the uploaded file.
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $exportOption = $params['exportOption'];
     $mergeSameAddress = CRM_Utils_Array::value('mergeOption', $params) == self::EXPORT_MERGE_SAME_ADDRESS ? 1 : 0;
     $mergeSameHousehold = CRM_Utils_Array::value('mergeOption', $params) == self::EXPORT_MERGE_HOUSEHOLD ? 1 : 0;
     $this->set('mergeSameAddress', $mergeSameAddress);
     $this->set('mergeSameHousehold', $mergeSameHousehold);
     // instead of increasing the number of arguments to exportComponents function, we
     // will send $exportParams as another argument, which is an array and suppose to contain
     // all submitted options or any other argument
     $exportParams = $params;
     if (!empty($this->_greetingOptions)) {
         foreach ($this->_greetingOptions as $key => $value) {
             if ($option = CRM_Utils_Array::value($key, $exportParams)) {
                 if ($this->_greetingOptions[$key][$option] == ts('Other')) {
                     $exportParams[$key] = $exportParams["{$key}_other"];
                 } elseif ($this->_greetingOptions[$key][$option] == ts('List of names')) {
                     $exportParams[$key] = '';
                 } else {
                     $exportParams[$key] = $this->_greetingOptions[$key][$option];
                 }
             }
         }
     }
     $mappingId = CRM_Utils_Array::value('mapping', $params);
     if ($mappingId) {
         $this->set('mappingId', $mappingId);
     } else {
         $this->set('mappingId', NULL);
     }
     if ($exportOption == self::EXPORT_ALL) {
         CRM_Export_BAO_Export::exportComponents($this->_selectAll, $this->_componentIds, $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), NULL, $this->get('returnProperties'), $this->_exportMode, $this->_componentClause, $this->_componentTable, $mergeSameAddress, $mergeSameHousehold, $exportParams, $this->get('queryOperator'));
     }
     //reset map page
     $this->controller->resetPage('Map');
 }
Ejemplo n.º 7
0
 public function testExportMasterAddress()
 {
     $contactA = $this->individualCreate(array(), 0);
     $contactB = $this->individualCreate(array(), 1);
     //create address for contact A
     $params = array('contact_id' => $contactA, 'location_type_id' => 'Home', 'street_address' => 'Ambachtstraat 23', 'postal_code' => '6971 BN', 'country_id' => '1152', 'city' => 'Brummen', 'is_primary' => 1);
     $result = $this->callAPISuccess('address', 'create', $params);
     $addressId = $result['id'];
     //share address with contact B
     $result = $this->callAPISuccess('address', 'create', array('contact_id' => $contactB, 'location_type_id' => "Home", 'master_id' => $addressId));
     //export the master address for contact B
     $selectedFields = array(array('Individual', 'master_id', 1));
     list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(TRUE, array($contactB), array(), NULL, $selectedFields, NULL, CRM_Export_Form_Select::CONTACT_EXPORT, "contact_a.id IN ({$contactB})", NULL, FALSE, FALSE, array('exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT, 'suppress_csv_for_testing' => TRUE));
     $field = key($sqlColumns);
     //assert the exported result
     $masterName = CRM_Core_DAO::singleValueQuery("SELECT {$field} FROM {$tableName}");
     $displayName = CRM_Contact_BAO_Contact::getMasterDisplayName(NULL, $contactB);
     $this->assertEquals($displayName, $masterName);
     // delete the export temp table and component table
     $sql = "DROP TABLE IF EXISTS {$tableName}";
     CRM_Core_DAO::executeQuery($sql);
 }