*/
class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField {
-
/**
* store contactType.
*
else {
$savedMapping = $this->get('savedMapping');
- list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingRelation) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping);
+ list($mappingName) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping);
$mappingName = $mappingName[1];
- $mappingContactType = $mappingContactType[1];
- $mappingLocation = $mappingLocation['1'] ?? NULL;
- $mappingPhoneType = $mappingPhoneType['1'] ?? NULL;
- $mappingRelation = $mappingRelation['1'] ?? NULL;
//mapping is to be loaded from database
$hasHeaders = !empty($this->_columnHeaders);
$headerPatterns = $this->get('headerPatterns');
$dataPatterns = $this->get('dataPatterns');
- $hasLocationTypes = $this->get('fieldTypes');
/* Initialize all field usages to false */
public static function formRule($fields, $files, $self) {
$errors = [];
- if (!array_key_exists('savedMapping', $fields)) {
- $importKeys = [];
- foreach ($fields['mapper'] as $mapperPart) {
- $importKeys[] = $mapperPart[0];
- }
- // FIXME: should use the schema titles, not redeclare them
- $requiredFields = array(
- 'membership_contact_id' => ts('Contact ID'),
- 'membership_type_id' => ts('Membership Type'),
- 'membership_start_date' => ts('Membership Start Date'),
- );
+ $importKeys = [];
+ foreach ($fields['mapper'] as $mapperPart) {
+ $importKeys[] = $mapperPart[0];
+ }
+ // FIXME: should use the schema titles, not redeclare them
+ $requiredFields = array(
+ 'membership_contact_id' => ts('Contact ID'),
+ 'membership_type_id' => ts('Membership Type'),
+ 'membership_start_date' => ts('Membership Start Date'),
+ );
- $contactTypeId = $self->get('contactType');
- $contactTypes = array(
- CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual',
- CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household',
- CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization',
- );
- $params = array(
- 'used' => 'Unsupervised',
- 'contact_type' => $contactTypes[$contactTypeId],
- );
- list($ruleFields, $threshold) = CRM_Dedupe_BAO_DedupeRuleGroup::dedupeRuleFieldsWeight($params);
- $weightSum = 0;
- foreach ($importKeys as $key => $val) {
- if (array_key_exists($val, $ruleFields)) {
- $weightSum += $ruleFields[$val];
- }
- }
- $fieldMessage = '';
- foreach ($ruleFields as $field => $weight) {
- $fieldMessage .= ' ' . $field . '(weight ' . $weight . ')';
+ $contactTypeId = $self->get('contactType');
+ $contactTypes = array(
+ CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual',
+ CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household',
+ CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization',
+ );
+ $params = array(
+ 'used' => 'Unsupervised',
+ 'contact_type' => $contactTypes[$contactTypeId],
+ );
+ list($ruleFields, $threshold) = CRM_Dedupe_BAO_DedupeRuleGroup::dedupeRuleFieldsWeight($params);
+ $weightSum = 0;
+ foreach ($importKeys as $key => $val) {
+ if (array_key_exists($val, $ruleFields)) {
+ $weightSum += $ruleFields[$val];
}
+ }
+ $fieldMessage = '';
+ foreach ($ruleFields as $field => $weight) {
+ $fieldMessage .= ' ' . $field . '(weight ' . $weight . ')';
+ }
- foreach ($requiredFields as $field => $title) {
- if (!in_array($field, $importKeys)) {
- if ($field == 'membership_contact_id') {
- if ((($weightSum >= $threshold || in_array('external_identifier', $importKeys)) &&
- $self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE
- ) ||
- in_array('membership_id', $importKeys)
- ) {
- continue;
- }
- else {
- if (!isset($errors['_qf_default'])) {
- $errors['_qf_default'] = '';
- }
- $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " $fieldMessage " . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array(
- 1 => $threshold,
- )) . ' ' . ts('(OR Membership ID if update mode.)') . '<br />';
- }
+ foreach ($requiredFields as $field => $title) {
+ if (!in_array($field, $importKeys)) {
+ if ($field == 'membership_contact_id') {
+ if ((($weightSum >= $threshold || in_array('external_identifier', $importKeys)) &&
+ $self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE
+ ) ||
+ in_array('membership_id', $importKeys)
+ ) {
+ continue;
}
else {
if (!isset($errors['_qf_default'])) {
$errors['_qf_default'] = '';
}
- $errors['_qf_default'] .= ts('Missing required field: %1', array(
- 1 => $title,
- )) . '<br />';
+ $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " $fieldMessage " . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array(
+ 1 => $threshold,
+ )) . ' ' . ts('(OR Membership ID if update mode.)') . '<br />';
+ }
+ }
+ else {
+ if (!isset($errors['_qf_default'])) {
+ $errors['_qf_default'] = '';
}
+ $errors['_qf_default'] .= ts('Missing required field: %1', array(
+ 1 => $title,
+ )) . '<br />';
}
}
}
*/
public function postProcess() {
$params = $this->controller->exportValues('MapField');
- //reload the mapfield if load mapping is pressed
- if (!empty($params['savedMapping'])) {
- $this->set('savedMapping', $params['savedMapping']);
- $this->controller->resetPage($this->_name);
- return;
- }
-
- $fileName = $this->controller->exportValue('DataSource', 'uploadFile');
- $separator = $this->controller->exportValue('DataSource', 'fieldSeparator');
- $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
-
- $mapperKeys = [];
+ $this->updateUserJobMetadata('submitted_values', $this->getSubmittedValues());
$mapper = [];
$mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
$mapperKeysMain = [];
- $mapperLocType = [];
- $mapperPhoneType = [];
for ($i = 0; $i < $this->_columnCount; $i++) {
$mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
$mapperKeysMain[$i] = $mapperKeys[$i][0];
-
- if (!empty($mapperKeys[$i][1]) && is_numeric($mapperKeys[$i][1])) {
- $mapperLocType[$i] = $mapperKeys[$i][1];
- }
- else {
- $mapperLocType[$i] = NULL;
- }
-
- if (!empty($mapperKeys[$i][2]) && (!is_numeric($mapperKeys[$i][2]))) {
- $mapperPhoneType[$i] = $mapperKeys[$i][2];
- }
- else {
- $mapperPhoneType[$i] = NULL;
- }
}
$this->set('mapper', $mapper);
$this->set('savedMapping', $saveMappingFields->mapping_id);
}
- $parser = new CRM_Member_Import_Parser_Membership($mapperKeysMain, $mapperLocType, $mapperPhoneType);
- $parser->run($fileName, $separator, $mapper, $skipColumnHeader,
+ $parser = new CRM_Member_Import_Parser_Membership($mapperKeysMain);
+ $parser->setUserJobID($this->getUserJobID());
+ $parser->run($this->getSubmittedValue('uploadFile'), $this->getSubmittedValue('fieldSeparator'), $mapper, $this->getSubmittedValue('skipColumnHeader'),
CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType')
);
// add all the necessary variables to the form
$parser->set($this);
}
+ /**
+ * @return \CRM_Member_Import_Parser_Membership
+ */
+ protected function getParser(): CRM_Member_Import_Parser_Membership {
+ if (!$this->parser) {
+ $this->parser = new CRM_Member_Import_Parser_Membership();
+ $this->parser->setUserJobID($this->getUserJobID());
+ $this->parser->init();
+ }
+ return $this->parser;
+ }
+
}