/** * handle the values in summary mode * * @param array $values the array of values belonging to this line * * @return boolean the result of this processing * @access public */ function summary(&$values) { $erroneousField = null; $response = $this->setActiveFieldValues($values, $erroneousField); $errorRequired = false; $index = -1; if ($this->_eventIndex > -1 && $this->_eventTitleIndex > -1) { array_unshift($values, ts('Select either EventID OR Event Title')); return CRM_Event_Import_Parser::ERROR; } elseif ($this->_eventTitleIndex > -1) { $index = $this->_eventTitleIndex; } elseif ($this->_eventIndex > -1) { $index = $this->_eventIndex; } $params =& $this->getActiveFieldParams(); require_once 'CRM/Import/Parser/Contact.php'; if (!($index < 0 || $this->_participantStatusIndex < 0)) { $errorRequired = !CRM_Utils_Array::value($this->_participantStatusIndex, $values); if (!$params['event_id'] && !$params['event_title']) { CRM_Import_Parser_Contact::addToErrorMsg('Event', $missingField); } if (!$params['participant_status_id']) { CRM_Import_Parser_Contact::addToErrorMsg('Participant Status', $missingField); } } else { $errorRequired = true; $missingField = null; if ($index < 0) { CRM_Import_Parser_Contact::addToErrorMsg('Event', $missingField); } if ($this->_participantStatusIndex < 0) { CRM_Import_Parser_Contact::addToErrorMsg('Participant Status', $missingField); } } if ($errorRequired) { array_unshift($values, ts('Missing required field(s) :') . $missingField); return CRM_Event_Import_Parser::ERROR; } $errorMessage = null; //for date-Formats $session = CRM_Core_Session::singleton(); $dateType = $session->get("dateTypes"); foreach ($params as $key => $val) { if ($val && $key == 'participant_register_date') { if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) { if (!CRM_Utils_Rule::date($params[$key])) { CRM_Import_Parser_Contact::addToErrorMsg('Register Date', $errorMessage); } } else { CRM_Import_Parser_Contact::addToErrorMsg('Register Date', $errorMessage); } } else { if ($val && ($key == 'participant_role_id' || $key == 'participant_role')) { $roleIDs = CRM_Event_PseudoConstant::participantRole(); $val = explode(',', $val); if ($key == 'participant_role_id') { foreach ($val as $role) { if (!in_array(trim($role), array_keys($roleIDs))) { CRM_Import_Parser_Contact::addToErrorMsg('Participant Role Id', $errorMessage); break; } } } else { foreach ($val as $role) { if (!CRM_Import_Parser_Contact::in_value(trim($role), $roleIDs)) { CRM_Import_Parser_Contact::addToErrorMsg('Participant Role', $errorMessage); break; } } } } else { if ($val && ($key == 'participant_status_id' || $key == 'participant_status')) { $statusIDs = CRM_Event_PseudoConstant::participantStatus(); if ($key == 'participant_status_id') { if (!in_array(trim($val), array_keys($statusIDs))) { CRM_Import_Parser_Contact::addToErrorMsg('Participant Status Id', $errorMessage); break; } } else { if (!CRM_Import_Parser_Contact::in_value($val, $statusIDs)) { CRM_Import_Parser_Contact::addToErrorMsg('Participant Status', $errorMessage); break; } } } } } } //date-Format part ends $params['contact_type'] = 'Participant'; //checking error in custom data CRM_Import_Parser_Contact::isErrorInCustomData($params, $errorMessage); if ($errorMessage) { $tempMsg = "Invalid value for field(s) : {$errorMessage}"; array_unshift($values, $tempMsg); $errorMessage = null; return CRM_Import_Parser::ERROR; } return CRM_Event_Import_Parser::VALID; }
/** * function to check if an error in Core( non-custom fields ) field * * @param String $errorMessage A string containing all the error-fields. * * @access public */ function isErrorInCoreData($params, &$errorMessage) { foreach ($params as $key => $value) { if ($value) { switch ($key) { case 'birth_date': if (!CRM_Utils_Rule::date($value)) { //return _crm_error('Birth Date'); CRM_Import_Parser_Contact::addToErrorMsg('Birth Date', $errorMessage); } break; case 'gender': if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::gender(true))) { //return _crm_error('Invalid value for field : Gender'); CRM_Import_Parser_Contact::addToErrorMsg('Gender', $errorMessage); } break; case 'preferred_communication_method': if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pcm(), CASE_LOWER))) { //return _crm_error('Invalid value for field : Preferred Communication Method'); CRM_Import_Parser_Contact::addToErrorMsg('Preferred Communication Method', $errorMessage); } break; case 'preferred_mail_format': if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) { //return _crm_error('Invalid value for field : Preferred Communication Method'); CRM_Import_Parser_Contact::addToErrorMsg('Preferred Mail Format', $errorMessage); } break; case 'individual_prefix': if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualPrefix(true))) { //return _crm_error('Invalid value for field : Individual Prefix'); CRM_Import_Parser_Contact::addToErrorMsg('Individual Prefix', $errorMessage); } break; case 'individual_suffix': if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualSuffix(true))) { //return _crm_error('Invalid value for field : Individual Suffix'); CRM_Import_Parser_Contact::addToErrorMsg('Individual Suffix', $errorMessage); } break; case 'state_province': if (!empty($value)) { foreach ($value as $stateValue) { if ($stateValue['state_province']) { if (CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) { continue; } else { //return _crm_error('Invalid value for field : State Province '); CRM_Import_Parser_Contact::addToErrorMsg('State Province', $errorMessage); } } } } break; case 'country': if (!empty($value)) { foreach ($value as $stateValue) { if ($stateValue['country']) { if (CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::countryIsoCode()) || CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) { continue; } else { //return _crm_error('Invalid value for field : Country'); CRM_Import_Parser_Contact::addToErrorMsg('Country', $errorMessage); } } } } break; case 'geo_code_1': if (!empty($value)) { foreach ($value as $codeValue) { if ($codeValue['geo_code_1']) { if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) { continue; } else { //return _crm_error('Invalid value for field : geo_code_1'); CRM_Import_Parser_Contact::addToErrorMsg('geo_code_1', $errorMessage); } } } } break; case 'geo_code_2': if (!empty($value)) { foreach ($value as $codeValue) { if ($codeValue['geo_code_2']) { if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) { continue; } else { //return _crm_error('Invalid value for field : geo_code_2'); CRM_Import_Parser_Contact::addToErrorMsg('geo_code_2', $errorMessage); } } } } } } } //return true; }