4 * Get details for the target and assignee contact of an activity.
6 * This is "simple" in that it is only appropriate for activities in which the business-process
7 * guarantees that there is only one target and one assignee. If the business-process permits
8 * multiple targets or multiple assignees, then consider the more versatile (but less sugary)
11 * Note: This will perform like a dog, but who cares -- at most, we deal with O(100) iterations
12 * as part of a background task.
14 * @param $params, array with keys:
15 * - activity_id: int, required
16 * - target_var: string, optional; name of a variable which will store the first/only target contact; default "target"
17 * - assignee_var: string, optional; name of a variable which will store the first/only assignee contact; default "assignee"
18 * - return: string, optional; comma-separated list of fields to return for each contact
22 function smarty_function_simpleActivityContacts($params, &$smarty) {
23 if (empty($params['activity_id'])) {
24 $smarty->trigger_error('assign: missing \'activity_id\' parameter');
26 if (!isset($params['target_var'])) {
27 $params['target_var'] = 'target';
29 if (!isset($params['assignee_var'])) {
30 $params['assignee_var'] = 'assignee';
32 if (!isset($params['return'])) {
33 $params['return'] = 'contact_id,contact_type,display_name,sort_name,first_name,last_name';
36 require_once 'api/api.php';
37 require_once 'api/v3/utils.php';
38 $activity = civicrm_api('activity', 'getsingle', array(
40 'id' => $params['activity_id'],
41 'return.target_contact_id' => 1,
42 'return.assignee_contact_id' => 1,
45 $baseContactParams = array('version' => 3);
46 foreach (explode(',', $params['return']) as $field) {
47 $baseContactParams['return.' . $field] = 1;
51 'target', 'assignee') as $role) {
53 if (!empty($activity[$role . '_contact_id'])) {
54 $contact_id = array_shift($activity[$role . '_contact_id']);
55 $contact = civicrm_api('contact', 'getsingle', $baseContactParams +
array(
56 'contact_id' => $contact_id,
59 $smarty->assign($params[$role . '_var'], $contact);