Commit | Line | Data |
---|---|---|
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 | * File for the CiviCRM APIv3 tag functions | |
32 | * | |
33 | * @package CiviCRM_APIv3 | |
34 | * @subpackage API_Tag | |
35 | * | |
36 | * @copyright CiviCRM LLC (c) 2004-2013 | |
37 | * @version $Id: Tag.php 30486 2010-11-02 16:12:09Z shot $ | |
38 | */ | |
39 | ||
40 | /** | |
41 | * Include utility functions | |
42 | */ | |
43 | require_once 'CRM/Core/BAO/Tag.php'; | |
44 | ||
45 | /** | |
46 | * Add a Tag. Tags are used to classify CRM entities (including Contacts, Groups and Actions). | |
47 | * | |
48 | * Allowed @params array keys are: | |
49 | * | |
50 | * {@example TagCreate.php} | |
51 | * | |
52 | * @return array of newly created tag property values. | |
53 | * {@getfields tag_create} | |
54 | * @access public | |
55 | */ | |
56 | function civicrm_api3_tag_create($params) { | |
57 | ||
58 | $ids = array('tag' => CRM_Utils_Array::value('tag', $params)); | |
59 | if (CRM_Utils_Array::value('tag', $params)) { | |
60 | $ids['tag'] = $params['tag']; | |
61 | } | |
62 | if (CRM_Utils_Array::value('id', $params)) { | |
63 | $ids['tag'] = $params['id']; | |
64 | } | |
65 | $tagBAO = CRM_Core_BAO_Tag::add($params, $ids); | |
66 | ||
67 | $values = array(); | |
68 | _civicrm_api3_object_to_array($tagBAO, $values[$tagBAO->id]); | |
69 | return civicrm_api3_create_success($values, $params, 'tag', 'create', $tagBAO); | |
70 | } | |
11e09c59 TO |
71 | |
72 | /** | |
6a488035 TO |
73 | * Specify Meta data for create. Note that this data is retrievable via the getfields function |
74 | * and is used for pre-filling defaults and ensuring mandatory requirements are met. | |
75 | */ | |
76 | function _civicrm_api3_tag_create_spec(&$params) { | |
77 | $params['used_for']['api.default'] = 'civicrm_contact'; | |
78 | $params['name']['api.required'] = 1; | |
79 | } | |
80 | ||
81 | /** | |
82 | * Deletes an existing Tag | |
83 | * | |
84 | * @param array $params | |
85 | * | |
86 | * @example TagDelete.ph | |
87 | * | |
88 | * @return boolean | error true if successfull, error otherwise | |
89 | * {@getfields tag_delete} | |
90 | * @access public | |
91 | */ | |
92 | function civicrm_api3_tag_delete($params) { | |
93 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
94 | } | |
95 | ||
96 | /** | |
97 | * Get a Tag. | |
98 | * | |
99 | * This api is used for finding an existing tag. | |
100 | * Either id or name of tag are required parameters for this api. | |
101 | * | |
102 | * @example TagGet.php | |
103 | * | |
104 | * @param array $params an associative array of name/value pairs. | |
105 | * | |
106 | * @return array details of found tags else error | |
107 | * {@getfields tag_get} | |
108 | * @access public | |
109 | */ | |
110 | function civicrm_api3_tag_get($params) { | |
111 | ||
112 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
113 | } | |
114 |