a5a9525660b0ba3f385bc4a616c62c69d97170f3
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
30 * File for the CiviCRM APIv3 entity tag functions
32 * @package CiviCRM_APIv3
33 * @subpackage API_EntityTag
35 * @copyright CiviCRM LLC (c) 2004-2013
36 * @version $Id: EntityTag.php 30879 2010-11-22 15:45:55Z shot $
40 * Include utility functions
44 * {@getfields EntityTag_get}
45 * @example EntityTagGet.php
47 * @param array $params
51 function civicrm_api3_entity_tag_get($params) {
54 $values = CRM_Core_BAO_EntityTag
::getTag($params['entity_id'], $params['entity_table']);
56 foreach ($values as $v) {
57 $result[$v] = array('tag_id' => $v);
59 return civicrm_api3_create_success($result, $params);
63 * Adjust Metadata for Get action
65 * The metadata is used for setting defaults, documentation & validation
66 * @param array $params array or parameters determined by getfields
68 function _civicrm_api3_entity_tag_get_spec(&$params) {
69 $params['entity_id']['api.required'] = 1;
70 $params['entity_id']['api.aliases'] = array('contact_id');
71 $params['entity_table']['api.default'] = 'civicrm_contact';
76 * @param array $params
79 * {@getfields EntityTag_create}
80 * @example EntityTagCreate.php
82 function civicrm_api3_entity_tag_create($params) {
83 return _civicrm_api3_entity_tag_common($params, 'add');
87 *{@getfields EntityTag_delete}
88 * @example EntityTagGet.php
90 * @param array $params
94 function civicrm_api3_entity_tag_delete($params) {
96 return _civicrm_api3_entity_tag_common($params, 'remove');
102 function _civicrm_api3_entity_tag_delete_spec(&$params) {
103 // set as not required as tag_id also acceptable & no either/or std yet
104 $params['id']['api.required'] = 0;
109 * @param <type> $params
114 function _civicrm_api3_entity_tag_common($params, $op = 'add') {
116 $entityIDs = array();
118 $entityTable = 'civicrm_contact';
119 if (is_array($params)) {
120 foreach ($params as $n => $v) {
121 if ((substr($n, 0, 10) == 'contact_id') ||
(substr($n, 0, 9) == 'entity_id')) {
124 elseif (substr($n, 0, 6) == 'tag_id') {
127 elseif (substr($n, 0, 12) == 'entity_table') {
132 if (empty($entityIDs)) {
133 return civicrm_api3_create_error('contact_id is a required field');
136 if (empty($tagIDs)) {
137 return civicrm_api3_create_error('tag_id is a required field');
140 $values = array('is_error' => 0);
142 $values['total_count'] = $values['added'] = $values['not_added'] = 0;
143 foreach ($tagIDs as $tagID) {
144 list($te, $a, $na) = CRM_Core_BAO_EntityTag
::addEntitiesToTag($entityIDs, $tagID, $entityTable);
145 $values['total_count'] +
= $te;
146 $values['added'] +
= $a;
147 $values['not_added'] +
= $na;
151 $values['total_count'] = $values['removed'] = $values['not_removed'] = 0;
152 foreach ($tagIDs as $tagID) {
153 list($te, $r, $nr) = CRM_Core_BAO_EntityTag
::removeEntitiesFromTag($entityIDs, $tagID, $entityTable);
154 $values['total_count'] +
= $te;
155 $values['removed'] +
= $r;
156 $values['not_removed'] +
= $nr;