Merge pull request #3679 from yashodha/CRM-14951
[civicrm-core.git] / api / v3 / EntityTag.php
index 3ea2aaea905bdcf325775e4540cd1a243cef9eb3..d0e20831e69cdd10ce225d72cf8aca1022d34f83 100644 (file)
@@ -2,9 +2,9 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -32,7 +32,7 @@
  * @package CiviCRM_APIv3
  * @subpackage API_EntityTag
  *
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * @version $Id: EntityTag.php 30879 2010-11-22 15:45:55Z shot $
  */
 
  */
 function civicrm_api3_entity_tag_get($params) {
 
-
-  $values = CRM_Core_BAO_EntityTag::getTag($params['entity_id'], $params['entity_table']);
-  $result = array();
-  foreach ($values as $v) {
-    $result[$v] = array('tag_id' => $v);
+  if(empty($params['entity_id'])) {
+    return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+  }
+  else{
+    //do legacy non-standard behaviour
+    $values = CRM_Core_BAO_EntityTag::getTag($params['entity_id'], $params['entity_table']);
+    $result = array();
+    foreach ($values as $v) {
+      $result[$v] = array('tag_id' => $v);
+    }
+    return civicrm_api3_create_success($result, $params);
   }
-  return civicrm_api3_create_success($result, $params);
 }
 
 /**
@@ -66,7 +71,6 @@ function civicrm_api3_entity_tag_get($params) {
  * @param array $params array or parameters determined by getfields
  */
 function _civicrm_api3_entity_tag_get_spec(&$params) {
-  $params['entity_id']['api.required'] = 1;
   $params['entity_id']['api.aliases'] = array('contact_id');
   $params['entity_table']['api.default'] = 'civicrm_contact';
 }
@@ -80,8 +84,6 @@ function _civicrm_api3_entity_tag_get_spec(&$params) {
  * @example EntityTagCreate.php
  */
 function civicrm_api3_entity_tag_create($params) {
-
-
   return _civicrm_api3_entity_tag_common($params, 'add');
 }
 
@@ -109,9 +111,9 @@ function _civicrm_api3_entity_tag_delete_spec(&$params) {
 /**
  *
  * @param <type> $params
- * @param <type> $op
+ * @param string $op
  *
- * @return <type>
+ * @return array <type>
  */
 function _civicrm_api3_entity_tag_common($params, $op = 'add') {