Commit | Line | Data |
---|---|---|
adc7f09e DL |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
adc7f09e | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
adc7f09e DL |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
adc7f09e DL |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class is for activity assignment functions | |
38 | * | |
39 | */ | |
40 | class CRM_Activity_BAO_ActivityContact extends CRM_Activity_DAO_ActivityContact { | |
41 | ||
42 | /** | |
43 | * class constructor | |
44 | */ | |
45 | function __construct() { | |
46 | parent::__construct(); | |
47 | } | |
48 | ||
49 | /** | |
50 | * funtion to add activity contact | |
51 | * | |
52 | * @param array $params the values for this table: activity id, contact id, record type | |
53 | * | |
54 | * @return object activity_contact object | |
55 | * @access public | |
56 | * | |
57 | */ | |
58 | public static function create(&$params) { | |
59 | $activityContact = new CRM_Activity_DAO_ActivityContact(); | |
60 | ||
61 | $activityContact->copyValues($params); | |
2517d079 DL |
62 | if (!$activityContact->find(TRUE)) { |
63 | return $activityContact->save(); | |
64 | } | |
65 | return $activityContact; | |
adc7f09e | 66 | } |
f04255e4 DL |
67 | |
68 | /** | |
69 | * function to retrieve names of contact by activity_id | |
70 | * | |
6c8f6e67 EM |
71 | * @param $activityID |
72 | * @param $recordTypeID | |
73 | * @param bool $alsoIDs | |
74 | * | |
75 | * @internal param int $id ID of the activity | |
76 | * @internal param string $type type of interaction | |
f04255e4 DL |
77 | * |
78 | * @return array | |
79 | * | |
80 | * @access public | |
f04255e4 | 81 | */ |
a24b3694 | 82 | static function getNames($activityID, $recordTypeID, $alsoIDs = FALSE) { |
f04255e4 DL |
83 | $names = array(); |
84 | $ids = array(); | |
85 | ||
86 | if (empty($activityID)) { | |
87 | return $alsoIDs ? array($names, $ids) : $names; | |
88 | } | |
89 | ||
90 | $query = " | |
91 | SELECT contact_a.id, contact_a.sort_name | |
92 | FROM civicrm_contact contact_a | |
93 | INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id | |
94 | WHERE civicrm_activity_contact.activity_id = %1 | |
a24b3694 | 95 | AND civicrm_activity_contact.record_type_id = %2 |
f04255e4 DL |
96 | AND contact_a.is_deleted = 0 |
97 | "; | |
98 | $params = array( | |
99 | 1 => array($activityID, 'Integer'), | |
a24b3694 | 100 | 2 => array($recordTypeID, 'Integer') |
f04255e4 DL |
101 | ); |
102 | ||
103 | $dao = CRM_Core_DAO::executeQuery($query, $params); | |
104 | while ($dao->fetch()) { | |
105 | $names[$dao->id] = $dao->sort_name; | |
106 | $ids[] = $dao->id; | |
107 | } | |
108 | ||
109 | return $alsoIDs ? array($names, $ids) : $names; | |
110 | } | |
111 | ||
034500d4 | 112 | /** |
2517d079 | 113 | * function to retrieve id of target contact by activity_id |
034500d4 | 114 | * |
77b97be7 EM |
115 | * @param $activityID |
116 | * @param $recordTypeID | |
117 | * | |
118 | * @internal param int $id ID of the activity | |
034500d4 | 119 | * |
120 | * @return mixed | |
121 | * | |
122 | * @access public | |
034500d4 | 123 | */ |
124 | static function retrieveContactIdsByActivityId($activityID, $recordTypeID) { | |
125 | $activityContact = array(); | |
126 | if (!CRM_Utils_Rule::positiveInteger($activityID) || | |
127 | !CRM_Utils_Rule::positiveInteger($recordTypeID)) { | |
128 | return $activityContact; | |
129 | } | |
130 | ||
131 | $sql = " SELECT contact_id | |
132 | FROM civicrm_activity_contact | |
133 | INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id | |
134 | WHERE activity_id = %1 | |
2517d079 DL |
135 | AND record_type_id = %2 |
136 | AND civicrm_contact.is_deleted = 0 | |
034500d4 | 137 | "; |
138 | $params = array( | |
139 | 1 => array($activityID, 'Integer'), | |
140 | 2 => array($recordTypeID, 'Integer') | |
141 | ); | |
142 | ||
143 | $dao = CRM_Core_DAO::executeQuery($sql, $params); | |
144 | while ($dao->fetch()) { | |
145 | $activityContact[] = $dao->contact_id; | |
146 | } | |
147 | return $activityContact; | |
148 | } | |
149 | ||
ffd93213 EM |
150 | /** |
151 | * Get the links associate array as defined by the links.ini file. | |
152 | * | |
153 | * | |
154 | * Experimental... - | |
155 | * Should look a bit like | |
156 | * [local_col_name] => "related_tablename:related_col_name" | |
157 | * | |
158 | * | |
159 | * @return array|null | |
160 | * array = if there are links defined for this table. | |
161 | * empty array - if there is a links.ini file, but no links on this table | |
162 | * null - if no links.ini exists for this database (hence try auto_links). | |
163 | * @access public | |
164 | * @see DB_DataObject::getLinks(), DB_DataObject::getLink() | |
165 | */ | |
166 | /** | |
167 | * @return array|null | |
168 | */ | |
6e1bb60c N |
169 | function links() { |
170 | $link = array('activity_id' => 'civicrm_activity:id'); | |
171 | return $link; | |
172 | } | |
adc7f09e | 173 | } |