$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"
);
$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);
}
$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();
$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;
+ }
+
}