}
else {
// check for duplicate relationship
- //@todo this code doesn't cope well with updates - causes e-Notices. API has a lot of code to work around
+ // @todo this code doesn't cope well with updates - causes e-Notices.
+ // API has a lot of code to work around
// this but should review this code & remove the extra handling from the api
- // it seems doubtful any of this is relevant if the contact fields & relationship type fields are not set
+ // it seems doubtful any of this is relevant if the contact fields & relationship
+ // type fields are not set
if (
self::checkDuplicateRelationship(
$params,
$validContacts = TRUE;
//validate contacts in update mode also.
- if (CRM_Utils_Array::value('contact', $ids) &&
- CRM_Utils_Array::value('contactTarget', $ids)
- ) {
+ if (!empty($ids['contact']) && !empty($ids['contactTarget'])) {
if (self::checkValidRelationship($params, $ids, $ids['contactTarget'])) {
$validContacts = FALSE;
$invalid++;
}
// do not add to recent items for import, CRM-4399
- if (!(CRM_Utils_Array::value('skipRecentView', $params) || $invalid || $duplicate)) {
+ if (!(!empty($params['skipRecentView']) || $invalid || $duplicate)) {
$url = CRM_Utils_System::url('civicrm/contact/view/rel',
"action=view&reset=1&id={$relationship->id}&cid={$relationship->contact_id_a}&context=home"
);
* @static
*/
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';
$relationshipTypes = CRM_Utils_Array::value('relationship_type_id', $params);
- // expolode the string with _ to get the relationship type id and to know which contact has to be inserted in
+ // explode the string with _ to get the relationship type id
+ // and to know which contact has to be inserted in
// contact_id_a and which one in contact_id_b
list($type, $first, $second) = explode('_', $relationshipTypes);
${'contact_' . $first} = CRM_Utils_Array::value('contact', $ids);
${'contact_' . $second} = $contactId;
- //check if the relationship type is Head of Household then update the household's primary contact with this contact.
+ // check if the relationship type is Head of Household then update the
+ // household's primary contact with this contact.
if ($type == 6) {
CRM_Contact_BAO_Household::updatePrimaryContact($contact_b, $contact_a);
}
$relationship->save();
// add custom field values
- if (CRM_Utils_Array::value('custom', $params)) {
+ if (!empty($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_relationship', $relationship->id);
}
$relationshipTypeId = CRM_Utils_Array::value('relationship_type_id', $params);
list($type, $first, $second) = explode('_', $relationshipTypeId);
- $queryString = " SELECT id
- FROM civicrm_relationship
- WHERE relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer');
+ $queryString = "
+SELECT id
+FROM civicrm_relationship
+WHERE relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer');
/*
- * CRM-11792 - date fields from API are in ISO format, but this function supports date arrays
- * BAO has increasingly standardised to ISO format so I believe this function should support
- * ISO rather than make API format it - however, need to support array format for now to avoid breakage
+ * CRM-11792 - date fields from API are in ISO format, but this function
+ * supports date arrays BAO has increasingly standardised to ISO format
+ * so I believe this function should support ISO rather than make API
+ * format it - however, need to support array format for now to avoid breakage
* @ time of writing this function is called from Relationship::create (twice)
* CRM_BAO_Contact_Utils::clearCurrentEmployer (seemingly without dates)
* CRM_Contact_Form_Task_AddToOrganization::postProcess &
foreach ($dateFields as $dateField){
if(array_key_exists($dateField, $params)) {
if (empty($params[$dateField]) || $params[$dateField] == 'null'){
- //this is most likely coming from an api call & probably loaded from the DB to deal with some of the
- //other myriad of excessive checks still in place both in the api & the create functions
+ //this is most likely coming from an api call & probably loaded
+ // from the DB to deal with some of the
+ // other myriad of excessive checks still in place both in
+ // the api & the create functions
$queryString .= " AND $dateField IS NULL";
continue;
}
elseif (is_array($params[$dateField])){
- $queryString .= " AND $dateField = " . CRM_Utils_Type::escape(CRM_Utils_Date::format($params[$dateField]), 'Date');
+ $queryString .= " AND $dateField = " .
+ CRM_Utils_Type::escape(CRM_Utils_Date::format($params[$dateField]), 'Date');
}
- else{
- $queryString .= " AND $dateField = " . CRM_Utils_Type::escape($params[$dateField], 'Date');
+ else {
+ $queryString .= " AND $dateField = " .
+ CRM_Utils_Type::escape($params[$dateField], 'Date');
}
}
}
$v = array();
// get the specific number of relationship or all relationships.
- if (CRM_Utils_Array::value('numRelationship', $params)) {
+ if (!empty($params['numRelationship'])) {
$v['data'] = &CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], NULL, $params['numRelationship']);
}
else {
$order = $limit = '';
if (!$count) {
- $order = ' ORDER BY civicrm_relationship_type_id, sort_name ';
+ if (empty($params['sort'])) {
+ $order = ' ORDER BY civicrm_relationship_type_id, sort_name ';
+ }
+ else {
+ $order = " ORDER BY {$params['sort']} ";
+ }
+
+ $offset = 0;
+ if (!empty($params['offset'])) {
+ $offset = $params['offset'];
+ }
if ($numRelationship) {
- $limit = " LIMIT 0, $numRelationship";
+ $limit = " LIMIT {$offset}, $numRelationship";
}
}
// building the query string
- $queryString = '';
$queryString = $select1 . $from1 . $where1 . $select2 . $from2 . $where2 . $order . $limit;
$relationship = new CRM_Contact_DAO_Relationship();
}
}
- $values[$rid]['action'] = CRM_Core_Action::formLink($links, $mask, $replace);
+ $values[$rid]['action'] = CRM_Core_Action::formLink(
+ $links,
+ $mask,
+ $replace,
+ ts('more'),
+ FALSE,
+ 'relationship.selector.row',
+ 'Relationship',
+ $rid);
unset($links[CRM_Core_Action::MAX_ACTION]);
}
}
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipValues['membership_type_id']);
// Check if contact's relationship type exists in membership type
$relTypeDirs = array();
- if (CRM_Utils_Array::value('relationship_type_id', $membershipType)) {
+ if (!empty($membershipType['relationship_type_id'])) {
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
}
- if (CRM_Utils_Array::value('relationship_direction', $membershipType)) {
+ if (!empty($membershipType['relationship_direction'])) {
$relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
}
foreach ($relTypeIds as $key => $value) {
}
foreach (array(
'join_date', 'start_date', 'end_date') as $dateField) {
- if (CRM_Utils_Array::value($dateField, $membershipValues)) {
+ if (!empty($membershipValues[$dateField])) {
$membershipValues[$dateField] = CRM_Utils_Date::processDate($membershipValues[$dateField]);
}
}
* 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 relationship type id
+ * @param $relTypeId string one or more relationship type id's
* @param $name string
*
* @static
FROM civicrm_relationship cr, civicrm_contact cc
WHERE
cr.contact_id_a = %1 AND
-cr.relationship_type_id = %2 AND
+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
AND cc.sort_name LIKE '%$name%'";
}
- $args = array(1 => array($contactID, 'Integer'), 2 => array($relTypeId, 'Integer'));
+ $args = array(1 => array($contactID, 'Integer'), 2 => array($relTypeId, 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $args);
while ($dao->fetch()) {
return $contacts;
}
- static function getValidContactTypeList($relType) {
- // string looks like 4_a_b
- $rel_parts = explode('_', $relType);
- $allRelationshipType = CRM_Core_PseudoConstant::relationshipType('label');
- $contactProfiles = CRM_Core_BAO_UFGroup::getReservedProfiles('Contact', NULL);
-
- if ($rel_parts[1] == 'a') {
- $leftType = $allRelationshipType[$rel_parts[0]]['contact_type_b'];
- }
- else {
- $leftType = $allRelationshipType[$rel_parts[0]]['contact_type_a'];
- }
-
- // Handle 'All Contacts' contact type for left side of relationship ($leftType is empty in this case)
- // In this case all reserved profiles are available
- if ($leftType == '') {
- $contactTypes = $contactProfiles;
- } else {
- $contactTypes = array();
- foreach ($contactProfiles as $key => $value) {
- if (strpos($value, $leftType) !== FALSE) {
- $contactTypes = array($key => $value);
- }
- }
- }
-
- return $contactTypes;
- }
-
/**
* Merge relationships from otherContact to mainContact
* Called during contact merge operation
}
}
}
+
+
+ /**
+ * This function is a wrapper for contact relationship selector
+ *
+ * @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
+ $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;
+ }
+ else {
+ $relationshipStatus = CRM_Contact_BAO_Relationship::CURRENT;
+ }
+
+ // check logged in user for permission
+ $page = new CRM_Core_Page();
+ CRM_Contact_Page_View::checkUserPermission($page, $params['contact_id']);
+ $permissions = array($page->_permission);
+ if ($page->_permission == CRM_Core_Permission::EDIT) {
+ $permissions[] = CRM_Core_Permission::DELETE;
+ }
+ $mask = CRM_Core_Action::mask($permissions);
+
+ // get contact relationships
+ $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'],
+ $relationshipStatus,
+ $params['rp'], 0, 0,
+ CRM_Contact_Page_View_Relationship::links(), $mask,
+ FALSE,
+ $params
+ );
+
+ $contactRelationships = array();
+ if (!empty($relationships)) {
+ // add total
+ $params['total'] = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'],
+ $relationshipStatus,
+ 0, 1);
+
+ // format params
+ foreach ($relationships as $relationshipId => $values) {
+ $contactRelationships[$relationshipId]['name'] = CRM_Utils_System::href(
+ $values['name'],
+ 'civicrm/contact/view',
+ "reset=1&cid={$values['contact_id_b']}");
+
+ $contactRelationships[$relationshipId]['relation'] = CRM_Utils_System::href(
+ $values['relation'],
+ 'civicrm/contact/view/rel',
+ "action=view&reset=1&cid={$values['contact_id_a']}&id={$values['id']}&rtype={$values['rtype']}");
+
+ if ($params['context'] != 'past') {
+ if (($params['contact_id'] == $values['contact_id_a'] AND $values['is_permission_a_b'] == 1) OR
+ ($params['contact_id'] == $values['contact_id_b'] AND $values['is_permission_b_a'] == 1)
+ ) {
+ $contactRelationships[$relationshipId]['name'] .= '<span id="permission-a-b" class="crm-marker permission-relationship"> *</span>';
+ }
+
+ if (($values['cid'] == $values['contact_id_a'] AND $values['is_permission_a_b'] == 1) OR
+ ($values['cid'] == $values['contact_id_b'] AND $values['is_permission_b_a'] == 1)
+ ) {
+ $contactRelationships[$relationshipId]['relation'] .= '<span id="permission-b-a" class="crm-marker permission-relationship"> *</span>';
+ }
+ }
+
+ if (!empty($values['description'])) {
+ $contactRelationships[$relationshipId]['relation'] .= "<p class='description'>{$values['description']}</p>";
+ }
+
+ $contactRelationships[$relationshipId]['start_date'] = CRM_Utils_Date::customFormat($values['start_date']);
+ $contactRelationships[$relationshipId]['end_date'] = CRM_Utils_Date::customFormat($values['end_date']);
+ $contactRelationships[$relationshipId]['city'] = $values['city'];
+ $contactRelationships[$relationshipId]['state'] = $values['state'];
+ $contactRelationships[$relationshipId]['email'] = $values['email'];
+ $contactRelationships[$relationshipId]['phone'] = $values['phone'];
+ $contactRelationships[$relationshipId]['links'] = $values['action'];
+ $contactRelationships[$relationshipId]['id'] = $values['id'];
+ }
+ }
+ return $contactRelationships;
+ }
+
}