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 $activityContact = new CRM_Activity_DAO_ActivityContact();
42 $activityContact->copyValues($params);
43 if (!$activityContact->find(TRUE)) {
44 return $activityContact->save();
46 return $activityContact;
50 * Retrieve names of contact by activity_id.
52 * @param int $activityID
53 * @param int $recordTypeID
54 * @param bool $alsoIDs
58 public static function getNames($activityID, $recordTypeID, $alsoIDs = FALSE) {
62 if (empty($activityID)) {
63 return $alsoIDs ?
[$names, $ids] : $names;
67 SELECT contact_a.id, contact_a.sort_name
68 FROM civicrm_contact contact_a
69 INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id
70 WHERE civicrm_activity_contact.activity_id = %1
71 AND civicrm_activity_contact.record_type_id = %2
72 AND contact_a.is_deleted = 0
75 1 => [$activityID, 'Integer'],
76 2 => [$recordTypeID, 'Integer'],
79 $dao = CRM_Core_DAO
::executeQuery($query, $params);
80 while ($dao->fetch()) {
81 $names[$dao->id
] = $dao->sort_name
;
85 return $alsoIDs ?
[$names, $ids] : $names;
89 * Retrieve id of target contact by activity_id.
91 * @param int $activityID
92 * @param int $recordTypeID
96 public static function retrieveContactIdsByActivityId($activityID, $recordTypeID) {
97 $activityContact = [];
98 if (!CRM_Utils_Rule
::positiveInteger($activityID) ||
99 !CRM_Utils_Rule
::positiveInteger($recordTypeID)
101 return $activityContact;
104 $sql = " SELECT contact_id
105 FROM civicrm_activity_contact
106 INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id
107 WHERE activity_id = %1
108 AND record_type_id = %2
109 AND civicrm_contact.is_deleted = 0
112 1 => [$activityID, 'Integer'],
113 2 => [$recordTypeID, 'Integer'],
116 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
117 while ($dao->fetch()) {
118 $activityContact[] = $dao->contact_id
;
120 return $activityContact;
124 * Get the links associate array as defined by the links.ini file.
127 * Should look a bit like
128 * [local_col_name] => "related_tablename:related_col_name"
130 * @see DB_DataObject::getLinks()
131 * @see DB_DataObject::getLink()
134 * array if there are links defined for this table.
135 * empty array - if there is a links.ini file, but no links on this table
136 * null - if no links.ini exists for this database (hence try auto_links).
138 public function links() {
139 $link = ['activity_id' => 'civicrm_activity:id'];