X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FEntityTag.php;h=a43d0978d7bd75984eb43634a15e7962ab3f9ebe;hb=c6e262c51134924a9cc023dcb0613238fd1d0451;hp=5c955b696c6c774386ae2742e3c55cdcfe39210a;hpb=c490a46ac4bf490d3fbb31e35d24c6b43e764f00;p=civicrm-core.git diff --git a/CRM/Core/BAO/EntityTag.php b/CRM/Core/BAO/EntityTag.php index 5c955b696c..a43d0978d7 100644 --- a/CRM/Core/BAO/EntityTag.php +++ b/CRM/Core/BAO/EntityTag.php @@ -1,7 +1,7 @@ copyValues($params); $entityTag->delete(); @@ -134,24 +134,27 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { /** * Given an array of entity ids and entity table, add all the entity to the tags * - * @param array $entityIds (reference ) the array of entity ids to be added - * @param int $tagId the id of the tag - * @param string $entityTable name of entity table default:civicrm_contact + * @param array $entityIds + * (reference ) the array of entity ids to be added. + * @param int $tagId + * The id of the tag. + * @param string $entityTable + * Name of entity table default:civicrm_contact. * - * @return array (total, added, notAdded) count of enities added to tag - * @access public + * @return array + * (total, added, notAdded) count of enities added to tag * @static */ - static function addEntitiesToTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') { - $numEntitiesAdded = 0; + public static function addEntitiesToTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') { + $numEntitiesAdded = 0; $numEntitiesNotAdded = 0; - $entityIdsAdded = array(); + $entityIdsAdded = array(); foreach ($entityIds as $entityId) { $tag = new CRM_Core_DAO_EntityTag(); - $tag->entity_id = $entityId; - $tag->tag_id = $tagId; + $tag->entity_id = $entityId; + $tag->tag_id = $tagId; $tag->entity_table = $entityTable; if (!$tag->find()) { $tag->save(); @@ -177,15 +180,18 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { /** * Given an array of entity ids and entity table, remove entity(s) tags * - * @param array $entityIds (reference ) the array of entity ids to be removed - * @param int $tagId the id of the tag - * @param string $entityTable name of entity table default:civicrm_contact + * @param array $entityIds + * (reference ) the array of entity ids to be removed. + * @param int $tagId + * The id of the tag. + * @param string $entityTable + * Name of entity table default:civicrm_contact. * - * @return array (total, removed, notRemoved) count of entities removed from tags - * @access public + * @return array + * (total, removed, notRemoved) count of entities removed from tags * @static */ - static function removeEntitiesFromTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') { + public static function removeEntitiesFromTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') { $numEntitiesRemoved = 0; $numEntitiesNotRemoved = 0; $entityIdsRemoved = array(); @@ -193,8 +199,8 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { foreach ($entityIds as $entityId) { $tag = new CRM_Core_DAO_EntityTag(); - $tag->entity_id = $entityId; - $tag->tag_id = $tagId; + $tag->entity_id = $entityId; + $tag->tag_id = $tagId; $tag->entity_table = $entityTable; if ($tag->find()) { $tag->delete(); @@ -218,17 +224,17 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { } /** - * takes an associative array and creates tag entity record for all tag entities + * Takes an associative array and creates tag entity record for all tag entities * - * @param array $params (reference) an assoc array of name/value pairs + * @param array $params + * (reference) an assoc array of name/value pairs. * @param $entityTable - * @param $entityID + * @param int $entityID * * @return void - * @access public * @static */ - static function create(&$params, $entityTable, $entityID) { + public static function create(&$params, $entityTable, $entityID) { // get categories for the entity id $entityTag = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable); @@ -265,12 +271,13 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { /** * This function returns all entities assigned to a specific tag * - * @param object $tag an object of a tag. + * @param object $tag + * An object of a tag. * - * @return array $entityIds array of entity ids - * @access public + * @return array + * array of entity ids */ - function getEntitiesByTag($tag) { + public function getEntitiesByTag($tag) { $entityIds = array(); $entityTagDAO = new CRM_Core_DAO_EntityTag(); $entityTagDAO->tag_id = $tag->id; @@ -282,9 +289,9 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { } /** - * get contact tags + * Get contact tags */ - static function getContactTags($contactID, $count = FALSE) { + public static function getContactTags($contactID, $count = FALSE) { $contactTags = array(); if (!$count) { $select = "SELECT name "; @@ -315,9 +322,9 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { } /** - * get child contact tags given parentId + * Get child contact tags given parentId */ - static function getChildEntityTags($parentId, $entityId, $entityTable = 'civicrm_contact') { + public static function getChildEntityTags($parentId, $entityId, $entityTable = 'civicrm_contact') { $entityTags = array(); $query = "SELECT ct.id as tag_id, name FROM civicrm_tag ct INNER JOIN civicrm_entity_tag et ON ( et.entity_id = {$entityId} AND @@ -337,17 +344,18 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { } /** - * Function to merge two tags: tag B into tag A. + * Merge two tags: tag B into tag A. */ - function mergeTags($tagAId, $tagBId) { - $queryParams = array(1 => array($tagBId, 'Integer'), + public function mergeTags($tagAId, $tagBId) { + $queryParams = array( + 1 => array($tagBId, 'Integer'), 2 => array($tagAId, 'Integer'), ); // re-compute used_for field $query = "SELECT id, name, used_for FROM civicrm_tag WHERE id IN (%1, %2)"; - $dao = CRM_Core_DAO::executeQuery($query, $queryParams); - $tags = array(); + $dao = CRM_Core_DAO::executeQuery($query, $queryParams); + $tags = array(); while ($dao->fetch()) { $label = ($dao->id == $tagAId) ? 'tagA' : 'tagB'; $tags[$label] = $dao->name; @@ -386,5 +394,30 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { $tags['status'] = TRUE; return $tags; } -} + /** + * Get options for a given field. + * @see CRM_Core_DAO::buildOptions + * + * @param string $fieldName + * @param string $context + * : @see CRM_Core_DAO::buildOptionsContext. + * @param array $props + * : whatever is known about this dao object. + * + * @return Array|bool + */ + public static function buildOptions($fieldName, $context = NULL, $props = array()) { + $params = array(); + + $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); + + // 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), '- '); + } + + return $options; + } +}