3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
35 * This class is for activity assignment functions.
37 class CRM_Activity_BAO_ActivityTarget
extends CRM_Activity_DAO_ActivityContact
{
42 public function __construct() {
43 parent
::__construct();
47 * Add activity target.
49 * @param array $params
52 * activity type of object that is added
54 public static function create(&$params) {
55 $target = new CRM_Activity_BAO_ActivityContact();
56 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
57 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
59 $target->copyValues($params);
60 $target->record_type_id
= $targetID;
61 return $target->save();
65 * Retrieve id of target contact by activity_id.
67 * @param int $activity_id
71 public static function retrieveTargetIdsByActivityId($activity_id) {
72 $targetArray = array();
73 if (!CRM_Utils_Rule
::positiveInteger($activity_id)) {
77 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
78 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
82 FROM civicrm_activity_contact
83 INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id
84 WHERE activity_id = %1
85 AND record_type_id = $targetID
86 AND civicrm_contact.is_deleted = 0
88 $target = CRM_Core_DAO
::executeQuery($sql, array(1 => array($activity_id, 'Integer')));
89 while ($target->fetch()) {
90 $targetArray[] = $target->contact_id
;
96 * Retrieve names of target contact by activity_id.
98 * @param int $activityID
102 public static function getTargetNames($activityID) {
103 $targetNames = array();
105 if (empty($activityID)) {
108 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
109 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
112 SELECT contact_a.id, contact_a.sort_name
113 FROM civicrm_contact contact_a
114 INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id
115 WHERE civicrm_activity_contact.activity_id = %1
116 AND civicrm_activity_contact.record_type_id = $targetID
117 AND contact_a.is_deleted = 0
119 $queryParam = array(1 => array($activityID, 'Integer'));
121 $dao = CRM_Core_DAO
::executeQuery($query, $queryParam);
122 while ($dao->fetch()) {
123 $targetNames[$dao->id
] = $dao->sort_name
;