codespell: CRM/*
[civicrm-core.git] / CRM / Core / BAO / Tag.php
index 435cdc7e2148b8520a59207188ff2639734e6e3e..9d7e976b29d01ffa0bef30ea04a846e64d7acc2a 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
 class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
 
   /**
-   * Class constructor
+   * Class constructor.
    */
   public function __construct() {
     parent::__construct();
   }
 
   /**
-   * Fetch object based on array of properties
+   * Fetch object based on array of properties.
    *
-   * @param array $params      (reference ) an assoc array of name/value pairs
-   * @param array $defaults    (reference ) an assoc array to hold the flattened values
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   * @param array $defaults
+   *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return object     CRM_Core_DAO_Tag object on success, otherwise null
-   * @static
+   * @return object
+   *   CRM_Core_DAO_Tag object on success, otherwise null
    */
   public static function retrieve(&$params, &$defaults) {
     $tag = new CRM_Core_DAO_Tag();
@@ -124,10 +126,11 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
    *
    * @return array
    */
-  public static function getTagsUsedFor($usedFor = array('civicrm_contact'),
+  public static function getTagsUsedFor(
+    $usedFor = array('civicrm_contact'),
     $buildSelect = TRUE,
-    $all         = FALSE,
-    $parentId    = NULL
+    $all = FALSE,
+    $parentId = NULL
   ) {
     $tags = array();
 
@@ -178,20 +181,26 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
   }
 
   /**
-   * Function to retrieve tags
+   * Function to retrieve tags.
    *
-   * @param string $usedFor which type of tag entity
-   * @param array $tags tags array
-   * @param int $parentId parent id if you want need only children
-   * @param string $separator separator to indicate children
-   * @param boolean $formatSelectable add special property for non-selectable
+   * @param string $usedFor
+   *   Which type of tag entity.
+   * @param array $tags
+   *   Tags array.
+   * @param int $parentId
+   *   Parent id if you want need only children.
+   * @param string $separator
+   *   Separator to indicate children.
+   * @param bool $formatSelectable
+   *   Add special property for non-selectable.
    *                tag, so they cannot be selected
    *
    * @return array
    */
-  static function getTags($usedFor = 'civicrm_contact',
+  public static function getTags(
+    $usedFor = 'civicrm_contact',
     &$tags = array(),
-    $parentId  = NULL,
+    $parentId = NULL,
     $separator = '  ',
     $formatSelectable = FALSE
   ) {
@@ -199,10 +208,10 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
       $tags = array();
     }
     // We need to build a list of tags ordered by hierarchy and sorted by
-    // name. The heirarchy will be communicated by an accumulation of
+    // name. The hierarchy will be communicated by an accumulation of
     // separators in front of the name to give it a visual offset.
     // Instead of recursively making mysql queries, we'll make one big
-    // query and build the heirarchy with the algorithm below.
+    // query and build the hierarchy with the algorithm below.
     $args = array(1 => array('%' . $usedFor . '%', 'String'));
     $query = "SELECT id, name, parent_id, is_tagset, is_selectable
                   FROM civicrm_tag
@@ -237,7 +246,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
           'prefix' => '',
           'name' => $dao->name,
           'idPrefix' => $idPrefix,
-          );
+        );
       }
       else {
         $rows[] = array(
@@ -246,7 +255,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
           'name' => $dao->name,
           'parent_id' => $dao->parent_id,
           'idPrefix' => $idPrefix,
-         );
+        );
       }
     }
 
@@ -257,14 +266,14 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
     // iterate through because we must modify the unplaced nodes list
     // during the loop.
     while (count($roots)) {
-      $new_roots         = array();
-      $current_rows      = $rows;
-      $root              = array_shift($roots);
+      $new_roots = array();
+      $current_rows = $rows;
+      $root = array_shift($roots);
       $tags[$root['id']] = array(
         $root['prefix'],
         $root['name'],
         $root['idPrefix'],
-        );
+      );
 
       // As you find the children, append them to the end of the new set
       // of roots (maintain alphabetical ordering). Also remove the node
@@ -277,7 +286,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
               'prefix' => $tags[$root['id']][0] . $separator,
               'name' => $row['name'],
               'idPrefix' => $row['idPrefix'],
-              );
+            );
             unset($rows[$key]);
           }
         }
