INFRA-132 - Drupal.Classes.ClassDeclaration
[civicrm-core.git] / CRM / Contact / BAO / Relationship.php
index ba544051b8e15d06474b743a2b66401f2a2ae505..941f183f356a0146c56b6afc81eaca0e3f8ce616 100644 (file)
@@ -47,7 +47,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    * and this is new in 4.6
    * All existing calls have been changed to createMultiple except the api call - however, it is recommended
    * that you call that as the end to end testing here is based on the api & refactoring may still be done
-   * @param $params
+   * @param array $params
    * @return \CRM_Contact_BAO_Relationship
    * @throws \CRM_Core_Exception
    */
@@ -67,6 +67,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
     self::addRecent($params, $relationship);
     return $relationship;
   }
+
   /**
    * Takes an associative array and creates a relationship object
    * @deprecated For single creates use the api instead (it's tested).
@@ -77,11 +78,10 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    *   (reference ) an assoc array of name/value pairs.
    * @param array $ids
    *   The array that holds all the db ids.
-   * per http://wiki.civicrm.org/confluence/display/CRM/Database+layer
+   *   per http://wiki.civicrm.org/confluence/display/CRM/Database+layer
    *  "we are moving away from the $ids param "
    *
-   * @return CRM_Contact_BAO_Relationship object
-   * @static
+   * @return CRM_Contact_BAO_Relationship
    */
   public static function createMultiple(&$params, $ids = array()) {
     $valid = $invalid = $duplicate = $saved = 0;
@@ -93,7 +93,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
       $hook = 'create';
       $action = CRM_Core_Action::ADD;
     }
