X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FRelationship.php;h=e8faf2c6d1efad08b8e2177c356599c66c25b763;hb=bdd49e3826fad29cc02081b07a81eda3455d126a;hp=33f1e9c4e6c4606e6ba19749a65d0cf29e0f3ae9;hpb=55039e98512c204e7919bd586b9e99ab176e51ea;p=civicrm-core.git diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 33f1e9c4e6..e8faf2c6d1 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -1,7 +1,7 @@ free(); - CRM_Utils_Hook::post($hook, 'Relationship', $relationshipId, $relationship); + CRM_Utils_Hook::post($hook, 'Relationship', $relationship->id, $relationship); return $relationship; } @@ -269,10 +267,9 @@ 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 - * @access public * @static */ - static function getdefaults() { + public static function getdefaults() { return array( 'is_active' => 0, 'is_permission_a_b' => 0, @@ -291,10 +288,9 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * @param array $params (reference ) an assoc array of name/value pairs * * @return boolean - * @access public * @static */ - static function dataExists(&$params) { + public static function dataExists(&$params) { // return if no data present if (!is_array(CRM_Utils_Array::value('contact_check', $params))) { return FALSE; @@ -316,7 +312,6 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * @param boolean $onlySubTypeRelationTypes if set only subtype which is passed by $contactSubType * related relationshiptypes get return * - * @access public * @static * * @return array - array reference of all relationship types with context to current contact. @@ -369,15 +364,9 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { (!$otherContactType) || $value['contact_type_b'] == $otherContactType ) && - (!$contactSubType || - (in_array($value['contact_sub_type_a'], $contactSubType) || - in_array($value['contact_sub_type_b'], $contactSubType) || - ((!$value['contact_sub_type_b'] && - !$value['contact_sub_type_a'] - ) && - !$onlySubTypeRelationTypes - ) - ) + (in_array($value['contact_sub_type_a'], $contactSubType) || + in_array($value['contact_sub_type_b'], $contactSubType) || + (!$value['contact_sub_type_a'] && !$onlySubTypeRelationTypes) ) ) { $relationshipType[$key . '_a_b'] = $value["{$column}_a_b"]; @@ -390,15 +379,9 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { (!$otherContactType) || $value['contact_type_a'] == $otherContactType ) && - (!$contactSubType || - (in_array($value['contact_sub_type_b'], $contactSubType) || - in_array($value['contact_sub_type_a'], $contactSubType) || - ((!$value['contact_sub_type_a'] && - !$value['contact_sub_type_b'] - ) && - !$onlySubTypeRelationTypes - ) - ) + (in_array($value['contact_sub_type_b'], $contactSubType) || + in_array($value['contact_sub_type_a'], $contactSubType) || + (!$value['contact_sub_type_b'] && !$onlySubTypeRelationTypes) ) ) { $relationshipType[$key . '_b_a'] = $value["{$column}_b_a"]; @@ -427,7 +410,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * * @return CRM_Contact_DAO_Relationship */ - static function clearCurrentEmployer($id, $action) { + public static function clearCurrentEmployer($id, $action) { $relationship = new CRM_Contact_DAO_Relationship(); $relationship->id = $id; $relationship->find(TRUE); @@ -456,11 +439,10 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * @param int $id relationship id * * @return null - * @access public * * @static */ - static function del($id) { + public static function del($id) { // delete from relationship table CRM_Utils_Hook::pre('delete', 'Relationship', $id, CRM_Core_DAO::$_nullArray); @@ -487,7 +469,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { $relationship->delete(); CRM_Core_Session::setStatus(ts('Selected relationship has been deleted successfully.'), ts('Record Deleted'), 'success'); - CRM_Utils_Hook::post('delete', 'Relationship', $relationship->id, $relationship); + CRM_Utils_Hook::post('delete', 'Relationship', $id, $relationship); // delete the recently created Relationship $relationshipRecent = array( @@ -507,10 +489,9 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * @param $action * * @return null - * @access public * @static */ - static function disableEnableRelationship($id, $action) { + public static function disableEnableRelationship($id, $action) { $relationship = self::clearCurrentEmployer($id, $action); if (CRM_Core_Permission::access('CiviMember')) { // create $params array which isrequired to delete memberships @@ -549,10 +530,9 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * @param int $contactId id of the contact to delete * * @return void - * @access public * @static */ - static function deleteContact($contactId) { + public static function deleteContact($contactId) { $relationship = new CRM_Contact_DAO_Relationship(); $relationship->contact_id_a = $contactId; $relationship->delete(); @@ -572,10 +552,9 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * $returns returns the contact ids in the realtionship * * @return \CRM_Contact_DAO_Relationship - * @access public * @static */ - static function getContactIds($id) { + public static function getContactIds($id) { $relationship = new CRM_Contact_DAO_Relationship(); $relationship->id = $id; @@ -594,10 +573,9 @@ 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 - * @access public * @static */ - static function checkRelationshipType($contact_a, $contact_b, $relationshipTypeId) { + public static function checkRelationshipType($contact_a, $contact_b, $relationshipTypeId) { $relationshipType = new CRM_Contact_DAO_RelationshipType(); $relationshipType->id = $relationshipTypeId; $relationshipType->selectAdd(); @@ -638,7 +616,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { @access public * @static */ - static function checkValidRelationship(&$params, &$ids, $contactId) { + public static function checkValidRelationship(&$params, &$ids, $contactId) { $errors = ''; // get the string of relationship type @@ -663,10 +641,9 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * @param integer $relationshipId this is relationship id for the contact * * @return boolean true if record exists else false - * @access public * @static */ - static function checkDuplicateRelationship(&$params, $id, $contactId = 0, $relationshipId = 0) { + public static function checkDuplicateRelationship(&$params, $id, $contactId = 0, $relationshipId = 0) { $relationshipTypeId = CRM_Utils_Array::value('relationship_type_id', $params); list($type, $first, $second) = explode('_', $relationshipTypeId); @@ -741,7 +718,7 @@ WHERE relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer'); * @return Object DAO object on success, null otherwise * @static */ - static function setIsActive($id, $is_active) { + public static function setIsActive($id, $is_active) { // as both the create & add functions have a bunch of logic in them that // doesn't seem to cope with a normal update we will call the api which // has tested handling for this @@ -772,10 +749,9 @@ 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 - * @access public * @static */ - static function &getValues(&$params, &$values) { + public static function &getValues(&$params, &$values) { if (empty($params)) { return NULL; } @@ -814,9 +790,8 @@ WHERE relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer'); * * @return array * @static - * @access public */ - static function makeURLClause($contactId, $status, $numRelationship, $count, $relationshipId, $direction, $params = array()) { + public static function makeURLClause($contactId, $status, $numRelationship, $count, $relationshipId, $direction, $params = array()) { $select = $from = $where = ''; $select = '( '; @@ -961,7 +936,6 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id) * * @return array|int * @static - * @access public */ static function getRelationship($contactId = NULL, $status = 0, $numRelationship = 0, @@ -1158,7 +1132,7 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id) * @return array - array reference of all relationship types with context to current contact type . * */ - function getRelationType($targetContactType) { + public function getRelationType($targetContactType) { $relationshipType = array(); $allRelationshipType = CRM_Core_PseudoConstant::relationshipType(); @@ -1188,7 +1162,7 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id) * * @static */ - static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = TRUE) { + 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 // accrodingly. $status = self::CURRENT; @@ -1403,7 +1377,7 @@ SELECT count(*) * @static * */ - static function isDeleteRelatedMembership($relTypeIds, $contactId, $mainRelatedContactId, $relTypeId, $relIds) { + public static function isDeleteRelatedMembership($relTypeIds, $contactId, $mainRelatedContactId, $relTypeId, $relIds) { if (in_array($relTypeId, $relTypeIds)) { return TRUE; } @@ -1440,7 +1414,7 @@ SELECT count(*) * * @return array $currentEmployer array of the current employer@static */ - static function getCurrentEmployer($contactIds) { + public static function getCurrentEmployer($contactIds) { $contacts = implode(',', $contactIds); $query = " @@ -1471,7 +1445,7 @@ WHERE id IN ( {$contacts} ) * @return array array of employers. * */ - static function getPermissionedEmployer($contactID, $name = NULL) { + public static function getPermissionedEmployer($contactID, $name = NULL) { //get the relationship id $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b' @@ -1492,7 +1466,7 @@ WHERE id IN ( {$contacts} ) * * @return array of contacts */ - static function getPermissionedContacts($contactID, $relTypeId, $name = NULL) { + public static function getPermissionedContacts($contactID, $relTypeId, $name = NULL) { $contacts = array(); if ($relTypeId) { @@ -1505,7 +1479,8 @@ cr.relationship_type_id IN (%2) AND cr.is_permission_a_b = 1 AND IF(cr.end_date IS NULL, 1, (DATEDIFF( CURDATE( ), cr.end_date ) <= 0)) AND cr.is_active = 1 AND -cc.id = cr.contact_id_b"; +cc.id = cr.contact_id_b AND +cc.is_deleted = 0"; if (!empty($name)) { $name = CRM_Utils_Type::escape($name, 'String'); @@ -1538,7 +1513,7 @@ AND cc.sort_name LIKE '%$name%'"; * * @static */ - static function mergeRelationships($mainId, $otherId, &$sqls) { + public static function mergeRelationships($mainId, $otherId, &$sqls) { // Delete circular relationships $sqls[] = "DELETE FROM civicrm_relationship WHERE (contact_id_a = $mainId AND contact_id_b = $otherId) @@ -1572,7 +1547,7 @@ AND cc.sort_name LIKE '%$name%'"; * * @return True on success, false if error is encountered. */ - static function disableExpiredRelationships() { + public static function disableExpiredRelationships() { $query = "SELECT id FROM civicrm_relationship WHERE is_active = 1 AND end_date < CURDATE()"; $dao = CRM_Core_DAO::executeQuery($query); @@ -1597,7 +1572,7 @@ AND cc.sort_name LIKE '%$name%'"; * * @return array */ - static function membershipTypeToRelationshipTypes(&$params, $direction = NULL) { + 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')); $relationshipTypes = $membershipType['relationship_type_id']; if(empty($relationshipTypes)) { @@ -1640,7 +1615,6 @@ AND cc.sort_name LIKE '%$name%'"; * @param array $params associated array for params record id. * * @return array $contactRelationships associated array of contact relationships - * @access public */ public static function getContactRelationshipSelector(&$params) { // format the params @@ -1749,4 +1723,3 @@ AND cc.sort_name LIKE '%$name%'"; } } -