@@ -295,7 +304,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
     $formattedTags = array();
     foreach ($tags as $key => $tag) {
       if (!empty($tag[2])) {
-        $key = $tag[2]. "-" . $key;
+        $key = $tag[2] . "-" . $key;
       }
       $formattedTags[$key] = $tag[0] . $tag[1];
     }
@@ -305,17 +314,16 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
   }
 
   /**
-   * Delete the tag
-   *
-   * @param int $id   tag id
+   * Delete the tag.
    *
-   * @return boolean
-   * @static
+   * @param int $id
+   *   Tag id.
    *
+   * @return bool
    */
   public static function del($id) {
     // since this is a destructive operation, lets make sure
-    // id is a postive number
+    // id is a positive number
     CRM_Utils_Type::validate($id, 'Positive');
 
     // delete all crm_entity_tag records with the selected tag id
@@ -337,18 +345,20 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
   }
 
   /**
-   * Takes an associative array and creates a contact object
+   * Takes an associative array and creates a contact object.
    *
    * The function extract all the params it needs to initialize the create a
    * contact object. the params array could contain additional unused name/value
    * pairs
    *
-   * @param array  $params         (reference) an assoc array of name/value pairs
-   * @param array  $ids  (optional)  the array that holds all the db ids - we are moving away from this in bao
+   * @param array $params
+   *   (reference) an assoc array of name/value pairs.
+   * @param array $ids
+   *   (optional) the array that holds all the db ids - we are moving away from this in bao.
    * signatures
    *
-   * @return object    CRM_Core_DAO_Tag object on success, otherwise null
-   * @static
+   * @return object
+   *   CRM_Core_DAO_Tag object on success, otherwise null
    */
   public static function add(&$params, $ids = array()) {
     $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('tag', $ids));
@@ -371,8 +381,8 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
 
     // save creator id and time
     if (!$tag->id) {
-      $session           = CRM_Core_Session::singleton();
-      $tag->created_id   = $session->get('userID');
+      $session = CRM_Core_Session::singleton();
+      $tag->created_id = $session->get('userID');
       $tag->created_date = date('YmdHis');
     }
 
@@ -382,7 +392,8 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
     // if we modify parent tag, then we need to update all children
     if ($tag->parent_id === 'null') {
       CRM_Core_DAO::executeQuery("UPDATE civicrm_tag SET used_for=%1 WHERE parent_id = %2",
-        array(1 => array($params['used_for'], 'String'),
+        array(
+          1 => array($params['used_for'], 'String'),
           2 => array($tag->id, 'Integer'),
         )
       );
@@ -392,12 +403,12 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
   }
 
   /**
-   * Check if there is data to create the object
+   * Check if there is data to create the object.
    *
-   * @param array  $params         (reference ) an assoc array of name/value pairs
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
    *
-   * @return boolean
-   * @static
+   * @return bool
    */
   public static function dataExists(&$params) {
     // Disallow empty values except for the number zero.
@@ -410,18 +421,24 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
   }
 
   /**
-   * Get the tag sets for a entity object
+   * Get the tag sets for a entity object.
    *
-   * @param string $entityTable entity_table
+   * @param string $entityTable
+   *   Entity_table.
    *
-   * @return array $tagSets array of tag sets
-   * @static
+   * @return array
+   *   array of tag sets
    */
   public static function getTagSet($entityTable) {
     $tagSets = array();
     $query = "SELECT name, id FROM civicrm_tag
               WHERE is_tagset=1 AND parent_id IS NULL and used_for LIKE %1";
-    $dao = CRM_Core_DAO::executeQuery($query, array(1 => array('%' . $entityTable . '%', 'String')), TRUE, NULL, FALSE, FALSE);
+    $dao = CRM_Core_DAO::executeQuery($query, array(
+        1 => array(
+          '%' . $entityTable . '%',
+          'String',
+        ),
+      ), TRUE, NULL, FALSE, FALSE);
     while ($dao->fetch()) {
       $tagSets[$dao->id] = $dao->name;
     }
@@ -432,8 +449,8 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
   /**
    * Get the tags that are not children of a tagset.
    *
-   * @return array $tags associated array of tag name and id@access public
-   * @static
+   * @return array
+   *   associated array of tag name and id
    */
   public static function getTagsNotInTagset() {
     $tags = $tagSets = array();
@@ -458,4 +475,5 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
 
     return $tags;
   }
+
 }