CRM-19386: Retrieve Activities custom fields in import parser
[civicrm-core.git] / CRM / Activity / Import / Parser / Activity.php
index adbc2abb5029444ccf8b9bc76e8a845c59031343..c47a7eb8c4e659393319e7dc628b5a95bb7f57a9 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
  */
 
 
@@ -55,14 +55,19 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
    * Class constructor.
    *
    * @param array $mapperKeys
-   * @param null $mapperLocType
-   * @param null $mapperPhoneType
+   * @param int $mapperLocType
+   * @param int $mapperPhoneType
    */
   public function __construct(&$mapperKeys, $mapperLocType = NULL, $mapperPhoneType = NULL) {
     parent::__construct();
     $this->_mapperKeys = &$mapperKeys;
   }
 
+  /**
+   * Function of undocumented functionality required by the interface.
+   */
+  protected function fini() {}
+
   /**
    * The initializer code, called before the processing.
    */
@@ -161,9 +166,8 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
    */
   public function summary(&$values) {
     $erroneousField = NULL;
-    $response = $this->setActiveFieldValues($values, $erroneousField);
+    $this->setActiveFieldValues($values, $erroneousField);
     $index = -1;
-    $errorRequired = FALSE;
 
     if ($this->_activityTypeIndex > -1 && $this->_activityLabelIndex > -1) {
       array_unshift($values, ts('Please select either Activity Type ID OR Activity Type Label.'));
@@ -192,7 +196,7 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
 
     $errorMessage = NULL;
 
-    //for date-Formats
+    // For date-Formats
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get('dateTypes');
     if (!isset($params['source_contact_id'])) {
@@ -216,9 +220,9 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
         CRM_Contact_Import_Parser_Contact::addToErrorMsg('Activity Engagement Index', $errorMessage);
       }
     }
-    //date-Format part ends
+    // Date-Format part ends.
 
-    //checking error in custom data
+    // Checking error in custom data.
     $params['contact_type'] = isset($this->_contactType) ? $this->_contactType : 'Activity';
 
     CRM_Contact_Import_Parser_Contact::isErrorInCustomData($params, $errorMessage);
@@ -245,7 +249,7 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
    *   the result of this processing
    */
   public function import($onDuplicate, &$values) {
-    // first make sure this is a valid line
+    // First make sure this is a valid line
     $response = $this->summary($values);
 
     if ($response != CRM_Import_Parser::VALID) {
@@ -256,14 +260,14 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
     if ($activityLabel) {
       $params = array_merge($params, array('activity_label' => $values[$activityLabel]));
     }
-    //for date-Formats
+    // For date-Formats.
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get('dateTypes');
     if (!isset($params['source_contact_id'])) {
       $params['source_contact_id'] = $session->get('userID');
     }
-    $formatted = array();
-    $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
+
+    $customFields = CRM_Core_BAO_CustomField::getFields('Activity');
 
     foreach ($params as $key => $val) {
       if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
@@ -284,7 +288,7 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
         $params['subject'] = $val;
       }
     }
-    //date-Format part ends
+    // Date-Format part ends.
     require_once 'CRM/Utils/DeprecatedUtils.php';
     $formatError = _civicrm_api3_deprecated_activity_formatted_param($params, $params, TRUE);
 
@@ -300,8 +304,8 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
 
     if ($this->_contactIdIndex < 0) {
 
-      //retrieve contact id using contact dedupe rule.
-      //since we are support only individual's activity import.
+      // Retrieve contact id using contact dedupe rule.
+      // Since we are supporting only individual's activity import.
       $params['contact_type'] = 'Individual';
       $params['version'] = 3;
       $error = _civicrm_api3_deprecated_duplicate_formatted_contact($params);
@@ -393,10 +397,4 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
     }
   }
 
-  /**
-   * The initializer code, called before the processing.
-   */
-  public function fini() {
-  }
-
 }