/** * This function is called when action is browse * * return null * @access public */ function browse() { $links =& CRM_Contact_Page_View_Relationship::links(); $mask = CRM_Core_Action::mask($this->_permission); $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_CONTACT_BAO_RELATIONSHIP_CURRENT, 0, 0, 0, $links, $mask); $pastRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_CONTACT_BAO_RELATIONSHIP_PAST, 0, 0, 0, $links, $mask); $disableRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_CONTACT_BAO_RELATIONSHIP_DISABLED, 0, 0, 0, $links, $mask); $this->assign('currentRelationships', $currentRelationships); $this->assign('pastRelationships', $pastRelationships); $this->assign('disableRelationships', $disableRelationships); }
static function isUserTeamAdmin($userId) { if (empty($userId)) { return NULL; } require_once 'CRM/Contact/BAO/Relationship.php'; $getUserRelationships = CRM_Contact_BAO_Relationship::getRelationship($userId, CRM_Contact_BAO_Relationship::CURRENT); // Team Admin Relationship $relTypeAdmin = CRM_Pcpteams_Constant::C_TEAM_ADMIN_REL_TYPE; $adminRelTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $relTypeAdmin, 'id', 'name_a_b'); foreach ($getUserRelationships as $value) { //check the user is admin of team. return team id if found one if ($value['relationship_type_id'] == $adminRelTypeId) { return array('id' => $value['contact_id_b'], 'state' => 'Team'); } } return null; }
/** * View details of a relationship. */ public function view() { $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, NULL, NULL, NULL, $this->_id); //To check whether selected contact is a contact_id_a in //relationship type 'a_b' in relationship table, if yes then //revert the permissionship text in template $relationship = new CRM_Contact_DAO_Relationship(); $relationship->id = $viewRelationship[$this->_id]['id']; if ($relationship->find(TRUE)) { if ($viewRelationship[$this->_id]['rtype'] == 'a_b' && $this->_contactId == $relationship->contact_id_a) { $this->assign("is_contact_id_a", TRUE); } } $relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id']; $this->assign('viewRelationship', $viewRelationship); $employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'employer_id'); $this->assign('isCurrentEmployer', FALSE); $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name')); if ($viewRelationship[$this->_id]['employer_id'] == $this->_contactId) { $this->assign('isCurrentEmployer', TRUE); } elseif ($relType == $relTypes['Employee of']['id'] && $viewRelationship[$this->_id]['cid'] == $employerId) { // make sure we are viewing employee of relationship $this->assign('isCurrentEmployer', TRUE); } $viewNote = CRM_Core_BAO_Note::getNote($this->_id); $this->assign('viewNote', $viewNote); $groupTree = CRM_Core_BAO_CustomGroup::getTree('Relationship', $this, $this->_id, 0, $relType); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id); $rType = CRM_Utils_Array::value('rtype', $viewRelationship[$this->_id]); // add viewed contribution to recent items list $url = CRM_Utils_System::url('civicrm/contact/view/rel', "action=view&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&context=home"); $session = CRM_Core_Session::singleton(); $recentOther = array(); if ($session->get('userID') == $this->_contactId || CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', "action=update&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', "action=delete&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home")); } $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); $this->assign('displayName', $displayName); CRM_Utils_System::setTitle(ts('View Relationship for') . ' ' . $displayName); $title = $displayName . ' (' . $viewRelationship[$this->_id]['relation'] . ' ' . CRM_Contact_BAO_Contact::displayName($viewRelationship[$this->_id]['cid']) . ')'; // add the recently viewed Relationship CRM_Utils_Recent::add($title, $url, $viewRelationship[$this->_id]['id'], 'Relationship', $this->_contactId, NULL, $recentOther); }
public static function getCaseClientRelationships() { $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE); $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } // sort clientRelationships array using jquery call params foreach ($clientRelationships as $key => $row) { $sortArray[$key] = $row[$params['_raw_values']['sort'][0]]; } $sort_type = "SORT_" . strtoupper($params['_raw_values']['order'][0]); array_multisort($sortArray, constant($sort_type), $clientRelationships); $relationships = array(); // after sort we can update username fields to be a url foreach ($clientRelationships as $key => $value) { $relationship = array(); $relationship['relation'] = $value['relation']; $relationship['name'] = '<a href=' . CRM_Utils_System::url('civicrm/contact/view', 'action=view&reset=1&cid=' . $clientRelationships[$key]['cid']) . '>' . $clientRelationships[$key]['name'] . '</a>'; $relationship['phone'] = $value['phone']; $relationship['email'] = $value['email']; array_push($relationships, $relationship); } $clientRelationshipsDT = array(); $clientRelationshipsDT['data'] = $relationships; $clientRelationshipsDT['recordsTotal'] = count($relationships); $clientRelationshipsDT['recordsFiltered'] = count($relationships); CRM_Utils_JSON::output($clientRelationshipsDT); }
/** * Given the list of params in the params array, fetch the object * and store the values in the values array * * @param array $params input parameters to find object * @param array $values output values of the object * @param array $ids the array that holds all the db ids * * @return array (reference) the values that could be potentially assigned to smarty * @access public * @static */ static function &getValues(&$params, &$values) { if (empty($params)) { return NULL; } $v = array(); // get the specific number of relationship or all relationships. if (CRM_Utils_Array::value('numRelationship', $params)) { $v['data'] =& CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], NULL, $params['numRelationship']); } else { $v['data'] = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id']); } // get the total count of relationships $v['totalCount'] = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], NULL, NULL, TRUE); $values['relationship']['data'] =& $v['data']; $values['relationship']['totalCount'] =& $v['totalCount']; return $v; }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js')->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); //adding case manager.CRM-4510. $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE); $allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); $emailActivityType = array_search('Email', $allActTypes); $pdfActivityType = array_search('Print PDF Letter', $allActTypes); // remove Open Case activity type since we're inside an existing case if ($openActTypeId = array_search('Open Case', $allActTypes)) { unset($aTypes[$openActTypeId]); } //check for link cases. $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases(NULL, array($this->_caseID)); if (empty($unclosedCases) && ($linkActTypeId = array_search('Link Cases', $allActTypes))) { unset($aTypes[$linkActTypeId]); } if (!$xmlProcessor->getNaturalActivityTypeSort()) { asort($aTypes); } $activityLinks = array('' => ts('Add Activity')); foreach ($aTypes as $type => $label) { if ($type == $emailActivityType) { $url = CRM_Utils_System::url('civicrm/activity/email/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { if ($type == $pdfActivityType) { $url = CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { $url = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } } $activityLinks[$url] = $label; } $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-plus twenty')); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', '', array('' => ts('Activity Audit')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-clipboard')); $this->add('select', 'timeline_id', '', array('' => ts('Add Timeline')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-play')); } $this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement')); if ($this->_mergeCases) { $allCases = CRM_Case_BAO_Case::getContactCases($this->_contactID); $otherCases = array(); foreach ($allCases as $caseId => $details) { //filter current and own cases. if ($caseId == $this->_caseID || !$this->_hasAccessToAllCases && !array_key_exists($caseId, $this->_userCases)) { continue; } $otherCases[$caseId] = 'Case ID: ' . $caseId . ' Type: ' . $details['case_type'] . ' Start: ' . $details['case_start_date']; } if (empty($otherCases)) { $this->_mergeCases = FALSE; $this->assign('mergeCases', $this->_mergeCases); } else { $this->add('select', 'merge_case_id', ts('Select Case for Merge'), array('' => ts('- select case -')) + $otherCases, FALSE, array('class' => 'crm-select2 huge')); $this->addElement('submit', $this->getButtonName('next', 'merge_case'), ts('Merge'), array('class' => 'crm-form-submit-inline hiddenElement')); } } //call activity form self::activityForm($this); //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //save special label because we unset it in the loop $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; foreach ($caseRelationships as $key => &$value) { if (!empty($managerRoleId)) { if ($managerRoleId == $value['relation_type']) { $value['relation'] = $managerLabel; } } //calculate roles that don't have relationships if (!empty($caseRoles[$value['relation_type']])) { unset($caseRoles[$value['relation_type']]); } } $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } $this->assign('clientRelationships', $clientRelationships); // Now global contact list that appears on all cases. $globalGroupInfo = array(); CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalGroupInfo', $globalGroupInfo); // List of relationship types $baoRel = new CRM_Contact_BAO_Relationship(); $relType = $baoRel->getRelationType('Individual'); $roleTypes = array(); foreach ($relType as $k => $v) { $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; } $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes, FALSE, array('class' => 'crm-select2 twenty')); $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } $allTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { if (isset($allTags[$tid])) { $tags[$tid] = $allTags[$tid]; } else { unset($tags[$tid]); } } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', TRUE); } else { $this->assign('showTags', FALSE); } // build tagset widget // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); if ($parentNames) { $this->assign('showTagsets', TRUE); } else { $this->assign('showTagsets', FALSE); } CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => TRUE))); }
/** * Function to check the membership extended through relationship * * @param int $membershipId membership id * @param int $contactId contact id * * @return Array array of contact_id of all related contacts. * @static */ static function checkMembershipRelationship($membershipId, $contactId, $action = CRM_Core_Action::ADD) { $contacts = array(); $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $membershipId, 'membership_type_id'); require_once 'CRM/Member/BAO/MembershipType.php'; $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID); require_once 'CRM/Contact/BAO/Relationship.php'; $relationships = array(); if (isset($membershipType['relationship_type_id'])) { $relationships = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::CURRENT); if ($action & CRM_Core_Action::UPDATE) { $pastRelationships = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::PAST); $relationships = array_merge($relationships, $pastRelationships); } } if (!empty($relationships)) { require_once "CRM/Contact/BAO/RelationshipType.php"; // check for each contact relationships foreach ($relationships as $values) { //get details of the relationship type $relType = array('id' => $values['civicrm_relationship_type_id']); $relValues = array(); CRM_Contact_BAO_RelationshipType::retrieve($relType, $relValues); // 1. Check if contact and membership type relationship type are same // 2. Check if relationship direction is same or name_a_b = name_b_a if ($values['civicrm_relationship_type_id'] == $membershipType['relationship_type_id'] && ($values['rtype'] == $membershipType['relationship_direction'] || $relValues['name_a_b'] == $relValues['name_b_a'])) { // $values['status'] is going to have value for // current or past relationships. $contacts[$values['cid']] = $values['status']; } } } return $contacts; }
/** * Function to build user dashboard * * @return none * @access public */ function buildUserDashBoard() { //build component selectors $dashboardElements = array(); $config =& CRM_Core_Config::singleton(); require_once 'CRM/Core/BAO/Preferences.php'; $this->_userOptions = CRM_Core_BAO_Preferences::valueOptions('user_dashboard_options'); $components = CRM_Core_Component::getEnabledComponents(); foreach ($components as $name => $component) { $elem = $component->getUserDashboardElement(); if (!$elem) { continue; } if (CRM_Utils_Array::value($name, $this->_userOptions) && (CRM_Core_Permission::access($component->name) || CRM_Core_Permission::check($elem['perm'][0]))) { $userDashboard = $component->getUserDashboardObject(); $dashboardElements[] = array('templatePath' => $userDashboard->getTemplateFileName(), 'sectionTitle' => $elem['title'], 'weight' => $elem['weight']); $userDashboard->run(); } } $sectionName = 'Permissioned Orgs'; if ($this->_userOptions[$sectionName]) { $dashboardElements[] = array('templatePath' => 'CRM/Contact/Page/View/Relationship.tpl', 'sectionTitle' => ts('Your Contacts / Organizations'), 'weight' => 40); $links =& self::links(); $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, $links, null, true); $this->assign('currentRelationships', $currentRelationships); } if ($this->_userOptions['PCP']) { require_once 'CRM/Contribute/BAO/PCP.php'; $dashboardElements[] = array('templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl', 'sectionTitle' => ts('Personal Campaign Pages'), 'weight' => 40); list($pcpBlock, $pcpInfo) = CRM_Contribute_BAO_PCP::getPcpDashboardInfo($this->_contactId); $this->assign('pcpBlock', $pcpBlock); $this->assign('pcpInfo', $pcpInfo); } require_once 'CRM/Utils/Sort.php'; usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('dashboardElements', $dashboardElements); if ($this->_userOptions['Groups']) { $this->assign('showGroup', true); //build group selector require_once "CRM/Contact/Page/View/UserDashBoard/GroupContact.php"; $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact(); $gContact->run(); } else { $this->assign('showGroup', false); } }
/** * Function to check whether allow to edit any contact's subtype * on the basis of custom data and relationship of specific subtype * * @param int $contactId contact id. * @param string $subType subtype. * * @return boolean true/false. * @static */ static function allowEditSubtype($contactId, $subType, $groupTree = null) { if (!$contactId || empty($subType)) { return true; } require_once 'CRM/Contact/BAO/ContactType.php'; $contactType = CRM_Contact_BAO_ContactType::getBasicType($subType); $subTypeGroupTree = array(); if (!array_key_exists($contactType . '_' . $subType, $subTypeGroupTree) && empty($groupTree)) { $form = null; require_once 'CRM/Core/BAO/CustomGroup.php'; $subTypeGroupTree[$contactType . '_' . $subType] = CRM_Core_BAO_CustomGroup::getTree($contactType, $form, $contactId, null, $subType, null); } else { $subTypeGroupTree[$contactType . '_' . $subType] = $groupTree; } if (!empty($subTypeGroupTree[$contactType . '_' . $subType])) { foreach ($subTypeGroupTree[$contactType . '_' . $subType] as $groupId => $groupDetails) { if (CRM_Utils_Array::value('extends_entity_column_value', $groupDetails)) { $customValue = CRM_Utils_Array::retrieveValueRecursive($groupDetails['fields'], 'element_value'); if (!empty($customValue)) { return false; } else { continue; } } } } if (!array_key_exists('rel_' . $contactType . '_' . $subType, $subTypeGroupTree)) { require_once 'CRM/Contact/BAO/Relationship.php'; $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $contactType, false, 'label', true, $subType, true); $subTypeGroupTree['rel_' . $contactType . '_' . $subType] = $relationshipTypes; } $relationships = CRM_Contact_BAO_Relationship::getRelationship($contactId); if (!empty($relationships)) { foreach ($relationships as $relId => $details) { if (in_array($details['relation'], $subTypeGroupTree['rel_' . $contactType . '_' . $subType])) { return false; } else { continue; } } } return true; }
/** * Wrapper for contact relationship selector. * * @param array $params * Associated array for params record id. * * @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); if ($params['context'] == 'past') { $relationshipStatus = CRM_Contact_BAO_Relationship::INACTIVE; } elseif ($params['context'] == 'all') { $relationshipStatus = CRM_Contact_BAO_Relationship::ALL; } 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); $permissionedContacts = TRUE; if ($params['context'] != 'user') { $links = CRM_Contact_Page_View_Relationship::links(); } else { $links = CRM_Contact_Page_View_UserDashBoard::links(); $mask = NULL; } // get contact relationships $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], $relationshipStatus, $params['rp'], 0, 0, $links, $mask, $permissionedContacts, $params); $contactRelationships = array(); $params['total'] = 0; if (!empty($relationships)) { // FIXME: we cannot directly determine total permissioned relationship, hence re-fire query $permissionedRelationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], $relationshipStatus, 0, 0, 0, NULL, NULL, $permissionedContacts); $params['total'] = count($permissionedRelationships); // format params foreach ($relationships as $relationshipId => $values) { $relationship = array(); $relationship['DT_RowId'] = $values['id']; $relationship['DT_RowClass'] = 'crm-entity'; if ($values['is_active'] == 0) { $relationship['DT_RowClass'] .= ' disabled'; } $relationship['DT_RowAttr'] = array(); $relationship['DT_RowAttr']['data-entity'] = 'relationship'; $relationship['DT_RowAttr']['data-id'] = $values['id']; //Add image icon for related contacts: CRM-14919 $icon = CRM_Contact_BAO_Contact_Utils::getImage($values['contact_type'], FALSE, $values['cid']); $relationship['sort_name'] = $icon . ' ' . CRM_Utils_System::href($values['name'], 'civicrm/contact/view', "reset=1&cid={$values['cid']}"); $relationship['relation'] = CRM_Utils_System::href($values['relation'], 'civicrm/contact/view/rel', "action=view&reset=1&cid={$values['cid']}&id={$values['id']}&rtype={$values['rtype']}"); if ($params['context'] == 'current') { 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) { $relationship['sort_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) { $relationship['relation'] .= '<span id="permission-b-a" class="crm-marker permission-relationship"> *</span>'; } } if (!empty($values['description'])) { $relationship['relation'] .= "<p class='description'>{$values['description']}</p>"; } $relationship['start_date'] = CRM_Utils_Date::customFormat($values['start_date']); $relationship['end_date'] = CRM_Utils_Date::customFormat($values['end_date']); $relationship['city'] = $values['city']; $relationship['state'] = $values['state']; $relationship['email'] = $values['email']; $relationship['phone'] = $values['phone']; $relationship['links'] = $values['action']; array_push($contactRelationships, $relationship); } } $relationshipsDT = array(); $relationshipsDT['data'] = $contactRelationships; $relationshipsDT['recordsTotal'] = $params['total']; $relationshipsDT['recordsFiltered'] = $params['total']; return $relationshipsDT; }
/** * Given the component name and returns the count of participation of contact. * * @param string $component * Input component name. * @param int $contactId * Input contact id. * @param string $tableName * Optional tableName if component is custom group. * * @return int * total number in database */ public static function getCountComponent($component, $contactId, $tableName = NULL) { $object = NULL; switch ($component) { case 'tag': return CRM_Core_BAO_EntityTag::getContactTags($contactId, TRUE); case 'rel': $result = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 1); return $result; case 'group': return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, "Added", NULL, TRUE); case 'log': if (CRM_Core_BAO_Log::useLoggingReport()) { return FALSE; } return CRM_Core_BAO_Log::getContactLogCount($contactId); case 'note': return CRM_Core_BAO_Note::getContactNoteCount($contactId); case 'contribution': return CRM_Contribute_BAO_Contribution::contributionCount($contactId); case 'membership': return CRM_Member_BAO_Membership::getContactMembershipCount($contactId, TRUE); case 'participant': return CRM_Event_BAO_Participant::getContactParticipantCount($contactId); case 'pledge': return CRM_Pledge_BAO_Pledge::getContactPledgeCount($contactId); case 'case': return CRM_Case_BAO_Case::caseCount($contactId); case 'grant': return CRM_Grant_BAO_Grant::getContactGrantCount($contactId); case 'activity': $input = array('contact_id' => $contactId, 'admin' => FALSE, 'caseId' => NULL, 'context' => 'activity'); return CRM_Activity_BAO_Activity::getActivitiesCount($input); case 'mailing': $params = array('contact_id' => $contactId); return CRM_Mailing_BAO_Mailing::getContactMailingsCount($params); default: $custom = explode('_', $component); if ($custom['0'] = 'custom') { if (!$tableName) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $custom['1'], 'table_name'); } $queryString = "SELECT count(id) FROM {$tableName} WHERE entity_id = {$contactId}"; return CRM_Core_DAO::singleValueQuery($queryString); } } }
/** * This function is called when action is browse * * return null * @access public */ function browse() { $links =& self::links(); //CRM-4418, handling edit and delete separately. $permissions = array($this->_permission); if ($this->_permission == CRM_Core_Permission::EDIT) { //previously delete was subset of edit //so for consistency lets grant delete also. $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, $links, $mask); $inactiveRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_Contact_BAO_Relationship::INACTIVE, 0, 0, 0, $links, $mask); $this->assign('currentRelationships', $currentRelationships); // to show the 'Current Relationships' title and links only when viewed // from relationship tab, not from dashboard $this->assign('relationshipTabContext', true); $this->assign('inactiveRelationships', $inactiveRelationships); }
/** * Function to get the relationship * * @param array $params input parameters. * @todo Result is inconsistent depending on whether contact_id is passed in : * - if you pass in contact_id - it just returns all relationships for 'contact_id' * - if you don't pass in contact_id then it does a filter on the relationship table (DAO based search) * * @return Array API Result Array * {@getfields relationship_get} * @example RelationshipGet.php * @access public */ function civicrm_api3_relationship_get($params) { if (!CRM_Utils_Array::value('contact_id', $params)) { $relationships = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE); } else { $relationships = array(); $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], CRM_Utils_Array::value('status_id', $params), 0, 0, CRM_Utils_Array::value('id', $params), NULL); } foreach ($relationships as $relationshipId => $values) { _civicrm_api3_custom_data_get($relationships[$relationshipId], 'Relationship', $relationshipId, NULL, CRM_Utils_Array::value('relationship_type_id', $values)); } return civicrm_api3_create_success($relationships, $params); }
public static function getCaseClientRelationships() { $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); $sortMapper = array(0 => 'relation', 1 => 'name', 2 => 'phone', 3 => 'email'); $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation'; $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; $params = $_POST; if ($sort && $sortOrder) { $sortSQL = $sort . ' ' . $sortOrder; } // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE); $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } // sort clientRelationships array using jquery call params foreach ($clientRelationships as $key => $row) { $sortArray[$key] = $row[$sort]; } $sort_type = "SORT_" . strtoupper($sortOrder); array_multisort($sortArray, constant($sort_type), $clientRelationships); //limit the rows $allClientRelationships = $clientRelationships; $clientRelationships = array_slice($allClientRelationships, $offset, $rowCount, TRUE); // after sort we can update username fields to be a url foreach ($clientRelationships as $key => $value) { $clientRelationships[$key]['name'] = '<a href=' . CRM_Utils_System::url('civicrm/contact/view', 'action=view&reset=1&cid=' . $clientRelationships[$key]['cid']) . '>' . $clientRelationships[$key]['name'] . '</a>'; } $iFilteredTotal = $iTotal = $params['total'] = count($allClientRelationships); $selectorElements = array('relation', 'name', 'phone', 'email'); header('Content-Type: application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($clientRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); //adding case manager.CRM-4510. $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', true); require_once 'CRM/Core/PseudoConstant.php'; $allActTypes = CRM_Core_PseudoConstant::activityType(true, true, false, 'name'); // remove Open Case activity type since we're inside an existing case if (($openActTypeId = array_search('Open Case', $allActTypes)) && array_key_exists($openActTypeId, $aTypes)) { unset($aTypes[$openActTypeId]); } //check for link cases. $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases(null, array($this->_caseID)); if (empty($unclosedCases) && ($linkActTypeId = array_search('Link Cases', $allActTypes)) && array_key_exists($linkActTypeId, $aTypes)) { unset($aTypes[$linkActTypeId]); } asort($aTypes); $this->add('select', 'activity_type_id', ts('New Activity'), array('' => ts('- select activity type -')) + $aTypes); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', ts('Run QA Audit / Redact'), array('' => ts('- select activity set -')) + $reports); $this->add('select', 'timeline_id', ts('Add Timeline'), array('' => ts('- select activity set -')) + $reports); } $this->addElement('submit', $this->getButtonName('next'), ts('Go'), array('class' => 'form-submit-inline', 'onclick' => "return checkSelection( this );")); if ($this->_mergeCases) { $allCases = CRM_Case_BAO_Case::getContactCases($this->_contactID); $otherCases = array(); foreach ($allCases as $caseId => $details) { //filter current and own cases. if ($caseId == $this->_caseID || !$this->_hasAccessToAllCases && !array_key_exists($caseId, $this->_userCases)) { continue; } $otherCases[$caseId] = 'Case ID: ' . $caseId . ' Type: ' . $details['case_type'] . ' Start: ' . $details['case_start_date']; } if (empty($otherCases)) { $this->_mergeCases = false; $this->assign('mergeCases', $this->_mergeCases); } else { $this->add('select', 'merge_case_id', ts('Select Case for Merge'), array('' => ts('- select case -')) + $otherCases); $this->addElement('submit', $this->getButtonName('next', 'merge_case'), ts('Merge'), array('class' => 'form-submit-inline', 'onclick' => "return checkSelection( this );")); } } $this->add('text', 'change_client_id', ts('Assign to another Client')); $this->add('hidden', 'contact_id', '', array('id' => 'contact_id')); $this->addElement('submit', $this->getButtonName('next', 'edit_client'), ts('Reassign Case'), array('class' => 'form-submit-inline', 'onclick' => "return checkSelection( this );")); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $this->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus); // activity dates $this->addDate('activity_date_low', ts('Activity Dates - From'), false, array('formatType' => 'searchDate')); $this->addDate('activity_date_high', ts('To'), false, array('formatType' => 'searchDate')); require_once "CRM/Core/Permission.php"; if (CRM_Core_Permission::check('administer CiviCRM')) { $this->add('checkbox', 'activity_deleted', ts('Deleted Activities')); } //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //build reporter select $reporters = array("" => ts(' - any reporter - ')); foreach ($caseRelationships as $key => &$value) { $reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )"; if ($managerRoleId == $value['relation_type']) { $value['relation'] = $caseRoles[$managerRoleId]; } //calculate roles that don't have relationships if (CRM_Utils_Array::value($value['relation_type'], $caseRoles)) { unset($caseRoles[$value['relation_type']]); } } // take all case activity types for search filter, CRM-7187 $aTypesFilter = array(); $allCaseActTypes = CRM_Case_PseudoConstant::activityType(); foreach ($allCaseActTypes as $typeDetails) { if (!in_array($typeDetails['name'], array('Open Case'))) { $aTypesFilter[$typeDetails['id']] = CRM_Utils_Array::value('label', $typeDetails); } } asort($aTypesFilter); $this->add('select', 'activity_type_filter_id', ts('Activity Type'), array('' => ts('- select activity type -')) + $aTypesFilter); $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); $this->add('select', 'reporter_id', ts('Reporter/Role'), $reporters); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, null, null, false); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } $this->assign('clientRelationships', $clientRelationships); // Now global contact list that appears on all cases. $globalGroupInfo = array(); $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalRelationships', $relGlobal); $this->assign('globalGroupInfo', $globalGroupInfo); // List of relationship types require_once 'CRM/Contact/BAO/Relationship.php'; $baoRel = new CRM_Contact_BAO_Relationship(); $relType = $baoRel->getRelationType('Individual'); $roleTypes = array(); foreach ($relType as $k => $v) { $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; } $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes); require_once 'CRM/Utils/Hook.php'; $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } require_once 'CRM/Core/BAO/EntityTag.php'; require_once 'CRM/Core/BAO/Tag.php'; $allTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, false, array('id' => 'tags', 'multiple' => 'multiple', 'title' => ts('- select -'))); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { $tags[$tid] = $allTags[$tid]; } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', true); } else { $this->assign('showTags', false); } // build tagset widget require_once 'CRM/Core/Form/Tag.php'; // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); if ($parentNames) { $this->assign('showTagsets', true); } else { $this->assign('showTagsets', false); } CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, false, true); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => true))); }
/** * Function to build user dashboard * * @return void * @access public */ function buildUserDashBoard() { //build component selectors $dashboardElements = array(); $config = CRM_Core_Config::singleton(); $this->_userOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'user_dashboard_options'); $components = CRM_Core_Component::getEnabledComponents(); $this->assign('contactId', $this->_contactId); foreach ($components as $name => $component) { $elem = $component->getUserDashboardElement(); if (!$elem) { continue; } if (!empty($this->_userOptions[$name]) && (CRM_Core_Permission::access($component->name) || CRM_Core_Permission::check($elem['perm'][0]))) { $userDashboard = $component->getUserDashboardObject(); $dashboardElements[] = array('class' => 'crm-dashboard-' . strtolower($component->name), 'sectionTitle' => $elem['title'], 'templatePath' => $userDashboard->getTemplateFileName(), 'weight' => $elem['weight']); $userDashboard->run(); } } if (!empty($this->_userOptions['Permissioned Orgs'])) { $dashboardElements[] = array('class' => 'crm-dashboard-permissionedOrgs', 'templatePath' => 'CRM/Contact/Page/View/Relationship.tpl', 'sectionTitle' => ts('Your Contacts / Organizations'), 'weight' => 40); $links = self::links(); $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, $links, NULL, TRUE); $this->assign('currentRelationships', $currentRelationships); } if (!empty($this->_userOptions['PCP'])) { $dashboardElements[] = array('class' => 'crm-dashboard-pcp', 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl', 'sectionTitle' => ts('Personal Campaign Pages'), 'weight' => 40); list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP::getPcpDashboardInfo($this->_contactId); $this->assign('pcpBlock', $pcpBlock); $this->assign('pcpInfo', $pcpInfo); } if (!empty($this->_userOptions['Assigned Activities'])) { // Assigned Activities section $dashboardElements[] = array('class' => 'crm-dashboard-assignedActivities', 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl', 'sectionTitle' => ts('Your Assigned Activities'), 'weight' => 5); $userDashboard = new CRM_Activity_Page_UserDashboard(); $userDashboard->run(); } usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('dashboardElements', $dashboardElements); if (!empty($this->_userOptions['Groups'])) { $this->assign('showGroup', TRUE); //build group selector $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact(); $gContact->run(); } else { $this->assign('showGroup', FALSE); } }
/** * Build the form object. */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } $allowedRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactID); CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header')->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js', 2, 'html-header')->addVars('relationshipTypes', CRM_Contact_Form_Relationship::getRelationshipTypeMetadata($allowedRelationshipTypes)); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); //adding case manager.CRM-4510. $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE); $allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); $emailActivityType = array_search('Email', $allActTypes); $pdfActivityType = array_search('Print PDF Letter', $allActTypes); if ($pdfActivityType) { $this->assign('exportDoc', CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$pdfActivityType}")); } // remove Open Case activity type since we're inside an existing case if ($openActTypeId = array_search('Open Case', $allActTypes)) { unset($aTypes[$openActTypeId]); } // Only show "link cases" activity if other cases exist. $linkActTypeId = array_search('Link Cases', $allActTypes); if ($linkActTypeId) { $count = civicrm_api3('Case', 'getcount', array('check_permissions' => TRUE, 'id' => array('!=' => $this->_caseID), 'is_deleted' => 0)); if (!$count) { unset($aTypes[$linkActTypeId]); } } if (!$xmlProcessor->getNaturalActivityTypeSort()) { asort($aTypes); } $activityLinks = array('' => ts('Add Activity')); foreach ($aTypes as $type => $label) { if ($type == $emailActivityType) { $url = CRM_Utils_System::url('civicrm/activity/email/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } elseif ($type == $pdfActivityType) { $url = CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { $url = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } $activityLinks[$url] = $label; } $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu fa-calendar-check-o twenty')); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', '', array('' => ts('Activity Audit')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu fa-list-alt')); $this->add('select', 'timeline_id', '', array('' => ts('Add Timeline')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu fa-list-ol')); } $this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement')); $this->buildMergeCaseForm(); //call activity form self::activityForm($this, $aTypes); //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //save special label because we unset it in the loop $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; foreach ($caseRelationships as $key => &$value) { if (!empty($managerRoleId)) { if ($managerRoleId == $value['relation_type']) { $value['relation'] = $managerLabel; } } //calculate roles that don't have relationships if (!empty($caseRoles[$value['relation_type']])) { unset($caseRoles[$value['relation_type']]); } } $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } $this->assign('clientRelationships', $clientRelationships); // Now global contact list that appears on all cases. $globalGroupInfo = array(); CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalGroupInfo', $globalGroupInfo); // List relationship types for adding an arbitrary new role to the case $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $allowedRelationshipTypes, FALSE, array('class' => 'crm-select2 twenty', 'data-select-params' => '{"allowClear": false}')); $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } CRM_Core_BAO_Tag::getTags('civicrm_case', $allTags, NULL, ' ', TRUE); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { if (isset($allTags[$tid])) { $tags[$tid] = $allTags[$tid]; } else { unset($tags[$tid]); } } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', TRUE); } else { $this->assign('showTags', FALSE); } // build tagset widget // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); $tagSetTags = array(); if ($parentNames) { $this->assign('showTags', TRUE); $tagSetItems = civicrm_api3('entityTag', 'get', array('entity_id' => $this->_caseID, 'entity_table' => 'civicrm_case', 'tag_id.parent_id.is_tagset' => 1, 'options' => array('limit' => 0), 'return' => array("tag_id.parent_id", "tag_id.parent_id.name", "tag_id.name"))); foreach ($tagSetItems['values'] as $tag) { $tagSetTags += array($tag['tag_id.parent_id'] => array('name' => $tag['tag_id.parent_id.name'], 'items' => array())); $tagSetTags[$tag['tag_id.parent_id']]['items'][] = $tag['tag_id.name']; } } $this->assign('tagSetTags', $tagSetTags); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => TRUE))); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); //adding case manager.CRM-4510. $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', true); // remove Open Case activity type since we're inside an existing case $openCaseID = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name'); unset($aTypes[$openCaseID]); asort($aTypes); $this->add('select', 'activity_type_id', ts('New Activity'), array('' => ts('- select activity type -')) + $aTypes); $this->add('select', 'report_id', ts('Run QA Audit / Redact'), array('' => ts('- select activity set -')) + $reports); $this->add('select', 'timeline_id', ts('Add Timeline'), array('' => ts('- select activity set -')) + $reports); $this->addElement('submit', $this->getButtonName('next'), ts('Go'), array('class' => 'form-submit-inline', 'onclick' => "return checkSelection( this );")); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $this->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus); // activity dates $this->addDate('activity_date_low', ts('Activity Dates - From'), false, array('formatType' => 'searchDate')); $this->addDate('activity_date_high', ts('To'), false, array('formatType' => 'searchDate')); require_once "CRM/Core/Permission.php"; if (CRM_Core_Permission::check('administer CiviCRM')) { $this->add('checkbox', 'activity_deleted', ts('Deleted Activities')); } //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //build reporter select $reporters = array("" => ts(' - any reporter - ')); foreach ($caseRelationships as $key => &$value) { $reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )"; if ($managerRoleId == $value['relation_type']) { $value['relation'] = $caseRoles[$managerRoleId]; } //calculate roles that don't have relationships if (CRM_Utils_Array::value($value['relation_type'], $caseRoles)) { unset($caseRoles[$value['relation_type']]); } } // activity type filter for case activity search, need to add Email Sent activity type $emailSentID = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name'); $aTypesFilter = array($emailSentID => 'Email') + $aTypes; asort($aTypesFilter); $this->add('select', 'activity_type_filter_id', ts('Activity Type'), array('' => ts('- select activity type -')) + $aTypesFilter); $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getcontactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); $this->add('select', 'reporter_id', ts('Reporter/Role'), $reporters); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, null, null, false); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } $this->assign('clientRelationships', $clientRelationships); // Now global contact list that appears on all cases. $globalGroupInfo = array(); $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalRelationships', $relGlobal); $this->assign('globalGroupInfo', $globalGroupInfo); // List of relationship types require_once 'CRM/Contact/BAO/Relationship.php'; $baoRel =& new CRM_Contact_BAO_Relationship(); $relType = $baoRel->getRelationType('Individual'); $roleTypes = array(); foreach ($relType as $k => $v) { $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; } $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => true))); }
function civicrm_api3_pcpteams_checkTeamAdmin($params) { $teamRelTypeName = CRM_Pcpteams_Constant::C_TEAM_ADMIN_REL_TYPE; $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $teamRelTypeName, 'id', 'name_a_b'); $reltionships = CRM_Contact_BAO_Relationship::getRelationship($params['user_id'], CRM_Contact_BAO_Relationship::CURRENT); $result['user_id'] = $params['user_id']; $result['is_team_admin'] = 0; $result['team_contact_id'] = $params['team_contact_id']; foreach ($reltionships as $relId => $relValue) { if ($relTypeId == $relValue['relationship_type_id'] && $params['team_contact_id'] == $relValue['contact_id_b'] && $relValue['is_active']) { $result['relationship_id'] = $relValue['id']; $result['is_team_admin'] = 1; } } return $result; }
function printCaseReport() { $caseID = CRM_Utils_Request::retrieve('caseID', 'Positive', CRM_Core_DAO::$_nullObject); $clientID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject); $activitySetName = CRM_Utils_Request::retrieve('asn', 'String', CRM_Core_DAO::$_nullObject); $isRedact = CRM_Utils_Request::retrieve('redact', 'Boolean', CRM_Core_DAO::$_nullObject); $includeActivities = CRM_Utils_Request::retrieve('all', 'Positive', CRM_Core_DAO::$_nullObject); $params = $otherRelationships = $globalGroupInfo = array(); $report = new CRM_Case_XMLProcessor_Report($isRedact); if ($includeActivities) { $params['include_activities'] = 1; } if ($isRedact) { $params['is_redact'] = 1; $report->_redactionStringRules = array(); } $template = CRM_Core_Smarty::singleton(); //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($clientID, $caseID); $caseType = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles'); foreach ($caseRelationships as $key => &$value) { if (!empty($caseRoles[$value['relation_type']])) { unset($caseRoles[$value['relation_type']]); } if ($isRedact) { if (!array_key_exists($value['name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['name'] => 'name_' . rand(10000, 100000))); } $value['name'] = self::redact($value['name'], TRUE, $report->_redactionStringRules); if (!empty($value['email']) && !array_key_exists($value['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['email'] => 'email_' . rand(10000, 100000))); } $value['email'] = self::redact($value['email'], TRUE, $report->_redactionStringRules); if (!empty($value['phone']) && !array_key_exists($value['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['phone'] => 'phone_' . rand(10000, 100000))); } $value['phone'] = self::redact($value['phone'], TRUE, $report->_redactionStringRules); } } $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID); if ($isRedact) { if (!array_key_exists($caseRoles['client']['sort_name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['sort_name'] => 'name_' . rand(10000, 100000))); } if (!array_key_exists($caseRoles['client']['display_name'], $report->_redactionStringRules)) { $report->_redactionStringRules[$caseRoles['client']['display_name']] = $report->_redactionStringRules[$caseRoles['client']['sort_name']]; } $caseRoles['client']['sort_name'] = self::redact($caseRoles['client']['sort_name'], TRUE, $report->_redactionStringRules); if (!empty($caseRoles['client']['email']) && !array_key_exists($caseRoles['client']['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['email'] => 'email_' . rand(10000, 100000))); } $caseRoles['client']['email'] = self::redact($caseRoles['client']['email'], TRUE, $report->_redactionStringRules); if (!empty($caseRoles['client']['phone']) && !array_key_exists($caseRoles['client']['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['phone'] => 'phone_' . rand(10000, 100000))); } $caseRoles['client']['phone'] = self::redact($caseRoles['client']['phone'], TRUE, $report->_redactionStringRules); } // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($clientID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE); foreach ($relClient as $r) { if ($isRedact) { if (!array_key_exists($r['name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['name'] => 'name_' . rand(10000, 100000))); } if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) { $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['name']]; } $r['name'] = self::redact($r['name'], TRUE, $report->_redactionStringRules); if (!empty($r['phone']) && !array_key_exists($r['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000))); } $r['phone'] = self::redact($r['phone'], TRUE, $report->_redactionStringRules); if (!empty($r['email']) && !array_key_exists($r['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000))); } $r['email'] = self::redact($r['email'], TRUE, $report->_redactionStringRules); } if (!array_key_exists($r['id'], $caseRelationships)) { $otherRelationships[] = $r; } } // Now global contact list that appears on all cases. $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); foreach ($relGlobal as &$r) { if ($isRedact) { if (!array_key_exists($r['sort_name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['sort_name'] => 'name_' . rand(10000, 100000))); } if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) { $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['sort_name']]; } $r['sort_name'] = self::redact($r['sort_name'], TRUE, $report->_redactionStringRules); if (!empty($r['phone']) && !array_key_exists($r['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000))); } $r['phone'] = self::redact($r['phone'], TRUE, $report->_redactionStringRules); if (!empty($r['email']) && !array_key_exists($r['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000))); } $r['email'] = self::redact($r['email'], TRUE, $report->_redactionStringRules); } } $template->assign('caseRelationships', $caseRelationships); $template->assign('caseRoles', $caseRoles); $template->assign('otherRelationships', $otherRelationships); $template->assign('globalRelationships', $relGlobal); $template->assign('globalGroupInfo', $globalGroupInfo); $contents = self::getCaseReport($clientID, $caseID, $activitySetName, $params, $report); $printReport = CRM_Case_Audit_Audit::run($contents, $clientID, $caseID, TRUE); echo $printReport; CRM_Utils_System::civiExit(); }
/** * Given the list of params in the params array, fetch the object * and store the values in the values array * * @param array $params input parameters to find object * @param array $values output values of the object * @param array $ids the array that holds all the db ids * * @return array (reference) the values that could be potentially assigned to smarty * @access public * @static */ function &getValues(&$params, &$values, &$ids) { $values['relationship']['data'] =& CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], null, 3); // get the total count of relationships $values['relationship']['totalCount'] = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], null, null, true); return $values; }
/** * Function to get the relationship * * @param object $contact_a A valid Contact object * @param object $contact_b A valid Contact object * @param array $relationship_type_name An array of Relationship_type object(s). * @param array $returnProperties Which properties should be included in the related Contact object(s). If NULL, the default set of contact properties will be included. * @param array $sort Associative array of one or more "property_name"=>"sort direction" pairs which will control order of Contact objects returned * @param int $offset Starting row index. * * @return Array of all relationship. * * @access public * */ function crm_get_relationships($contact_a, $contact_b = null, $relationship_type_name = null, $returnProperties = null, $sort = null, $offset = 0, $row_count = 25) { if (!isset($contact_a->id)) { return _crm_error('$contact_a is not valid contact datatype'); } require_once 'CRM/Contact/BAO/Relationship.php'; $contactID = $contact_a->id; $relationships = CRM_Contact_BAO_Relationship::getRelationship($contactID); $relationships_b = array(); $cid = $contact_b->id; if (isset($contact_b->id)) { foreach ($relationships as $key => $relationship) { if ($relationship['cid'] == $cid) { $relationships_b[$key] = $relationship; } } return $relationships_b; } return $relationships; }
/** * function to get information of emergency conatct id and count */ function _getEmergencyContacts($contactID) { $relationshipTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Emergency Contact', 'id', 'name_a_b'); // get contact relationships $relationships = CRM_Contact_BAO_Relationship::getRelationship($contactID, 0, 0, 0, 0, NULL, NULL, FALSE, array('relationship_type_id' => $relationshipTypeId)); $hideStr = ''; $count = 0; $rid = array(); foreach ($relationships as $relationshipK => $relationshipV) { $hideStr .= "\$('#relationship-{$relationshipK}').show();"; if ($relationshipV['is_active'] == 1) { $count++; } $rid[] = $relationshipK; } $relation['rid'] = $rid; $relation['hideStr'] = $hideStr; $relation['count'] = $count; return $relation; }
/** * Function to get the relationship * * @param array $contact_a (reference ) input parameters. * @param array $contact_b (reference ) input parameters. * @param array $relationshipTypes an array of Relationship Type Name. * @param string $sort sort all relationship by relationshipId (eg asc/desc) * * @return Array of all relationship. * * @access public */ function civicrm_contact_relationship_get($contact_a, $contact_b = NULL, $relationshipTypes = NULL, $sort = NULL) { if (!is_array($contact_a)) { return civicrm_create_error(ts('Input parameter is not an array')); } if (!isset($contact_a['contact_id'])) { return civicrm_create_error(ts('Could not find contact_id in input parameters.')); } require_once 'CRM/Contact/BAO/Relationship.php'; $contactID = $contact_a['contact_id']; $relationships = CRM_Contact_BAO_Relationship::getRelationship($contactID); if (!empty($relationshipTypes)) { $result = array(); foreach ($relationshipTypes as $relationshipName) { foreach ($relationships as $key => $relationship) { if ($relationship['relation'] == $relationshipName) { $result[$key] = $relationship; } } } $relationships = $result; } if (isset($contact_b['contact_id'])) { $cid = $contact_b['contact_id']; $result = array(); foreach ($relationships as $key => $relationship) { if ($relationship['cid'] == $cid) { $result[$key] = $relationship; } } $relationships = $result; } //sort by relationship id if ($sort) { if (strtolower($sort) == 'asc') { ksort($relationships); } elseif (strtolower($sort) == 'desc') { krsort($relationships); } } //handle custom data. require_once 'CRM/Core/BAO/CustomGroup.php'; foreach ($relationships as $relationshipId => $values) { $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Relationship', CRM_Core_DAO::$_nullObject, $relationshipId, FALSE, $values['civicrm_relationship_type_id']); $formatTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject); $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($formatTree, $defaults); if (!empty($defaults)) { foreach ($defaults as $key => $val) { $relationships[$relationshipId][$key] = $val; } } } if ($relationships) { return civicrm_create_success($relationships); } else { return civicrm_create_error(ts('Invalid Data')); } }
/** * Given the component name and returns * the count of participation of contact * * @param string $component input component name * @param integer $contactId input contact id * @param string $tableName optional tableName if component is custom group * * @return total number of count of occurence in database * @access public * @static */ static function getCountComponent($component, $contactId, $tableName = null) { $object = null; switch ($component) { case 'tag': require_once 'CRM/Core/BAO/EntityTag.php'; return CRM_Core_BAO_EntityTag::getContactTags($contactId, true); case 'rel': require_once 'CRM/Contact/BAO/Relationship.php'; return count(CRM_Contact_BAO_Relationship::getRelationship($contactId)); case 'group': require_once 'CRM/Contact/BAO/GroupContact.php'; return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, null, null, true); case 'log': require_once 'CRM/Core/BAO/Log.php'; return CRM_Core_BAO_Log::getContactLogCount($contactId); case 'note': require_once 'CRM/Core/BAO/Note.php'; return CRM_Core_BAO_Note::getContactNoteCount($contactId); case 'contribution': require_once 'CRM/Contribute/BAO/Contribution.php'; return CRM_Contribute_BAO_Contribution::contributionCount($contactId); case 'membership': require_once 'CRM/Member/BAO/Membership.php'; return CRM_Member_BAO_Membership::getContactMembershipCount($contactId); case 'participant': require_once 'CRM/Event/BAO/Participant.php'; return CRM_Event_BAO_Participant::getContactParticipantCount($contactId); case 'pledge': require_once 'CRM/Pledge/BAO/Pledge.php'; return CRM_Pledge_BAO_Pledge::getContactPledgeCount($contactId); case 'case': require_once 'CRM/Case/BAO/Case.php'; return CRM_Case_BAO_Case::caseCount($contactId); case 'grant': require_once 'CRM/Grant/BAO/Grant.php'; return CRM_Grant_BAO_Grant::getContactGrantCount($contactId); case 'activity': require_once 'CRM/Activity/BAO/Activity.php'; return CRM_Activity_BAO_Activity::getActivitiesCount($contactId, false, null, null); default: $custom = explode('_', $component); if ($custom['0'] = 'custom') { require_once 'CRM/Core/DAO/CustomGroup.php'; if (!$tableName) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $custom['1'], 'table_name'); } $queryString = "SELECT count(id) FROM {$tableName} WHERE entity_id = {$contactId}"; return CRM_Core_DAO::singleValueQuery($queryString); } } }
/** * Check the membership extended through relationship. * * @param int $membershipId * Membership id. * @param int $contactId * Contact id. * * @param int $action * * @return array * array of contact_id of all related contacts. */ public static function checkMembershipRelationship($membershipId, $contactId, $action = CRM_Core_Action::ADD) { $contacts = array(); $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $membershipId, 'membership_type_id'); $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID); $relationships = array(); if (isset($membershipType['relationship_type_id'])) { $relationships = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::CURRENT); if ($action & CRM_Core_Action::UPDATE) { $pastRelationships = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::PAST); $relationships = array_merge($relationships, $pastRelationships); } } if (!empty($relationships)) { // check for each contact relationships foreach ($relationships as $values) { //get details of the relationship type $relType = array('id' => $values['civicrm_relationship_type_id']); $relValues = array(); CRM_Contact_BAO_RelationshipType::retrieve($relType, $relValues); // Check if contact's relationship type exists in membership type $relTypeDirs = array(); $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']); $relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']); $bidirectional = FALSE; foreach ($relTypeIds as $key => $value) { $relTypeDirs[] = $value . '_' . $relDirections[$key]; if (in_array($value, $relType) && $relValues['name_a_b'] == $relValues['name_b_a']) { $bidirectional = TRUE; break; } } $relTypeDir = $values['civicrm_relationship_type_id'] . '_' . $values['rtype']; if ($bidirectional || in_array($relTypeDir, $relTypeDirs)) { // $values['status'] is going to have value for // current or past relationships. $contacts[$values['cid']] = $values['status']; } } } // Sort by contact_id ascending ksort($contacts); return $contacts; }
/** * Function to get the relationship * * @param array $params input parameters. * @todo Result is inconsistent depending on whether contact_id is passed in : * - if you pass in contact_id - it just returns all relationships for 'contact_id' * - if you don't pass in contact_id then it does a filter on the relationship table (DAO based search) * * @return Array API Result Array * {@getfields relationship_get} * @example RelationshipGet.php * @access public */ function civicrm_api3_relationship_get($params) { $options = _civicrm_api3_get_options_from_params($params); if (empty($params['contact_id'])) { if (!empty($params['membership_type_id']) && empty($params['relationship_type_id'])) { CRM_Contact_BAO_Relationship::membershipTypeToRelationshipTypes($params); } $relationships = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE); } else { $relationships = array(); $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], CRM_Utils_Array::value('status_id', $params), 0, CRM_Utils_Array::value('is_count', $options), CRM_Utils_Array::value('id', $params), NULL, NULL, FALSE, $params); } //perhaps we should add a 'getcount' but at this stage lets just handle getcount output if ($options['is_count']) { return array('count' => $relationships); } foreach ($relationships as $relationshipId => $values) { _civicrm_api3_custom_data_get($relationships[$relationshipId], 'Relationship', $relationshipId, NULL, CRM_Utils_Array::value('relationship_type_id', $values)); } return civicrm_api3_create_success($relationships, $params); }