Merge pull request #766 from eileenmcnaughton/test-fix
[civicrm-core.git] / api / v3 / ActivityType.php
CommitLineData
6a488035
TO
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
6a488035
TO
44/**
45 * Function to retrieve activity types
46 *
47 * @return array $activityTypes activity types keyed by id
48 * @access public
49 *
50 * @example ActivityTypeGet.php
51 * @deprecated - use constant_get
52 */
53function civicrm_api3_activity_type_get($params) {
54
55
56 $activityTypes = CRM_Core_OptionGroup::values('activity_type');
57 return civicrm_api3_create_success($activityTypes, $params, 'activity_type', 'get');
58}
59
60/**
61 * Function to create activity type (
62 *
63 * @param array $params associated array of fields
64 * $params['option_value_id'] is required for updation of activity type
65 *
66 * @return array $activityType created / updated activity type
67 *
68 * @access public
69 *
70 *{@schema Activity/ActivityType.xml}
71 *
72 * {@example ActivityTypeCreate.php 0}
73 * @deprecated - we will introduce OptionValue Create - plse consider helping with this if not done
74 */
75function civicrm_api3_activity_type_create($params) {
76
77
78 $action = 1;
79 $groupParams = array('name' => 'activity_type');
80
81 if ($optionValueID = CRM_Utils_Array::value('option_value_id', $params)) {
82 $action = 2;
83 }
84
6a488035
TO
85 $activityObject = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $action, $optionValueID);
86 $activityType = array();
87 _civicrm_api3_object_to_array($activityObject, $activityType[$activityObject->id]);
88 return civicrm_api3_create_success($activityType, $params, 'activity_type', 'create');
89}
11e09c59
TO
90
91/**
6a488035
TO
92 * Adjust Metadata for Create action
93 *
94 * The metadata is used for setting defaults, documentation & validation
95 * @param array $params array or parameters determined by getfields
96 */
97function _civicrm_api3_activity_type_create_spec(&$params) {
98 $params['label']['api.required'] = 1;
99 $params['weight']['api.required'] = 1;
100}
101
102/**
103 * Function to delete activity type
104 *
105 * @param activityTypeId int activity type id to delete
106 *
107 * @return boolen
108 *
109 * @access public
110 *
111 * @deprecated - we will introduce OptionValue Delete- plse consider helping with this if not done
112 * {@example ActivityTypeDelete.php 0}
113 */
114function civicrm_api3_activity_type_delete($params) {
115
116 civicrm_api3_verify_mandatory($params, NULL, array('activity_type_id'));
117
118 $activityTypeId = $params['activity_type_id'];
6a488035
TO
119
120 return CRM_Core_BAO_OptionValue::del($activityTypeId);
121}
122