clean up(CRM-12274)
[civicrm-core.git] / CRM / Activity / BAO / ActivityContact.php
CommitLineData
adc7f09e
DL
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36/**
37 * This class is for activity assignment functions
38 *
39 */
40class CRM_Activity_BAO_ActivityContact extends CRM_Activity_DAO_ActivityContact {
41
42 /**
43 * class constructor
44 */
45 function __construct() {
46 parent::__construct();
47 }
48
49 /**
50 * funtion to add activity contact
51 *
52 * @param array $params the values for this table: activity id, contact id, record type
53 *
54 * @return object activity_contact object
55 * @access public
56 *
57 */
58 public static function create(&$params) {
59 $activityContact = new CRM_Activity_DAO_ActivityContact();
60
61 $activityContact->copyValues($params);
62 return $activityContact->save();
63 }
f04255e4
DL
64
65 /**
66 * function to retrieve names of contact by activity_id
67 *
68 * @param int $id ID of the activity
69 * @param string $type type of interaction
70 *
71 * @return array
72 *
73 * @access public
74 *
75 */
a24b3694 76 static function getNames($activityID, $recordTypeID, $alsoIDs = FALSE) {
f04255e4
DL
77 $names = array();
78 $ids = array();
79
80 if (empty($activityID)) {
81 return $alsoIDs ? array($names, $ids) : $names;
82 }
83
84 $query = "
85SELECT contact_a.id, contact_a.sort_name
86FROM civicrm_contact contact_a
87INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id
88WHERE civicrm_activity_contact.activity_id = %1
a24b3694 89AND civicrm_activity_contact.record_type_id = %2
f04255e4
DL
90AND contact_a.is_deleted = 0
91";
92 $params = array(
93 1 => array($activityID, 'Integer'),
a24b3694 94 2 => array($recordTypeID, 'Integer')
f04255e4
DL
95 );
96
97 $dao = CRM_Core_DAO::executeQuery($query, $params);
98 while ($dao->fetch()) {
99 $names[$dao->id] = $dao->sort_name;
100 $ids[] = $dao->id;
101 }
102
103 return $alsoIDs ? array($names, $ids) : $names;
104 }
105
034500d4 106 /**
107 * function to retrieve id of target contact by activity_id
108 *
109 * @param int $id ID of the activity
110 *
111 * @return mixed
112 *
113 * @access public
114 *
115 */
116 static function retrieveContactIdsByActivityId($activityID, $recordTypeID) {
117 $activityContact = array();
118 if (!CRM_Utils_Rule::positiveInteger($activityID) ||
119 !CRM_Utils_Rule::positiveInteger($recordTypeID)) {
120 return $activityContact;
121 }
122
123 $sql = " SELECT contact_id
124FROM civicrm_activity_contact
125INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id
126WHERE activity_id = %1
127AND record_type_id = %2
128AND civicrm_contact.is_deleted = 0
129";
130 $params = array(
131 1 => array($activityID, 'Integer'),
132 2 => array($recordTypeID, 'Integer')
133 );
134
135 $dao = CRM_Core_DAO::executeQuery($sql, $params);
136 while ($dao->fetch()) {
137 $activityContact[] = $dao->contact_id;
138 }
139 return $activityContact;
140 }
141
adc7f09e 142}