Merge pull request #287 from totten/givi
[civicrm-core.git] / api / v3 / ActivityType.php
1 <?php
2 // $Id$
3
4 /*
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
11 | |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
20 | |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
28 */
29
30 /**
31 * Definition of the ActivityType part of the CRM API.
32 * More detailed documentation can be found
33 * {@link http://objectledge.org/confluence/display/CRM/CRM+v1.0+Public+APIs
34 * here}
35 *
36 * @package CiviCRM_APIv3
37 * @subpackage API_Activity
38 *
39 * @copyright CiviCRM LLC (c) 2004-2013
40 * $Id: ActivityType.php 30171 2010-10-14 09:11:27Z mover $
41 *
42 */
43
44 /**
45 * Include common API util functions
46 */
47 require_once 'CRM/Core/OptionGroup.php';
48
49 /**
50 * Function to retrieve activity types
51 *
52 * @return array $activityTypes activity types keyed by id
53 * @access public
54 *
55 * @example ActivityTypeGet.php
56 * @deprecated - use constant_get
57 */
58 function civicrm_api3_activity_type_get($params) {
59
60
61 $activityTypes = CRM_Core_OptionGroup::values('activity_type');
62 return civicrm_api3_create_success($activityTypes, $params, 'activity_type', 'get');
63 }
64
65 /**
66 * Function to create activity type (
67 *
68 * @param array $params associated array of fields
69 * $params['option_value_id'] is required for updation of activity type
70 *
71 * @return array $activityType created / updated activity type
72 *
73 * @access public
74 *
75 *{@schema Activity/ActivityType.xml}
76 *
77 * {@example ActivityTypeCreate.php 0}
78 * @deprecated - we will introduce OptionValue Create - plse consider helping with this if not done
79 */
80 function civicrm_api3_activity_type_create($params) {
81
82
83 $action = 1;
84 $groupParams = array('name' => 'activity_type');
85
86 if ($optionValueID = CRM_Utils_Array::value('option_value_id', $params)) {
87 $action = 2;
88 }
89
90 require_once 'CRM/Core/OptionValue.php';
91 $activityObject = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $action, $optionValueID);
92 $activityType = array();
93 _civicrm_api3_object_to_array($activityObject, $activityType[$activityObject->id]);
94 return civicrm_api3_create_success($activityType, $params, 'activity_type', 'create');
95 }
96
97 /**
98 * Adjust Metadata for Create action
99 *
100 * The metadata is used for setting defaults, documentation & validation
101 * @param array $params array or parameters determined by getfields
102 */
103 function _civicrm_api3_activity_type_create_spec(&$params) {
104 $params['label']['api.required'] = 1;
105 $params['weight']['api.required'] = 1;
106 }
107
108 /**
109 * Function to delete activity type
110 *
111 * @param activityTypeId int activity type id to delete
112 *
113 * @return boolen
114 *
115 * @access public
116 *
117 * @deprecated - we will introduce OptionValue Delete- plse consider helping with this if not done
118 * {@example ActivityTypeDelete.php 0}
119 */
120 function civicrm_api3_activity_type_delete($params) {
121
122 civicrm_api3_verify_mandatory($params, NULL, array('activity_type_id'));
123
124 $activityTypeId = $params['activity_type_id'];
125 require_once 'CRM/Core/BAO/OptionValue.php';
126
127 return CRM_Core_BAO_OptionValue::del($activityTypeId);
128 }
129