INFRA-132 - Comment grammar cleanup
[civicrm-core.git] / CRM / Core / BAO / EntityTag.php
index 34689a15baecc75c642789c7ee26f0ac29c7d475..12593abd3c2f17d29afc4db96af31f2c7a3f3bab 100644 (file)
@@ -40,16 +40,17 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
    * Given a contact id, it returns an array of tag id's the
    * contact belongs to.
    *
-   * @param int $entityID id of the entity usually the contactID.
-   * @param string $entityTable name of the entity table usually 'civicrm_contact'
+   * @param int $entityID
+   *   Id of the entity usually the contactID.
+   * @param string $entityTable
+   *   Name of the entity table usually 'civicrm_contact'.
    *
    * @return array(
-     ) reference $tag array of category id's the contact belongs to.
+  ) reference $tag array of category id's the contact belongs to.
    *
-   * @access public
    * @static
    */
-  static function &getTag($entityID, $entityTable = 'civicrm_contact') {
+  public static function &getTag($entityID, $entityTable = 'civicrm_contact') {
     $tags = array();
 
     $entityTag = new CRM_Core_BAO_EntityTag();
@@ -70,13 +71,13 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
    * group object. the params array could contain additional unused name/value
    * pairs
    *
-   * @param array  $params         (reference ) an assoc array of name/value pairs
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
    *
    * @return CRM_Core_BAO_EntityTag object
-   * @access public
    * @static
    */
-  static function add(&$params) {
+  public static function add(&$params) {
     $dataExists = self::dataExists($params);
     if (!$dataExists) {
       return NULL;
@@ -101,27 +102,27 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
   /**
    * Check if there is data to create the object
    *
-   * @param array  $params an assoc array of name/value pairs
+   * @param array $params
+   *   An assoc array of name/value pairs.
    *
    * @return boolean
-   * @access public
    * @static
    */
-  static function dataExists($params) {
+  public static function dataExists($params) {
     return !($params['tag_id'] == 0);
   }
 
   /**
    * Delete the tag for a contact
    *
-   * @param array  $params         (reference ) an assoc array of name/value pairs
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
    *
    * @return CRM_Core_BAO_EntityTag object
-   * @access public
    * @static
    *
    */
-  static function del(&$params) {
+  public static function del(&$params) {
     $entityTag = new CRM_Core_BAO_EntityTag();
     $entityTag->copyValues($params);
     $entityTag->delete();
@@ -134,15 +135,17 @@ 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
    * @static
    */
-  static function addEntitiesToTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') {
+  public static function addEntitiesToTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') {
     $numEntitiesAdded    = 0;
     $numEntitiesNotAdded = 0;
     $entityIdsAdded      = array();
@@ -177,15 +180,17 @@ 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
    * @static
    */
-  static function removeEntitiesFromTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') {
+  public static function removeEntitiesFromTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') {
     $numEntitiesRemoved = 0;
     $numEntitiesNotRemoved = 0;
     $entityIdsRemoved = array();
@@ -220,15 +225,15 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
   /**
    * 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 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 +270,12 @@ 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   $entityIds    array of entity ids
    */
-  function getEntitiesByTag($tag) {
+  public function getEntitiesByTag($tag) {
     $entityIds = array();
     $entityTagDAO = new CRM_Core_DAO_EntityTag();
     $entityTagDAO->tag_id = $tag->id;
@@ -284,7 +289,7 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
   /**
    * Get contact tags
    */
-  static function getContactTags($contactID, $count = FALSE) {
+  public static function getContactTags($contactID, $count = FALSE) {
     $contactTags = array();
     if (!$count) {
       $select = "SELECT name ";
@@ -317,7 +322,7 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
   /**
    * 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
@@ -339,8 +344,9 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
   /**
    * 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'),
     );
 
@@ -386,5 +392,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;
+  }
+}