INFRA-132 - Fix missing newlines in comments
[civicrm-core.git] / CRM / Core / BAO / Mapping.php
index 4735d777aad78d57af858188e971ed3c974fabbe..3b5d659e4a5e2213ce2e13d88deb15a7e5fea4a8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 
   /**
-   * class constructor
+   * Class constructor
    */
-  function __construct() {
+  public function __construct() {
     parent::__construct();
   }
 
   /**
-   * Takes a bunch of params that are needed to match certain criteria and
-   * retrieves the relevant objects. Typically the valid params are only
-   * contact_id. We'll tweak this function to be more full featured over a period
-   * of time. This is the inverse function of create. It also stores all the retrieved
-   * values in the default array
+   * Fetch object based on array of properties
    *
-   * @param array $params      (reference ) an assoc array of name/value pairs
-   * @param array $defaults    (reference ) an assoc array to hold the flattened values
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   * @param array $defaults
+   *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return object     CRM_Core_DAO_Mapping object on success, otherwise null
-   * @access public
+   * @return object     CRM_Core_DAO_Mapping object on success, otherwise NULL
    * @static
    */
-  static function retrieve(&$params, &$defaults) {
+  public static function retrieve(&$params, &$defaults) {
     $mapping = new CRM_Core_DAO_Mapping();
     $mapping->copyValues($params);
     if ($mapping->find(TRUE)) {
@@ -66,16 +63,16 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * Function to delete the mapping
+   * Delete the mapping
    *
-   * @param int $id   mapping id
+   * @param int $id
+   *   Mapping id.
    *
    * @return boolean
-   * @access public
    * @static
    *
    */
-  static function del($id) {
+  public static function del($id) {
     // delete from mapping_field table
     $mappingField = new CRM_Core_DAO_MappingField();
     $mappingField->mapping_id = $id;
@@ -94,19 +91,19 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * takes an associative array and creates a contact object
+   * Takes an associative array and creates a contact object
    *
    * The function extract all the params it needs to initialize the create a
    * contact object. the params array could contain additional unused name/value
    * pairs
    *
-   * @param array  $params an array of name/value pairs
+   * @param array $params
+   *   An array of name/value pairs.
    *
-   * @return object    CRM_Core_DAO_Mapper object on success, otherwise null
-   * @access public
+   * @return object    CRM_Core_DAO_Mapper object on success, otherwise NULL
    * @static
    */
-  static function add($params) {
+  public static function add($params) {
     $mapping = new CRM_Core_DAO_Mapping();
     $mapping->copyValues($params);
     $mapping->save();
@@ -115,17 +112,15 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * function to get the list of mappings
+   * Get the list of mappings
    *
-   * @params string  $mappingTypeId  mapping type id
-   *
-   * @param $mappingTypeId
+   * @param string $mappingTypeId
+   *   Mapping type id.
    *
    * @return array $mapping array of mapping name
-   * @access public
    * @static
    */
-  static function getMappings($mappingTypeId) {
+  public static function getMappings($mappingTypeId) {
     $mapping = array();
     $mappingDAO = new CRM_Core_DAO_Mapping();
     $mappingDAO->mapping_type_id = $mappingTypeId;
@@ -139,17 +134,15 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * function to get the mapping fields
-   *
-   * @params int $mappingId  mapping id
+   * Get the mapping fields
    *
-   * @param $mappingId
+   * @param int $mappingId
+   *   Mapping id.
    *
    * @return array $mappingFields array of mapping fields
-   * @access public
    * @static
    */
-  static function getMappingFields($mappingId) {
+  public static function getMappingFields($mappingId) {
     //mapping is to be loaded from database
     $mapping = new CRM_Core_DAO_MappingField();
     $mapping->mapping_id = $mappingId;
@@ -199,40 +192,32 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   *function to check Duplicate Mapping Name
-   *
-   * @params $nameField  string mapping Name
+   * Check Duplicate Mapping Name
    *
-   * @params $mapTypeId string mapping Type
-   *
-   * @param $nameField
-   * @param $mapTypeId
+   * @param string $nameField
+   *   mapping Name.
+   * @param string $mapTypeId
+   *   mapping Type.
    *
    * @return boolean
    */
-  static function checkMapping($nameField, $mapTypeId) {
+  public static function checkMapping($nameField, $mapTypeId) {
     $mapping = new CRM_Core_DAO_Mapping();
     $mapping->name = $nameField;
     $mapping->mapping_type_id = $mapTypeId;
-    if ($mapping->find(TRUE)) {
-      return TRUE;
-    }
-    else {
-      return FALSE;
-    }
+    return (bool) $mapping->find(TRUE);
   }
 
   /**
    * Function returns associated array of elements, that will be passed for search
    *
-   * @params int $smartGroupId smart group id
-   *
-   * @param $smartGroupId
+   * @param int $smartGroupId
+   *   Smart group id.
    *
-   * @return array $returnFields  associated array of elements@static
-   * @public
+   * @return array $returnFields  associated array of elements
+   * @static
    */
-  static function getFormattedFields($smartGroupId) {
+  public static function getFormattedFields($smartGroupId) {
     $returnFields = array();
 
     //get the fields from mapping table
@@ -255,26 +240,21 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * Function to build the mapping form
+   * Build the mapping form
    *
-   * @params object $form        form object
-   * @params string $mappingType mapping type (Export/Import/Search Builder)
-   * @params int    $mappingId   mapping id
-   * @params mixed  $columnCount column count is int for and array for search builder
-   * @params int    $blockCount  block count (no of blocks shown)
-   *
-   * @param $form
+   * @param CRM_Core_Form $form
    * @param string $mappingType
-   * @param null $mappingId
-   * @param $columnNo
+   *   (Export/Import/Search Builder).
+   * @param int $mappingId
+   * @param int $columnNo
    * @param int $blockCount
-   * @param null $exportMode
+   *   (no of blocks shown).
+   * @param NULL $exportMode
    *
    * @return void
-   * @access public
    * @static
    */
-  static function buildMappingForm(&$form, $mappingType = 'Export', $mappingId = NULL, $columnNo, $blockCount = 3, $exportMode = NULL) {
+  public static function buildMappingForm(&$form, $mappingType = 'Export', $mappingId = NULL, $columnNo, $blockCount = 3, $exportMode = NULL) {
     if ($mappingType == 'Export') {
       $name = "Map";
       $columnCount = array('1' => $columnNo);
@@ -398,8 +378,8 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       if (array_key_exists('note', $fields['Contact'])) {
         $noteTitle = $fields['Contact']['note']['title'];
         $fields['Contact']['note']['title'] = $noteTitle . ': ' . ts('Body and Subject');
-        $fields['Contact']['note_body']    = array( 'title' => $noteTitle . ': ' . ts('Body Only'),    'name' => 'note_body' );
-        $fields['Contact']['note_subject'] = array( 'title' => $noteTitle . ': ' . ts('Subject Only'), 'name' => 'note_subject' );
+        $fields['Contact']['note_body']    = array('title' => $noteTitle . ': ' . ts('Body Only'),    'name' => 'note_body');
+        $fields['Contact']['note_subject'] = array('title' => $noteTitle . ': ' . ts('Subject Only'), 'name' => 'note_subject');
       }
     }
 
@@ -546,20 +526,16 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
 
-    /* FIXME: dirty hack to make the default option show up first.  This
-         * avoids a mozilla browser bug with defaults on dynamically constructed
-         * selector widgets. */
-
-
+    // FIXME: dirty hack to make the default option show up first.  This
+    // avoids a mozilla browser bug with defaults on dynamically constructed
+    // selector widgets.
     if ($defaultLocationType) {
       $defaultLocation = $locationTypes[$defaultLocationType->id];
       unset($locationTypes[$defaultLocationType->id]);
-      $locationTypes = array(
-        $defaultLocationType->id => $defaultLocation) + $locationTypes;
+      $locationTypes = array($defaultLocationType->id => $defaultLocation) + $locationTypes;
     }
 
-    $locationTypes = array(
-      ' ' => ts('Primary')) + $locationTypes;
+    $locationTypes = array(' ' => ts('Primary')) + $locationTypes;
 
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
@@ -568,8 +544,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       $contactTypes = array('Contact' => ts('Contacts')) + $contactTypes;
     }
 
-    $sel1 =
-      array('' => ts('- select record type -')) + $contactTypes + $compArray;
+    $sel1 = array('' => ts('- select record type -')) + $contactTypes + $compArray;
 
     foreach ($sel1 as $key => $sel) {
       if ($key) {
@@ -612,8 +587,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       }
     }
 
-    //Array for core fields and relationship custom data
-
+    // Array for core fields and relationship custom data
     $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
 
     if ($mappingType == 'Export') {
@@ -625,7 +599,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
               // FIX ME: For now let's not expose custom data related to relationship
               $relationshipCustomFields = array();
               //$relationshipCustomFields    = self::getRelationTypeCustomGroupData( $id );
-              //asort( $relationshipCustomFields ) ;
+              //asort($relationshipCustomFields);
 
               $relationshipType = new CRM_Contact_BAO_RelationshipType();
               $relationshipType->id = $id;
@@ -648,7 +622,6 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       }
 
       //Location Type for relationship fields
-
       foreach ($sel5 as $k => $v) {
         if ($v) {
           foreach ($v as $rel => $fields) {
@@ -899,7 +872,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       $js .= implode(', ', $elements);
       $js .= "]";
       $js .= "
-                for(var i=0;i<nullArray.length;i++) {
+                for (var i=0;i<nullArray.length;i++) {
                     if ( {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'] ) {
                         {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'].style.display = '';
                     }
@@ -920,7 +893,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       $js .= implode(', ', $elements);
       $js .= "]";
       $js .= "
-                for(var i=0;i<noneArray.length;i++) {
+                for (var i=0;i<noneArray.length;i++) {
                     if ( {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'] ) {
   {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'].style.display = 'none';
                     }
@@ -937,17 +910,16 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
     $form->setDefaultAction('refresh');
   }
 
-  /* Function returns all custom fields with group title and
-   * field label
-   * @relationshipTypeId related relationship type id
-   * @return $groupTitle all custom field titles
-   */
   /**
-   * @param $relationshipTypeId
+   * Function returns all custom fields with group title and
+   * field label
    *
-   * @return array
+   * @param int $relationshipTypeId
+   *   Related relationship type id.
+   *
+   * @return array all custom field titles
    */
-  function getRelationTypeCustomGroupData($relationshipTypeId) {
+  public function getRelationTypeCustomGroupData($relationshipTypeId) {
 
     $customFields = CRM_Core_BAO_CustomField::getFields('Relationship', NULL, NULL, $relationshipTypeId, NULL, NULL);
     $groupTitle = array();
@@ -961,12 +933,13 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   /**
    * Function returns all  Custom group Names
    *
-   * @param related $customfieldId
+   * @param int $customfieldId
+   *   Related file id.
    *
-   * @internal param \related $customfieldId custom field id
-   * @return null|string $customGroupName all custom group names@static
+   * @return null|string $customGroupName all custom group names
+   * @static
    */
-  static function getCustomGroupName($customfieldId) {
+  public static function getCustomGroupName($customfieldId) {
     if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($customfieldId)) {
       $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
       $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
@@ -982,16 +955,16 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   /**
    * Function returns associated array of elements, that will be passed for search
    *
-   * @params array   $params associated array of submitted values
-   * @params boolean $row    row no of the fields
-   *
-   * @param $params
+   * @param array $params
+   *   Associated array of submitted values.
    * @param bool $row
+   *   Row no of the fields.
    *
-   * @return array $returnFields  formatted associated array of elements@static
-   * @public
+   *
+   * @return array $returnFields  formatted associated array of elements
+   * @static
    */
-  static function formattedFields(&$params, $row = FALSE) {
+  public static function formattedFields(&$params, $row = FALSE) {
     $fields = array();
 
     if (empty($params) || !isset($params['mapper'])) {
@@ -1052,7 +1025,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
               'Multi-Select',
               'AdvMulti-Select',
               'Multi-Select State/Province',
-              'Multi-Select Country'
+              'Multi-Select Country',
             );
 
             // override the operator to handle separator ( note: this might have some performance issues )
@@ -1067,7 +1040,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
           }
 
           // CRM-14983: verify if values are comma separated convert to array
-          if (!is_array($value) && (strpos($value,',') !== false || strstr($value, '(')) && empty($isCustomField) && $params['operator'][$key][$k] == 'IN') {
+          if (!is_array($value) && (strpos($value,',') !== FALSE || strstr($value, '(')) && empty($isCustomField) && $params['operator'][$key][$k] == 'IN') {
             preg_match('#\((.*?)\)#', $value, $match);
             $tmpArray = explode(',', $match[1]);
             $value = array_combine(array_values($tmpArray),array_values($tmpArray));
@@ -1120,11 +1093,11 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * @param $params
+   * @param array $params
    *
    * @return array
    */
-  static function &returnProperties(&$params) {
+  public static function &returnProperties(&$params) {
     $fields = array(
       'contact_type' => 1,
       'contact_sub_type' => 1,
@@ -1179,16 +1152,17 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * save the mapping field info for search builder / export given the formvalues
+   * Save the mapping field info for search builder / export given the formvalues
    *
-   * @param array $params       asscociated array of formvalues
-   * @param int   $mappingId    mapping id
+   * @param array $params
+   *   Asscociated array of formvalues.
+   * @param int $mappingId
+   *   Mapping id.
    *
-   * @return null
+   * @return NULL
    * @static
-   * @access public
    */
-  static function saveMappingFields(&$params, $mappingId) {
+  public static function saveMappingFields(&$params, $mappingId) {
     //delete mapping fields records for exixting mapping
     $mappingFields = new CRM_Core_DAO_MappingField();
     $mappingFields->mapping_id = $mappingId;
@@ -1268,4 +1242,3 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
     }
   }
 }
-