Merge pull request #900 from dlobo/CRM-12588
[civicrm-core.git] / api / v3 / Tag.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 * File for the CiviCRM APIv3 tag functions
31 *
32 * @package CiviCRM_APIv3
33 * @subpackage API_Tag
34 *
35 * @copyright CiviCRM LLC (c) 2004-2013
36 * @version $Id: Tag.php 30486 2010-11-02 16:12:09Z shot $
37 */
38
39 /**
40 * Add a Tag. Tags are used to classify CRM entities (including Contacts, Groups and Actions).
41 *
42 * Allowed @params array keys are:
43 *
44 * {@example TagCreate.php}
45 *
46 * @return array of newly created tag property values.
47 * {@getfields tag_create}
48 * @access public
49 */
50 function civicrm_api3_tag_create($params) {
51
52 $ids = array('tag' => CRM_Utils_Array::value('tag', $params));
53 if (CRM_Utils_Array::value('tag', $params)) {
54 $ids['tag'] = $params['tag'];
55 }
56 if (CRM_Utils_Array::value('id', $params)) {
57 $ids['tag'] = $params['id'];
58 }
59 $tagBAO = CRM_Core_BAO_Tag::add($params, $ids);
60
61 $values = array();
62 _civicrm_api3_object_to_array($tagBAO, $values[$tagBAO->id]);
63 return civicrm_api3_create_success($values, $params, 'tag', 'create', $tagBAO);
64 }
65
66 /**
67 * Specify Meta data for create. Note that this data is retrievable via the getfields function
68 * and is used for pre-filling defaults and ensuring mandatory requirements are met.
69 */
70 function _civicrm_api3_tag_create_spec(&$params) {
71 $params['used_for']['api.default'] = 'civicrm_contact';
72 $params['name']['api.required'] = 1;
73 }
74
75 /**
76 * Deletes an existing Tag
77 *
78 * @param array $params
79 *
80 * @example TagDelete.ph
81 *
82 * @return boolean | error true if successfull, error otherwise
83 * {@getfields tag_delete}
84 * @access public
85 */
86 function civicrm_api3_tag_delete($params) {
87 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
88 }
89
90 /**
91 * Get a Tag.
92 *
93 * This api is used for finding an existing tag.
94 * Either id or name of tag are required parameters for this api.
95 *
96 * @example TagGet.php
97 *
98 * @param array $params an associative array of name/value pairs.
99 *
100 * @return array details of found tags else error
101 * {@getfields tag_get}
102 * @access public
103 */
104 function civicrm_api3_tag_get($params) {
105
106 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
107 }
108