private function wf_crm_webform_preprocess::findExistingActivities in Webform CiviCRM Integration 7.4
Same name and namespace in other branches
- 7.5 includes/wf_crm_webform_preprocess.inc \wf_crm_webform_preprocess::findExistingActivities()
Find activity ids based on url input or "existing activity" settings
1 call to wf_crm_webform_preprocess::findExistingActivities()
- wf_crm_webform_preprocess::alterForm in includes/
wf_crm_webform_preprocess.inc - Alter front-end of webforms: Called by hook_form_alter() when rendering a civicrm-enabled webform Add custom prefix. Display messages. Block users who should not have access. Set webform default values.
File
- includes/
wf_crm_webform_preprocess.inc, line 691
Class
Code
private function findExistingActivities() {
// Support legacy url param
if (empty($_GET["activity1"]) && !empty($_GET["aid"])) {
$_GET["activity1"] = $_GET["aid"];
}
for ($n = 1; $n <= $this->data['activity']['number_of_activity']; ++$n) {
if (!empty($this->data['activity'][$n]['activity'][1]['target_contact_id'])) {
$targets = array();
foreach ($this->data['activity'][$n]['activity'][1]['target_contact_id'] as $c) {
if (!empty($this->ent['contact'][$c]['id'])) {
$targets[] = $this->ent['contact'][$c]['id'];
}
}
if ($targets) {
if (isset($_GET["activity{$n}"]) && wf_crm_is_positive($_GET["activity{$n}"])) {
$id = $_GET["activity{$n}"];
$item = wf_civicrm_api('activity', 'getsingle', array(
'id' => $id,
'return' => array(
'target_contact_id',
),
));
if (array_intersect($targets, $item['target_contact_id'])) {
$this->ent['activity'][$n] = array(
'id' => $id,
);
}
}
elseif (!empty($this->data['activity'][$n]['existing_activity_status'])) {
// If the activity type hasn't been set, bail.
if (empty($this->data['activity'][$n]['activity'][1]['activity_type_id'])) {
watchdog('webform_civicrm', "Activity type to update hasn't been set, so won't try to update activity. location = %1, webform activity number : %2", array(
'%1' => request_uri(),
'%2' => $n,
), WATCHDOG_ERROR);
continue;
}
// The api doesn't accept an array of target contacts so we'll do it as a loop
// If targets has more than one entry, the below could result in the wrong activity getting updated.
foreach ($targets as $cid) {
$params = array(
'sequential' => 1,
'target_contact_id' => $cid,
'status_id' => array(
'IN' => (array) $this->data['activity'][$n]['existing_activity_status'],
),
'is_deleted' => '0',
'is_current_revision' => '1',
'options' => array(
'limit' => 1,
),
);
$params['activity_type_id'] = $this->data['activity'][$n]['activity'][1]['activity_type_id'];
$items = wf_crm_apivalues('activity', 'get', $params);
if (isset($items[0]['id'])) {
$this->ent['activity'][$n] = array(
'id' => $items[0]['id'],
);
break;
}
}
}
}
}
}
}