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