Merge pull request #227 from deepak-srivastava/crm
[civicrm-core.git] / api / v2 / ActivityContact.php
CommitLineData
6a488035
TO
1<?php
2// $Id: ActivityContact.php 45502 2013-02-08 13:32:55Z kurund $
3
4
5/*
6 +--------------------------------------------------------------------+
7 | CiviCRM version 4.3 |
8 +--------------------------------------------------------------------+
9 | Copyright CiviCRM LLC (c) 2004-2013 |
10 +--------------------------------------------------------------------+
11 | This file is a part of CiviCRM. |
12 | |
13 | CiviCRM is free software; you can copy, modify, and distribute it |
14 | under the terms of the GNU Affero General Public License |
15 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | |
17 | CiviCRM is distributed in the hope that it will be useful, but |
18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
20 | See the GNU Affero General Public License for more details. |
21 | |
22 | You should have received a copy of the GNU Affero General Public |
23 | License and the CiviCRM Licensing Exception along |
24 | with this program; if not, contact CiviCRM LLC |
25 | at info[AT]civicrm[DOT]org. If you have questions about the |
26 | GNU Affero General Public License or the licensing of CiviCRM, |
27 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
28 +--------------------------------------------------------------------+
29*/
30
31/**
32 * File for the CiviCRM APIv2 activity contact functions
33 *
34 * @package CiviCRM_APIv2
35 * @subpackage API_Activity
36 *
37 * @copyright CiviCRM LLC (c) 2004-2013
38 * @version $Id: ActivityContact.php 45502 2013-02-08 13:32:55Z kurund $
39 *
40 */
41
42/**
43 * Files required for this package
44 */
45require_once 'api/v2/utils.php';
46
47require_once 'CRM/Activity/BAO/Activity.php';
48
49/**
50 * Retrieve a set of activities, specific to given input params.
51 *
52 * @param array $params (reference ) input parameters.
53 *
54 * @return array (reference) array of activities / error message.
55 * @access public
56
57 */
58function civicrm_activity_contact_get($params) {
59 _civicrm_initialize();
60
61 $contactId = CRM_Utils_Array::value('contact_id', $params);
62 if (empty($contactId)) {
63 return civicrm_create_error(ts("Required parameter not found"));
64 }
65
66 //check if $contactId is valid
67 if (!is_numeric($contactId) || !preg_match('/^\d+$/', $contactId)) {
68 return civicrm_create_error(ts("Invalid contact Id"));
69 }
70
71 $activities = &_civicrm_activities_get($contactId);
72
73 //show success for empty $activities array
74 if (empty($activities)) {
75 return civicrm_create_success(ts("0 activity record matching input params"));
76 }
77
78 if ($activities) {
79 return civicrm_create_success($activities);
80 }
81 else {
82 return civicrm_create_error(ts('Invalid Data'));
83 }
84}
85
86/**
87 * Retrieve a set of Activities specific to given contact Id.
88 *
89 * @param int $contactID.
90 *
91 * @return array (reference) array of activities.
92 * @access public
93
94 */
95function &_civicrm_activities_get($contactID, $type = 'all') {
96 $activities = CRM_Activity_BAO_Activity::getContactActivity($contactID);
97
98 //get the custom data.
99 if (is_array($activities) && !empty($activities)) {
100 require_once 'api/v2/Activity.php';
101 foreach ($activities as $activityId => $values) {
102 $customParams = array(
103 'activity_id' => $activityId,
104 'activity_type_id' => CRM_Utils_Array::value('activity_type_id', $values),
105 );
106
107 $customData = civicrm_activity_custom_get($customParams);
108
109 if (is_array($customData) && !empty($customData)) {
110 $activities[$activityId] = array_merge($activities[$activityId], $customData);
111 }
112 }
113 }
114
115 return $activities;
116}
117