Skip to content

Commit

Permalink
Merge pull request #46 from jackaponte/1.x-5.0.0
Browse files Browse the repository at this point in the history
Revert "Revert "#43: Update to match Drupal 7.x-5.0""
  • Loading branch information
jackaponte authored Jan 31, 2020
2 parents ecc5957 + 07bff3a commit 78498a2
Show file tree
Hide file tree
Showing 12 changed files with 573 additions and 528 deletions.
59 changes: 30 additions & 29 deletions includes/contact_component.inc
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function _webform_edit_civicrm_contact($component) {
'#parents' => array('extra', 'default_custom_ref'),
);
}

$case_count = isset($data['case']['number_of_case']) ? $data['case']['number_of_case'] : 0;
if ($case_count > 0) {
$form['defaults']['default']['#options']['case_roles'] = t('Case roles');
Expand Down Expand Up @@ -347,7 +347,7 @@ function _webform_edit_civicrm_contact($component) {
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Tags'),
'#options' => array('' => '- ' . t('None') . ' -') + CRM_Core_BAO_Tag::getTags("civicrm_contact", $tags, NULL, '- '),
'#options' => array('' => '- ' . t('None') . ' -') + wf_crm_get_tags('contact'),
'#default_value' => $component['extra']['filters']['tag'],
'#description' => t('Listed contacts must be have at least one of the selected tags (leave blank to not filter by tag).'),
);
Expand Down Expand Up @@ -887,55 +887,56 @@ function wf_crm_update_existing_component(&$component, $enabled, $data) {
* @return array
*/
function wf_crm_find_relations($cid, $types = array(), $current = TRUE) {
$found = $allowed = array();
$found = $allowed = $type_ids = [];
$cid = (int) $cid;
static $employer_type = 0;
if ($cid) {
if (!$employer_type && $current) {
$employer_type = wf_crm_aval(wf_civicrm_api('relationshipType', 'get', array('name_a_b' => 'Employee of', 'return' => 'id')), 'id');
}
$type_ids = '';
foreach ($types as $t) {
list($type, $a_b) = explode('_', $t);
list($type, $a) = explode('_', $t);
// Put current employer first in the list
if ($type == $employer_type && $current) {
$sql = "SELECT id, employer_id
FROM civicrm_contact
WHERE id = $cid OR employer_id = $cid";
$dao = CRM_Core_DAO::executeQuery($sql);
$employer = $dao->id == $cid ? $dao->employer_id : $dao->id;
while ($dao->fetch()) {
$found[$employer] = $employer;
$search_key = $a == 'b' ? 'id' : 'employer_id';
// Note: inconsistency in api3 - search key is "employer_id" but return key is "current_employer_id"
$employer = wf_crm_apivalues('contact', 'get', [
$search_key => $cid,
'sequential' => 1,
], $a == 'b' ? 'current_employer_id' : 'id');
if ($employer) {
$found[$employer[0]] = $employer[0];
}
$dao->free();
}
$type_ids .= ($type_ids ? ',' : '') . $type;
if ($a_b == 'a' || $a_b == 'r') {
$type_ids[] = $type;
if ($a == 'a' || $a == 'r') {
$allowed[] = $type . '_a';
}
if ($a_b == 'b' || $a_b == 'r') {
if ($a == 'b' || $a == 'r') {
$allowed[] = $type . '_b';
}
}
$typeClause = '';
$params = [
'return' => ['contact_id_a', 'contact_id_b', 'relationship_type_id', 'end_date'],
'contact_id_a' => $cid,
'contact_id_b' => $cid,
'options' => ['or' => [['contact_id_a', 'contact_id_b']]],
];
if ($type_ids) {
$typeClause = "AND relationship_type_id IN ($type_ids)";
$params['relationship_type_id'] = ['IN' => $type_ids];
}
$sql = "SELECT relationship_type_id, contact_id_a, contact_id_b
FROM civicrm_relationship
WHERE (contact_id_a = $cid OR contact_id_b = $cid) $typeClause";
if ($current) {
$sql .= " AND is_active = 1 AND (end_date > CURDATE() OR end_date IS NULL)";
$params['is_active'] = 1;
}
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
$a_b = $dao->contact_id_a == $cid ? 'b' : 'a';
if (!$allowed || in_array($dao->relationship_type_id . '_' . $a_b, $allowed)) {
$c = $dao->{"contact_id_$a_b"};
$found[$c] = $c;
foreach (wf_crm_apivalues('relationship', 'get', $params) as $relationship) {
$a = $relationship['contact_id_a'] == $cid ? 'b' : 'a';
if (!$current || empty($relationship['end_date']) || strtotime($relationship['end_date']) > time()) {
if (!$allowed || in_array($relationship['relationship_type_id'] . '_' . $a, $allowed)) {
$c = $relationship["contact_id_$a"];
$found[$c] = $c;
}
}
}
$dao->free();
}
return $found;
}
Expand Down
Loading

0 comments on commit 78498a2

Please sign in to comment.