+
+ /**
+ * Add relationship to recent links
+ * @param array $params
+ * @param CRM_Contact_DAO_Relationship $relationship
+ */
+ public static function addRecent($params, $relationship) {
+ $url = CRM_Utils_System::url('civicrm/contact/view/rel',
+ "action=view&reset=1&id={$relationship->id}&cid={$relationship->contact_id_a}&context=home"
+ );
+ $session = CRM_Core_Session::singleton();
+ $recentOther = array();
+ if (($session->get('userID') == $relationship->contact_id_a) ||
+ CRM_Contact_BAO_Contact_Permission::allow($relationship->contact_id_a, CRM_Core_Permission::EDIT)
+ ) {
+ $rType = substr(CRM_Utils_Array::value('relationship_type_id', $params), -3);
+ $recentOther = array(
+ 'editUrl' => CRM_Utils_System::url('civicrm/contact/view/rel',
+ "action=update&reset=1&id={$relationship->id}&cid={$relationship->contact_id_a}&rtype={$rType}&context=home"
+ ),
+ 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/rel',
+ "action=delete&reset=1&id={$relationship->id}&cid={$relationship->contact_id_a}&rtype={$rType}&context=home"
+ ),
+ );
+ }
+ $title = CRM_Contact_BAO_Contact::displayName($relationship->contact_id_a) . ' (' . CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType',
+ $relationship->relationship_type_id, 'label_a_b'
+ ) . ' ' . CRM_Contact_BAO_Contact::displayName($relationship->contact_id_b) . ')';
+
+ CRM_Utils_Recent::add($title,
+ $url,
+ $relationship->id,
+ 'Relationship',
+ $relationship->contact_id_a,
+ NULL,
+ $recentOther
+ );
+ }
+
+ /**
+ * Resolve passed in contact IDs to contact_id_a & contact_id_b
+ * @param array $params
+ * @param array $ids
+ * @param null $contactID
+ * @throws \CRM_Core_Exception
+ */
+ public static function setContactABFromIDs(&$params, $ids = array(), $contactID = NULL) {
+ if (!empty($params['contact_id_a']) && !empty($params['contact_id_b'])) {
+ return;
+ }
+ if (empty($ids['contact'])) {
+ 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',
+ ),
+ ));
+ while ($result->fetch()) {
+ foreach ($fieldsToFill as $field) {
+ $params[$field] = !empty($params[$field]) ? $params[$field] : $result->$field;
+ }
+ }
+ return;
+ }
+ throw new CRM_Core_Exception('Cannot create relationship, insufficient contact IDs provided');
+ }
+ $relationshipTypes = CRM_Utils_Array::value('relationship_type_id', $params);
+ list($relationshipTypeID, $first, $second) = explode('_', $relationshipTypes);
+ if (empty($params['relationship_type_id'])) {
+ $params['relationship_type_id'] = $relationshipTypeID;
+ }
+ foreach (array('a', 'b') as $contactLetter) {
+ if (empty($params['contact_' . $contactLetter])) {
+ if ($first == $contactLetter) {
+ $params['contact_id_' . $contactLetter] = CRM_Utils_Array::value('contact', $ids);
+ }
+ else {
+ $params['contact_id_' . $contactLetter] = $contactID;
+ }
+ }
+ }
+ }
+