Ejemplo n.º 1
0
 /**
  * Handle the values in summary mode.
  *
  * @param array $values
  *   The array of values belonging to this line.
  *
  * @return bool
  *   the result of this processing
  */
 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_Import_Parser::ERROR;
     } elseif ($this->_eventTitleIndex > -1) {
         $index = $this->_eventTitleIndex;
     } elseif ($this->_eventIndex > -1) {
         $index = $this->_eventIndex;
     }
     $params =& $this->getActiveFieldParams();
     if (!($index < 0 || $this->_participantStatusIndex < 0)) {
         $errorRequired = !CRM_Utils_Array::value($this->_participantStatusIndex, $values);
         if (empty($params['event_id']) && empty($params['event_title'])) {
             CRM_Contact_Import_Parser_Contact::addToErrorMsg('Event', $missingField);
         }
         if (empty($params['participant_status_id'])) {
             CRM_Contact_Import_Parser_Contact::addToErrorMsg('Participant Status', $missingField);
         }
     } else {
         $errorRequired = TRUE;
         $missingField = NULL;
         if ($index < 0) {
             CRM_Contact_Import_Parser_Contact::addToErrorMsg('Event', $missingField);
         }
         if ($this->_participantStatusIndex < 0) {
             CRM_Contact_Import_Parser_Contact::addToErrorMsg('Participant Status', $missingField);
         }
     }
     if ($errorRequired) {
         array_unshift($values, ts('Missing required field(s) :') . $missingField);
         return CRM_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 ($dateValue = CRM_Utils_Date::formatDate($params[$key], $dateType)) {
                 $params[$key] = $dateValue;
             } else {
                 CRM_Contact_Import_Parser_Contact::addToErrorMsg('Register Date', $errorMessage);
             }
         } elseif ($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_Contact_Import_Parser_Contact::addToErrorMsg('Participant Role Id', $errorMessage);
                         break;
                     }
                 }
             } else {
                 foreach ($val as $role) {
                     if (!CRM_Contact_Import_Parser_Contact::in_value(trim($role), $roleIDs)) {
                         CRM_Contact_Import_Parser_Contact::addToErrorMsg('Participant Role', $errorMessage);
                         break;
                     }
                 }
             }
         } elseif ($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_Contact_Import_Parser_Contact::addToErrorMsg('Participant Status Id', $errorMessage);
                     break;
                 }
             } elseif (!CRM_Contact_Import_Parser_Contact::in_value($val, $statusIDs)) {
                 CRM_Contact_Import_Parser_Contact::addToErrorMsg('Participant Status', $errorMessage);
                 break;
             }
         }
     }
     //date-Format part ends
     $params['contact_type'] = 'Participant';
     //checking error in custom data
     CRM_Contact_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_Import_Parser::VALID;
 }