3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * This class is for activity assignment functions
40 class CRM_Activity_BAO_ActivityContact
extends CRM_Activity_DAO_ActivityContact
{
45 public function __construct() {
46 parent
::__construct();
50 * Function to add activity contact.
52 * @param array $params
53 * The values for this table: activity id, contact id, record type.
56 * activity_contact object
58 public static function create(&$params) {
59 $activityContact = new CRM_Activity_DAO_ActivityContact();
61 $activityContact->copyValues($params);
62 if (!$activityContact->find(TRUE)) {
63 return $activityContact->save();
65 return $activityContact;
69 * Retrieve names of contact by activity_id.
71 * @param int $activityID
72 * @param int $recordTypeID
73 * @param bool $alsoIDs
77 public static function getNames($activityID, $recordTypeID, $alsoIDs = FALSE) {
81 if (empty($activityID)) {
82 return $alsoIDs ?
array($names, $ids) : $names;
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
90 AND civicrm_activity_contact.record_type_id = %2
91 AND contact_a.is_deleted = 0
94 1 => array($activityID, 'Integer'),
95 2 => array($recordTypeID, 'Integer'),
98 $dao = CRM_Core_DAO
::executeQuery($query, $params);
99 while ($dao->fetch()) {
100 $names[$dao->id
] = $dao->sort_name
;
104 return $alsoIDs ?
array($names, $ids) : $names;
108 * Retrieve id of target contact by activity_id.
110 * @param int $activityID
111 * @param int $recordTypeID
115 public static function retrieveContactIdsByActivityId($activityID, $recordTypeID) {
116 $activityContact = array();
117 if (!CRM_Utils_Rule
::positiveInteger($activityID) ||
118 !CRM_Utils_Rule
::positiveInteger($recordTypeID)
120 return $activityContact;
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
127 AND record_type_id = %2
128 AND civicrm_contact.is_deleted = 0
131 1 => array($activityID, 'Integer'),
132 2 => array($recordTypeID, 'Integer'),
135 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
136 while ($dao->fetch()) {
137 $activityContact[] = $dao->contact_id
;
139 return $activityContact;
143 * Get the links associate array as defined by the links.ini file.
146 * Should look a bit like
147 * [local_col_name] => "related_tablename:related_col_name"
151 * array = if there are links defined for this table.
152 * empty array - if there is a links.ini file, but no links on this table
153 * null - if no links.ini exists for this database (hence try auto_links).
154 * @see DB_DataObject::getLinks(), DB_DataObject::getLink()
159 public function links() {
160 $link = array('activity_id' => 'civicrm_activity:id');