-    else{
+    else {
       $hook = 'edit';
       $action = CRM_Core_Action::UPDATE;
     }
@@ -122,12 +122,12 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
         }
 
         if (
-          self::checkDuplicateRelationship(
-            $params,
-            CRM_Utils_Array::value('contact', $ids),
-            // step 2
-            $key
-          )
+        self::checkDuplicateRelationship(
+          $params,
+          CRM_Utils_Array::value('contact', $ids),
+          // step 2
+          $key
+        )
         ) {
           $duplicate++;
           continue;
@@ -148,12 +148,12 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
       // it seems doubtful any of this is relevant if the contact fields & relationship
       // type fields are not set
       if (
-        self::checkDuplicateRelationship(
-          $params,
-          CRM_Utils_Array::value('contact', $ids),
-          $ids['contactTarget'],
-          $relationshipId
-        )
+      self::checkDuplicateRelationship(
+        $params,
+        CRM_Utils_Array::value('contact', $ids),
+        $ids['contactTarget'],
+        $relationshipId
+      )
       ) {
         $duplicate++;
         return array($valid, $invalid, $duplicate, $saved, NULL);
@@ -189,24 +189,22 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
-   * @param int $contactId
-   *   This is contact id for adding relationship.
    * @param array $ids
    *   The array that holds all the db ids.
+   * @param int $contactId
+   *   This is contact id for adding relationship.
    *
    * @return CRM_Contact_BAO_Relationship
-   * @static
    */
   public static function add(&$params, $ids = array(), $contactId = NULL) {
-    $relationshipId =
-      CRM_Utils_Array::value('relationship', $ids, CRM_Utils_Array::value('id', $params));
+    $relationshipId = CRM_Utils_Array::value('relationship', $ids, CRM_Utils_Array::value('id', $params));
 
     $hook = 'create';
     if ($relationshipId) {
       $hook = 'edit';
     }
     //@todo hook are called from create and add - remove one
-    CRM_Utils_Hook::pre($hook , 'Relationship', $relationshipId, $params);
+    CRM_Utils_Hook::pre($hook, 'Relationship', $relationshipId, $params);
 
     self::setContactABFromIDs($params);
     $relationshipTypes = CRM_Utils_Array::value('relationship_type_id', $params);
@@ -240,11 +238,11 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
             $relationship->$defaultField = 'NULL';
           }
         }
-        else{
+        else {
           $relationship->$defaultField = $params[$defaultField];
         }
       }
-      elseif(!$relationshipId) {
+      elseif (!$relationshipId) {
         $relationship->$defaultField = $defaultValue;
       }
     }
@@ -303,7 +301,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
 
   /**
    * Resolve passed in contact IDs to contact_id_a & contact_id_b
-   * @param $params
+   * @param array $params
    * @param array $ids
    * @param null $contactID
    * @throws \CRM_Core_Exception
@@ -316,7 +314,12 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
       if (!empty($params['id'])) {
         //let's load the missing ids here since other things tend to rely on them.
         $fieldsToFill = array('contact_id_a', 'contact_id_b', 'relationship_type_id');
-        $result = CRM_Core_DAO::executeQuery("SELECT " . implode(',', $fieldsToFill) . " FROM civicrm_relationship WHERE id = %1", array(1 => array($params['id'], 'Integer')));
+        $result = CRM_Core_DAO::executeQuery("SELECT " . implode(',', $fieldsToFill) . " FROM civicrm_relationship WHERE id = %1", array(
+          1 => array(
+            $params['id'],
+            'Integer',
+          ),
+        ));
         while ($result->fetch()) {
           foreach ($fieldsToFill as $field) {
             $params[$field] = !empty($params[$field]) ? $params[$field] : $result->$field;
@@ -346,8 +349,8 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
   /**
    * Specifiy defaults for creating a relationship
    *
-   * @return array $defaults array of defaults for creating relationship
-   * @static
+   * @return array
+   *   array of defaults for creating relationship
    */
   public static function getdefaults() {
     return array(
@@ -368,8 +371,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
    *
-   * @return boolean
-   * @static
+   * @return bool
    */
   public static function dataExists(&$params) {
     // return if no data present
@@ -400,11 +402,11 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    *   If set only subtype which is passed by $contactSubType.
    *                                          related relationshiptypes get return
    *
-   * @static
    *
-   * @return array - array reference of all relationship types with context to current contact.
+   * @return array
+   *   array reference of all relationship types with context to current contact.
    */
-  static function getContactRelationshipType(
+  public static function getContactRelationshipType(
     $contactId = NULL,
     $contactSuffix = NULL,
     $relationshipId = NULL,
@@ -416,7 +418,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
     $onlySubTypeRelationTypes = FALSE
   ) {
     $allRelationshipType = array();
-    $relationshipType    = array();
+    $relationshipType = array();
     $allRelationshipType = CRM_Core_PseudoConstant::relationshipType($column);
 
     $otherContactType = NULL;
@@ -509,17 +511,18 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
     if (($action & CRM_Core_Action::DISABLE) || ($action & CRM_Core_Action::DELETE)) {
       $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
       if ($relationship->relationship_type_id == $relTypes['Employee of']['id'] ||
-          $relationship->relationship_type_id == $relTypes['Household Member of']['id']) {
+        $relationship->relationship_type_id == $relTypes['Household Member of']['id']
+      ) {
         $sharedContact = new CRM_Contact_DAO_Contact();
         $sharedContact->id = $relationship->contact_id_a;
         $sharedContact->find(TRUE);
 
-          if ($relationship->relationship_type_id == 4 && $relationship->contact_id_b == $sharedContact->employer_id) {
+        if ($relationship->relationship_type_id == 4 && $relationship->contact_id_b == $sharedContact->employer_id) {
           CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($relationship->contact_id_a);
         }
       }
     }
-    return  $relationship;
+    return $relationship;
   }
 
   /**
@@ -530,7 +533,6 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    *
    * @return null
    *
-   * @static
    */
   public static function del($id) {
     // delete from relationship table
@@ -579,8 +581,6 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    *
    * @param $action
    *
-   * @return null
-   * @static
    */
   public static function disableEnableRelationship($id, $action) {
     $relationship = self::clearCurrentEmployer($id, $action);
@@ -622,7 +622,6 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    *   Id of the contact to delete.
    *
    * @return void
-   * @static
    */
   public static function deleteContact($contactId) {
     $relationship = new CRM_Contact_DAO_Relationship();
@@ -645,7 +644,6 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    * $returns  returns the contact ids in the realtionship
    *
    * @return \CRM_Contact_DAO_Relationship
-   * @static
    */
   public static function getContactIds($id) {
     $relationship = new CRM_Contact_DAO_Relationship();
@@ -668,8 +666,8 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    * @param int $relationshipTypeId
    *   Relationship type id.
    *
-   * @return boolean  true if it is valid relationship else false
-   * @static
+   * @return bool
+   *   true if it is valid relationship else false
    */
   public static function checkRelationshipType($contact_a, $contact_b, $relationshipTypeId) {
     $relationshipType = new CRM_Contact_DAO_RelationshipType();
@@ -686,11 +684,11 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
       if (((!$relationshipType->contact_type_a) || ($relationshipType->contact_type_a == $contact_type_a)) &&
         ((!$relationshipType->contact_type_b) || ($relationshipType->contact_type_b == $contact_type_b)) &&
         ((!$relationshipType->contact_sub_type_a) || (in_array($relationshipType->contact_sub_type_a,
-              $contact_sub_type_a
-            ))) &&
+            $contact_sub_type_a
+          ))) &&
         ((!$relationshipType->contact_sub_type_b) || (in_array($relationshipType->contact_sub_type_b,
-              $contact_sub_type_b
-            )))
+            $contact_sub_type_b
+          )))
       ) {
         return TRUE;
       }
@@ -712,8 +710,6 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    *   This is contact id for adding relationship.
    *
    * @return string
-  @access public
-   * @static
    */
   public static function checkValidRelationship($params, $ids, $contactId) {
     $errors = '';
@@ -741,8 +737,8 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    * @param int $relationshipId
    *   This is relationship id for the contact.
    *
-   * @return boolean true if record exists else false
-   * @static
+   * @return bool
+   *   true if record exists else false
    */
   public static function checkDuplicateRelationship(&$params, $id, $contactId = 0, $relationshipId = 0) {
     $relationshipTypeId = CRM_Utils_Array::value('relationship_type_id', $params);
@@ -818,8 +814,8 @@ WHERE  relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer');
    *   Value we want to set the is_active field.
    *
    * @throws CiviCRM_API3_Exception
-   * @return Object             DAO object on success, null otherwise
-   * @static
+   * @return Object
+   *   DAO object on success, null otherwise
    */
   public static function setIsActive($id, $is_active) {
     // as both the create & add functions have a bunch of logic in them that
@@ -853,8 +849,8 @@ WHERE  relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer');
    * @param array $values
    *   Output values of the object.
    *
-   * @return array (reference)   the values that could be potentially assigned to smarty
-   * @static
+   * @return array
+   *   (reference)   the values that could be potentially assigned to smarty
    */
   public static function &getValues(&$params, &$values) {
     if (empty($params)) {
@@ -897,10 +893,8 @@ WHERE  relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer');
    * @param array $params
    *   Array of extra values including relationship_type_id per api spec.
    *
-   * return string the query for this diretion
-   *
    * @return array
-   * @static
+   *   [select, from, where]
    */
   public static function makeURLClause($contactId, $status, $numRelationship, $count, $relationshipId, $direction, $params = array()) {
     $select = $from = $where = '';
@@ -1010,7 +1004,7 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
     }
     if (!empty($params['relationship_type_id'])) {
       if (is_array($params['relationship_type_id'])) {
-        $where .=  " AND " . CRM_Core_DAO::createSQLFilter('relationship_type_id', $params['relationship_type_id'], 'Integer');
+        $where .= " AND " . CRM_Core_DAO::createSQLFilter('relationship_type_id', $params['relationship_type_id'], 'Integer');
       }
       else {
         $where .= ' AND relationship_type_id = ' . CRM_Utils_Type::escape($params['relationship_type_id'], 'Positive');
@@ -1027,7 +1021,7 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
   }
 
   /**
-   * This is the function to get the list of relationships
+   * Get a list of relationships
    *
    * @param int $contactId
    *   Contact id.
@@ -1037,26 +1031,23 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
    *   No of relationships to display (limit).
    * @param int $count
    *   Get the no of relationships.
-   * $param int $relationshipId relationship id
-   * $param array $links the list of links to display
-   * $param int   $permissionMask  the permission mask to be applied for the actions
-   * $param boolean $permissionedContact to return only permissioned Contact
-   * $param array $params array of variables consistent with filters supported by the api
-   * return array $values relationship records
    * @param int $relationshipId
-   * @param null $links
-   * @param null $permissionMask
+   * @param array $links
+   *   the list of links to display
+   * @param int $permissionMask
+   *   the permission mask to be applied for the actions
    * @param bool $permissionedContact
+   *   to return only permissioned Contact
    * @param array $params
    *
    * @return array|int
-   * @static
+   *   relationship records
    */
-  static function getRelationship(
+  public static function getRelationship(
     $contactId = NULL,
-    $status              = 0, $numRelationship = 0,
-    $count               = 0, $relationshipId = 0,
-    $links               = NULL, $permissionMask = NULL,
+    $status = 0, $numRelationship = 0,
+    $count = 0, $relationshipId = 0,
+    $links = NULL, $permissionMask = NULL,
     $permissionedContact = FALSE,
     $params = array()
   ) {
@@ -1246,8 +1237,8 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
    * @param string $targetContactType
    *   It's valid contact tpye(may be Individual , Organization , Household).
    *
-   * @return array - array reference of all relationship types with context to current contact type .
-   *
+   * @return array
+   *   array reference of all relationship types with context to current contact type .
    */
   public function getRelationType($targetContactType) {
     $relationshipType = array();
@@ -1270,17 +1261,16 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
    * membership is is extedned by the same relationship type to that
    * of the existing relationship.
    *
-   * @param $contactId
-   *   Int contact id.
-   * @param $params
-   *   Array array of values submitted by POST.
-   * @param $ids
-   *   Array array of ids.
+   * @param int $contactId
+   *   contact id.
+   * @param array $params
+   *   array of values submitted by POST.
+   * @param array $ids
+   *   array of ids.
    * @param \const|\which $action which action called this function
    *
    * @param bool $active
    *
-   * @static
    */
   public static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = TRUE) {
     // Check the end date and set the status of the relationship
@@ -1307,7 +1297,7 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
 
     $rel = explode('_', $params['relationship_type_id']);
 
-    $relTypeId     = $rel[0];
+    $relTypeId = $rel[0];
     if (!empty($rel[1])) {
       $relDirection = "_{$rel[1]}_{$rel[2]}";
     }
@@ -1457,7 +1447,10 @@ SELECT relationship_type_id, relationship_direction
               $membershipValues['skipStatusCal'] = TRUE;
             }
             foreach (array(
-              'join_date', 'start_date', 'end_date') as $dateField) {
+                       'join_date',
+                       'start_date',
+                       'end_date',
+                     ) as $dateField) {
               if (!empty($membershipValues[$dateField])) {
                 $membershipValues[$dateField] = CRM_Utils_Date::processDate($membershipValues[$dateField]);
               }
@@ -1501,8 +1494,6 @@ SELECT count(*)
    * Helper function to check whether to delete the membership or
    * not.
    *
-   * @static
-   *
    */
   public static function isDeleteRelatedMembership($relTypeIds, $contactId, $mainRelatedContactId, $relTypeId, $relIds) {
     if (in_array($relTypeId, $relTypeIds)) {
@@ -1513,19 +1504,20 @@ SELECT count(*)
       return FALSE;
     }
 
-    $relParamas = array(1 => array($contactId, 'Integer'),
+    $relParamas = array(
+      1 => array($contactId, 'Integer'),
       2 => array($mainRelatedContactId, 'Integer'),
     );
 
     if ($contactId == $mainRelatedContactId) {
-      $recordsFound = (int)CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM civicrm_relationship WHERE relationship_type_id IN ( " . implode(',', $relTypeIds) . " )  AND contact_id_a IN ( %1 ) OR contact_id_b IN ( %1 ) AND id IN (" . implode(',', $relIds) . ")", $relParamas);
+      $recordsFound = (int) CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM civicrm_relationship WHERE relationship_type_id IN ( " . implode(',', $relTypeIds) . " )  AND contact_id_a IN ( %1 ) OR contact_id_b IN ( %1 ) AND id IN (" . implode(',', $relIds) . ")", $relParamas);
       if ($recordsFound) {
         return FALSE;
       }
       return TRUE;
     }
 
-    $recordsFound = (int)CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM civicrm_relationship WHERE relationship_type_id IN ( " . implode(',', $relTypeIds) . " ) AND contact_id_a IN ( %1, %2 ) AND contact_id_b IN ( %1, %2 ) AND id NOT IN (" . implode(',', $relIds) . ")", $relParamas);
+    $recordsFound = (int) CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM civicrm_relationship WHERE relationship_type_id IN ( " . implode(',', $relTypeIds) . " ) AND contact_id_a IN ( %1, %2 ) AND contact_id_b IN ( %1, %2 ) AND id NOT IN (" . implode(',', $relIds) . ")", $relParamas);
 
     if ($recordsFound) {
       return FALSE;
@@ -1540,7 +1532,8 @@ SELECT count(*)
    * @param $contactIds
    *   Contact Ids.
    *
-   * @return array $currentEmployer array of the current employer@static
+   * @return array
+   *   array of the current employer
    */
   public static function getCurrentEmployer($contactIds) {
     $contacts = implode(',', $contactIds);
@@ -1564,16 +1557,15 @@ WHERE id IN ( {$contacts} )
   /**
    * Return list of permissioned employer for a given contact.
    *
-   * @param $contactID
-   *   Int contact id whose employers.
-   * are to be found.
-   * @param $name
-   *   String employers sort name.
+   * @param int $contactID
+   *   contact id whose employers.
+   *   are to be found.
+   * @param string $name
+   *   employers sort name.
    *
-   * @static
-   *
-   * @return array array of employers.
    *
+   * @return array
+   *   array of employers.
    */
   public static function getPermissionedEmployer($contactID, $name = NULL) {
     //get the relationship id
@@ -1585,20 +1577,19 @@ WHERE id IN ( {$contacts} )
   }
 
 
- /**
-  * Function to return list of permissioned contacts for a given contact and relationship type
-  *
-  * @param $contactID
-  *   Int contact id whose permissioned contacts are to be found.
-  * @param $relTypeId
-  *   String one or more relationship type id's.
-  * @param $name
-  *   String.
-  *
-  * @static
-  *
-  * @return array of contacts
-  */
+  /**
+   * Function to return list of permissioned contacts for a given contact and relationship type
+   *
+   * @param int $contactID
+   *   contact id whose permissioned contacts are to be found.
+   * @param string $relTypeId
+   *   one or more relationship type id's.
+   * @param string $name
+   *
+   *
+   * @return array
+   *   Array of contacts
+   */
   public static function getPermissionedContacts($contactID, $relTypeId, $name = NULL) {
     $contacts = array();
 
@@ -1616,13 +1607,13 @@ cc.id = cr.contact_id_b AND
 cc.is_deleted = 0";
 
       if (!empty($name)) {
-        $name   = CRM_Utils_Type::escape($name, 'String');
+        $name = CRM_Utils_Type::escape($name, 'String');
         $query .= "
 AND cc.sort_name LIKE '%$name%'";
       }
 
       $args = array(1 => array($contactID, 'Integer'), 2 => array($relTypeId, 'String'));
-      $dao  = CRM_Core_DAO::executeQuery($query, $args);
+      $dao = CRM_Core_DAO::executeQuery($query, $args);
 
       while ($dao->fetch()) {
         $contacts[$dao->id] = array(
@@ -1647,7 +1638,6 @@ AND cc.sort_name LIKE '%$name%'";
    *
    * @see CRM_Dedupe_Merger::cpTables()
    *
-   * @static
    */
   public static function mergeRelationships($mainId, $otherId, &$sqls) {
     // Delete circular relationships
@@ -1681,7 +1671,8 @@ AND cc.sort_name LIKE '%$name%'";
   /**
    * Set 'is_valid' field to false for all relationships whose end date is in the past, ie. are expired.
    *
-   * @return True on success, false if error is encountered.
+   * @return bool
+   *   True on success, false if error is encountered.
    */
   public static function disableExpiredRelationships() {
     $query = "SELECT id FROM civicrm_relationship WHERE is_active = 1 AND end_date < CURDATE()";
@@ -1707,38 +1698,41 @@ AND cc.sort_name LIKE '%$name%'";
    *   Api input array.
    * @param null $direction
    *
-   * @return array
+   * @return array|void
    */
   public static function membershipTypeToRelationshipTypes(&$params, $direction = NULL) {
-    $membershipType = civicrm_api3('membership_type', 'getsingle', array('id' => $params['membership_type_id'], 'return' => 'relationship_type_id, relationship_direction'));
+    $membershipType = civicrm_api3('membership_type', 'getsingle', array(
+      'id' => $params['membership_type_id'],
+      'return' => 'relationship_type_id, relationship_direction',
+    ));
     $relationshipTypes = $membershipType['relationship_type_id'];
     if (empty($relationshipTypes)) {
-      return;
+      return NULL;
     }
     // if we don't have any contact data we can only filter on type
     if (empty($params['contact_id']) && empty($params['contact_id_a']) && empty($params['contact_id_a'])) {
       $params['relationship_type_id'] = array('IN' => $relationshipTypes);
-      return;
+      return NULL;
     }
     else {
       $relationshipDirections = (array) $membershipType['relationship_direction'];
       // if we have contact_id_a OR contact_id_b we can make a call here
       // if we have contact??
       foreach ($relationshipDirections as $index => $mtdirection) {
-        if (isset($params['contact_id_a']) && $mtdirection == 'a_b'  || $direction == 'a_b') {
+        if (isset($params['contact_id_a']) && $mtdirection == 'a_b' || $direction == 'a_b') {
           $types[] = $relationshipTypes[$index];
         }
-        if (isset($params['contact_id_b']) && $mtdirection == 'b_a'  || $direction == 'b_a') {
+        if (isset($params['contact_id_b']) && $mtdirection == 'b_a' || $direction == 'b_a') {
           $types[] = $relationshipTypes[$index];
         }
       }
       if (!empty($types)) {
         $params['relationship_type_id'] = array('IN' => $types);
       }
-      elseif(!empty($clauses)) {
+      elseif (!empty($clauses)) {
         return explode(' OR ', $clauses);
       }
-      else{
+      else {
         // effectively setting it to return no results
         $params['relationship_type_id'] = 0;
       }
@@ -1747,17 +1741,18 @@ AND cc.sort_name LIKE '%$name%'";
 
 
   /**
-   * This function is a wrapper for contact relationship selector
+   * wrapper for contact relationship selector
    *
    * @param array $params
    *   Associated array for params record id.
    *
-   * @return array   $contactRelationships associated array of contact relationships
+   * @return array
+   *   associated array of contact relationships
    */
   public static function getContactRelationshipSelector(&$params) {
     // format the params
-    $params['offset']   = ($params['page'] - 1) * $params['rp'];
-    $params['sort']     = CRM_Utils_Array::value('sortBy', $params);
+    $params['offset'] = ($params['page'] - 1) * $params['rp'];
+    $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
 
     if ($params['context'] == 'past') {
       $relationshipStatus = CRM_Contact_BAO_Relationship::INACTIVE;
@@ -1799,7 +1794,7 @@ AND cc.sort_name LIKE '%$name%'";
       // get the total relationships
       if ($params['context'] != 'user') {
         $params['total'] = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'],
-        $relationshipStatus, 0, 1, 0, NULL, NULL, $permissionedContacts);
+          $relationshipStatus, 0, 1, 0, NULL, NULL, $permissionedContacts);
       }
       else {
         // FIX ME: we cannot directly determine total permissioned relationship, hence re-fire query
@@ -1819,9 +1814,9 @@ AND cc.sort_name LIKE '%$name%'";
           $values['cid']
         );
         $contactRelationships[$relationshipId]['name'] = $icon . ' ' . CRM_Utils_System::href(
-          $values['name'],
-          'civicrm/contact/view',
-          "reset=1&cid={$values['cid']}");
+            $values['name'],
+            'civicrm/contact/view',
+            "reset=1&cid={$values['cid']}");
 
         $contactRelationships[$relationshipId]['relation'] = CRM_Utils_System::href(
           $values['relation'],