Esempio n. 1
0
 /**
  * Process the uploaded file
  *
  * @return void
  * @access public
  */
 function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     if ($this->controller->exportValue($this->_name, 'addMore')) {
         $this->set('columnCount', $this->_columnCount);
         return;
     }
     //reload the mapfield if load mapping is pressed
     //if ( CRM_Utils_Array::value( 'savedMapping', $params ) ) {
     if ($this->controller->exportValue($this->_name, 'loadMapping')) {
         CRM_Utils_Array::value('savedMapping', $params);
         $this->set('savedMapping', $params['savedMapping']);
         $this->controller->resetPage($this->_name);
         return;
     }
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $checkEmpty = 0;
     foreach ($mapperKeys as $value) {
         if ($value[0]) {
             $checkEmpty++;
         }
     }
     if (!$checkEmpty) {
         require_once 'CRM/Utils/System.php';
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/search/basic', '_qf_Map_display=true'));
     }
     //Updating Mapping Records
     if (CRM_Utils_Array::value('updateMapping', $params)) {
         $mappingFields =& new CRM_Core_DAO_MappingField();
         $mappingFields->mapping_id = $params['mappingId'];
         $mappingFields->find();
         $mappingFieldsId = array();
         while ($mappingFields->fetch()) {
             if ($mappingFields->id) {
                 $mappingFieldsId[$mappingFields->column_number] = $mappingFields->id;
             }
         }
         for ($i = 0; $i < $this->_columnCount; $i++) {
             if (!empty($mapperKeys[$i][0])) {
                 $updateMappingFields =& new CRM_Core_DAO_MappingField();
                 $updateMappingFields->id = $mappingFieldsId[$i];
                 $updateMappingFields->mapping_id = $params['mappingId'];
                 $updateMappingFields->name = $this->_mapperFields[$mapperKeys[$i][0]][$mapperKeys[$i][1]];
                 $updateMappingFields->column_number = $i;
                 $locationId = $mapperKeys[$i][2];
                 $updateMappingFields->location_type_id = isset($locationId) ? $locationId : null;
                 $relation = $mapperKeys[$i][1];
                 list($id, $first, $second) = explode('_', $relation);
                 if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
                     $updateMappingFields->relationship_type_id = $id;
                 } else {
                     $updateMappingFields->relationship_type_id = null;
                 }
                 $phoneType = $mapperKeys[$i][3];
                 $updateMappingFields->phone_type = isset($phoneType) ? $phoneType : null;
                 $updateMappingFields->save();
             }
         }
     }
     //Saving Mapping Details and Records
     if (CRM_Utils_Array::value('saveMapping', $params)) {
         $saveMapping =& new CRM_Core_DAO_Mapping();
         $saveMapping->domain_id = CRM_Core_Config::domainID();
         $saveMapping->name = $params['saveMappingName'];
         $saveMapping->description = $params['saveMappingDesc'];
         $saveMapping->mapping_type = 'Export';
         $saveMapping->save();
         for ($i = 0; $i < $this->_columnCount; $i++) {
             if (!empty($mapperKeys[$i][0])) {
                 $saveMappingFields =& new CRM_Core_DAO_MappingField();
                 $saveMappingFields->mapping_id = $saveMapping->id;
                 $saveMappingFields->name = $this->_mapperFields[$mapperKeys[$i][0]][$mapperKeys[$i][1]];
                 $saveMappingFields->contact_type = $mapperKeys[$i][0];
                 $saveMappingFields->column_number = $i;
                 $locationId = $mapperKeys[$i][2];
                 $saveMappingFields->location_type_id = isset($locationId) ? $locationId : null;
                 $saveMappingFields->phone_type = $mapperKeys[$i][3];
                 $relation = $mapperKeys[$i][1];
                 list($id, $first, $second) = explode('_', $relation);
                 if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
                     $saveMappingFields->relationship_type_id = $id;
                 } else {
                     $saveMappingFields->relationship_type_id = null;
                 }
                 $saveMappingFields->save();
             }
         }
     }
     //get the csv file
     require_once 'CRM/Contact/BAO/Export.php';
     CRM_Contact_BAO_Export::exportContacts($this->get('selectAll'), $this->get('contactIds'), $this->get('formValues'), $this->get(CRM_UTILS_SORT_SORT_ORDER), $mapperKeys);
 }