Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-08-31-12-20-39
[civicrm-core.git] / CRM / Core / BAO / EntityTag.php
index 2064277944b02cb02d945deb69ffcea4674997c7..1935f79d5bb5067df7d074a7a476c07c29b9be90 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -29,7 +29,7 @@
  * This class contains functions for managing Tag(tag) for a contact
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -403,14 +403,21 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
   public static function buildOptions($fieldName, $context = NULL, $props = array()) {
     $params = array();
 
-    $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+    if ($fieldName == 'tag' || $fieldName == 'tag_id') {
+      if (!empty($props['entity_table'])) {
+        $entity = CRM_Utils_Type::escape($props['entity_table'], 'String');
+        $params[] = "used_for LIKE '%$entity%'";
+      }
 
-    // Output tag list as nested hierarchy
-    // TODO: This will only work when api.entity is "entity_tag". What about others?
-    if (($fieldName == 'tag' || $fieldName == 'tag_id') && ($context == 'search' || $context == 'create')) {
-      $options = CRM_Core_BAO_Tag::getTags('civicrm_contact', CRM_Core_DAO::$_nullArray, CRM_Utils_Array::value('parent_id', $params), '- ');
+      // Output tag list as nested hierarchy
+      // TODO: This will only work when api.entity is "entity_tag". What about others?
+      if ($context == 'search' || $context == 'create') {
+        return CRM_Core_BAO_Tag::getTags(CRM_Utils_Array::value('entity_table', $props, 'civicrm_contact'), CRM_Core_DAO::$_nullArray, CRM_Utils_Array::value('parent_id', $params), '- ');
+      }
     }
 
+    $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+
     return $options;
   }