Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class is for activity assignment functions | |
38 | * | |
39 | */ | |
40 | class CRM_Activity_BAO_ActivityAssignment extends CRM_Activity_DAO_ActivityAssignment { | |
41 | ||
42 | /** | |
43 | * class constructor | |
44 | */ | |
45 | function __construct() { | |
46 | parent::__construct(); | |
47 | } | |
48 | ||
49 | /** | |
50 | * Add activity assignment. | |
51 | * | |
52 | * @param array $params (reference ) an assoc array of name/value pairs | |
53 | * @param array $ids (reference ) the array that holds all the db ids | |
54 | * | |
55 | * @return object activity type of object that is added | |
56 | * @access public | |
57 | * | |
58 | */ | |
59 | public static function create(&$params) { | |
60 | $assignment = new CRM_Activity_BAO_ActivityAssignment(); | |
61 | ||
62 | $assignment->copyValues($params); | |
63 | return $assignment->save(); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Retrieve assignee_id by activity_id | |
68 | * | |
69 | * @param int $id ID of the activity | |
70 | * | |
71 | * @return void | |
72 | * | |
73 | * @access public | |
74 | * | |
75 | */ | |
76 | static function retrieveAssigneeIdsByActivityId($activity_id) { | |
77 | $assigneeArray = array(); | |
78 | if (!CRM_Utils_Rule::positiveInteger($activity_id)) { | |
79 | return $assigneeArray; | |
80 | } | |
81 | ||
82 | $sql = ' | |
83 | SELECT assignee_contact_id | |
84 | FROM civicrm_activity_assignment | |
85 | JOIN civicrm_contact ON assignee_contact_id = civicrm_contact.id | |
86 | WHERE activity_id = %1 AND civicrm_contact.is_deleted = 0 | |
87 | '; | |
88 | $assignment = CRM_Core_DAO::executeQuery($sql, array(1 => array($activity_id, 'Integer'))); | |
89 | while ($assignment->fetch()) { | |
90 | $assigneeArray[] = $assignment->assignee_contact_id; | |
91 | } | |
92 | ||
93 | return $assigneeArray; | |
94 | } | |
95 | ||
96 | /** | |
97 | * Retrieve assignee names by activity_id | |
98 | * | |
99 | * @param int $id ID of the activity | |
100 | * @param boolean $isDisplayName if set returns display names of assignees | |
101 | * @param boolean $skipDetails if false returns all details of assignee contact. | |
102 | * | |
103 | * @return array | |
104 | * | |
105 | * @access public | |
106 | * | |
107 | */ | |
108 | static function getAssigneeNames($activityID, $isDisplayName = FALSE, $skipDetails = TRUE) { | |
109 | $assigneeNames = array(); | |
110 | if (empty($activityID)) { | |
111 | return $assigneeNames; | |
112 | } | |
113 | ||
114 | $whereClause = ""; | |
115 | if (!$skipDetails) { | |
116 | $whereClause = " AND ce.is_primary= 1"; | |
117 | } | |
118 | ||
119 | $query = "SELECT contact_a.id, contact_a.sort_name, contact_a.display_name, ce.email | |
120 | FROM civicrm_contact contact_a | |
121 | LEFT JOIN civicrm_activity_assignment | |
122 | ON civicrm_activity_assignment.assignee_contact_id = contact_a.id | |
123 | LEFT JOIN civicrm_email ce | |
124 | ON ce.contact_id = contact_a.id | |
125 | WHERE civicrm_activity_assignment.activity_id = %1 | |
126 | AND contact_a.is_deleted = 0 | |
127 | {$whereClause}"; | |
128 | ||
129 | $queryParam = array(1 => array($activityID, 'Integer')); | |
130 | $dao = CRM_Core_DAO::executeQuery($query, $queryParam); | |
131 | while ($dao->fetch()) { | |
132 | if (!$isDisplayName) { | |
133 | $assigneeNames[$dao->id] = $dao->sort_name; | |
134 | } | |
135 | else { | |
136 | if ($skipDetails) { | |
137 | $assigneeNames[$dao->id] = $dao->display_name; | |
138 | } | |
139 | else { | |
140 | $assigneeNames[$dao->id]['contact_id'] = $dao->id; | |
141 | $assigneeNames[$dao->id]['display_name'] = $dao->display_name; | |
142 | $assigneeNames[$dao->id]['sort_name'] = $dao->sort_name; | |
143 | $assigneeNames[$dao->id]['email'] = $dao->email; | |
144 | $assigneeNames[$dao->id]['role'] = ts('Activity Assignee'); | |
145 | } | |
146 | } | |
147 | } | |
148 | return $assigneeNames; | |
149 | } | |
150 | } | |
151 |