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