3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class is for activity assignment functions.
21 class CRM_Activity_BAO_ActivityContact
extends CRM_Activity_DAO_ActivityContact
{
26 public function __construct() {
27 parent
::__construct();
31 * Function to add activity contact.
33 * @param array $params
34 * The values for this table: activity id, contact id, record type.
37 * activity_contact object
39 public static function create($params) {
40 $errorScope = CRM_Core_TemporaryErrorScope
::useException();
41 $activityContact = new CRM_Activity_DAO_ActivityContact();
42 $activityContact->copyValues($params);
44 return $activityContact->save();
46 catch (PEAR_Exception
$e) {
47 // This check used to be done first, creating an extra query before each insert.
48 // However, in none of the core tests was this ever called with values that already
49 // existed, meaning that this line would never or almost never be hit.
50 // hence it's better to save the select query here.
51 if ($activityContact->find(TRUE)) {
52 return $activityContact;
59 * Retrieve names of contact by activity_id.
61 * @param int $activityID
62 * @param int $recordTypeID
63 * @param bool $alsoIDs
67 public static function getNames($activityID, $recordTypeID, $alsoIDs = FALSE) {
71 if (empty($activityID)) {
72 return $alsoIDs ?
[$names, $ids] : $names;
76 SELECT contact_a.id, contact_a.sort_name
77 FROM civicrm_contact contact_a
78 INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id
79 WHERE civicrm_activity_contact.activity_id = %1
80 AND civicrm_activity_contact.record_type_id = %2
81 AND contact_a.is_deleted = 0
84 1 => [$activityID, 'Integer'],
85 2 => [$recordTypeID, 'Integer'],
88 $dao = CRM_Core_DAO
::executeQuery($query, $params);
89 while ($dao->fetch()) {
90 $names[$dao->id
] = $dao->sort_name
;
94 return $alsoIDs ?
[$names, $ids] : $names;
98 * Retrieve id of target contact by activity_id.
100 * @param int $activityID
101 * @param int $recordTypeID
105 public static function retrieveContactIdsByActivityId($activityID, $recordTypeID) {
106 $activityContact = [];
107 if (!CRM_Utils_Rule
::positiveInteger($activityID) ||
108 !CRM_Utils_Rule
::positiveInteger($recordTypeID)
110 return $activityContact;
113 $sql = " SELECT contact_id
114 FROM civicrm_activity_contact
115 INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id
116 WHERE activity_id = %1
117 AND record_type_id = %2
118 AND civicrm_contact.is_deleted = 0
121 1 => [$activityID, 'Integer'],
122 2 => [$recordTypeID, 'Integer'],
125 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
126 while ($dao->fetch()) {
127 $activityContact[] = $dao->contact_id
;
129 return $activityContact;
133 * Get the links associate array as defined by the links.ini file.
136 * Should look a bit like
137 * [local_col_name] => "related_tablename:related_col_name"
139 * @see DB_DataObject::getLinks()
140 * @see DB_DataObject::getLink()
143 * array if there are links defined for this table.
144 * empty array - if there is a links.ini file, but no links on this table
145 * null - if no links.ini exists for this database (hence try auto_links).
147 public function links() {
148 $link = ['activity_id' => 'civicrm_activity:id'];