Merge pull request #4360 from christianwach/wordpress-hooks
[civicrm-core.git] / CRM / Event / Import / Parser / Participant.php
index 8b026129bccea8d2311173bf4baaa63f753fcce6..f097124aa5586adb778f2fe10340563294c18c1b 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -58,7 +58,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
   protected $_newParticipants;
 
   /**
-   * class constructor
+   * Class constructor
    */
   function __construct(&$mapperKeys, $mapperLocType = NULL, $mapperPhoneType = NULL) {
     parent::__construct();
@@ -66,7 +66,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
   }
 
   /**
-   * the initializer code, called before the processing
+   * The initializer code, called before the processing
    *
    * @return void
    * @access public
@@ -124,7 +124,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
   }
 
   /**
-   * handle the values in mapField mode
+   * Handle the values in mapField mode
    *
    * @param array $values the array of values belonging to this line
    *
@@ -136,7 +136,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
   }
 
   /**
-   * handle the values in preview mode
+   * Handle the values in preview mode
    *
    * @param array $values the array of values belonging to this line
    *
@@ -148,7 +148,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
   }
 
   /**
-   * handle the values in summary mode
+   * Handle the values in summary mode
    *
    * @param array $values the array of values belonging to this line
    *
@@ -176,10 +176,10 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
 
     if (!(($index < 0) || ($this->_participantStatusIndex < 0))) {
       $errorRequired = !CRM_Utils_Array::value($this->_participantStatusIndex, $values);
-      if (!CRM_Utils_Array::value('event_id', $params) && !CRM_Utils_Array::value('event_title', $params)) {
+      if (empty($params['event_id']) && empty($params['event_title'])) {
         CRM_Contact_Import_Parser_Contact::addToErrorMsg('Event', $missingField);
       }
-      if (!CRM_Utils_Array::value('participant_status_id', $params)) {
+      if (empty($params['participant_status_id'])) {
         CRM_Contact_Import_Parser_Contact::addToErrorMsg('Participant Status', $missingField);
       }
     }
@@ -264,7 +264,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
   }
 
   /**
-   * handle the values in import mode
+   * Handle the values in import mode
    *
    * @param int $onDuplicate the code for what action to take on duplicates
    * @param array $values the array of values belonging to this line
@@ -299,11 +299,15 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
             $params[$key] = CRM_Utils_String::strtoboolstr($val);
           }
         }
+        if($key == 'participant_register_date') {
+          CRM_Utils_Date::convertToDefaultDate($params, $dateType, 'participant_register_date');
+          $formatted['participant_register_date'] = CRM_Utils_Date::processDate($params['participant_register_date']);
+        }
       }
     }
 
-    if (!(CRM_Utils_Array::value('participant_role_id', $params) || CRM_Utils_Array::value('participant_role', $params))) {
-      if (CRM_Utils_Array::value('event_id', $params)) {
+    if (!(!empty($params['participant_role_id']) || !empty($params['participant_role']))) {
+      if (!empty($params['event_id'])) {
         $params['participant_role_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'default_role_id');
       }
       else {
@@ -373,7 +377,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
             return CRM_Import_Parser::ERROR;
           }
           $newParticipant = CRM_Event_BAO_Participant::create($formatted, $ids);
-          if( CRM_Utils_Array::value('fee_level', $formatted)) {
+          if (!empty($formatted['fee_level'])) {
             $otherParams = array(
               'fee_label' => $formatted['fee_level'],
               'event_id' => $newParticipant->event_id
@@ -429,7 +433,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
           }
         }
 
-        if (CRM_Utils_Array::value('external_identifier', $params)) {
+        if (!empty($params['external_identifier'])) {
           if ($disp) {
             $disp .= "AND {$params['external_identifier']}";
           }
@@ -443,7 +447,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
       }
     }
     else {
-      if (CRM_Utils_Array::value('external_identifier', $formatValues)) {
+      if (!empty($formatValues['external_identifier'])) {
         $checkCid = new CRM_Contact_DAO_Contact();
         $checkCid->external_identifier = $formatValues['external_identifier'];
         $checkCid->find(TRUE);
@@ -496,7 +500,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser {
   }
 
   /**
-   * the initializer code, called before the processing
+   * The initializer code, called before the processing
    *
    * @return void
    * @access public