Merge pull request #6458 from totten/4.6-toxic-list
[civicrm-core.git] / CRM / Contact / BAO / GroupNesting.php
index d6ad7f296e6f2ecc2645c24edadb947e3d6446b1..03522d43afcd05e01c5484bd037d37448c0c83da 100644 (file)
@@ -24,7 +24,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -50,7 +50,10 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
   private $_alreadyStyled = FALSE;
 
   /**
-   * Class constructor
+   * Class constructor.
+   *
+   * @param bool $styleLabels
+   * @param string $styleIndent
    */
   public function __construct($styleLabels = FALSE, $styleIndent = " -- ") {
     parent::__construct();
@@ -105,14 +108,17 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
     $this->_alreadyStyled = FALSE;
   }
 
+  /**
+   * @return mixed
+   */
   public function current() {
     if ($this->_styleLabels &&
       $this->valid() &&
       !$this->_alreadyStyled
     ) {
-      $styledGroup  = clone($this->_current);
+      $styledGroup = clone($this->_current);
       $nestingLevel = $this->getCurrentNestingLevel();
-      $indent       = '';
+      $indent = '';
       while ($nestingLevel--) {
         $indent .= $this->_styleIndent;
       }
@@ -155,7 +161,7 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
       $nextGroup = $this->_getNextSiblingGroup($currentGroup);
       if (!$nextGroup) {
         // no sibling, find an ancestor w/ a sibling
-        for (;; ) {
+        for (;;) {
           // since we pop this array everytime, we should be
           // reasonably safe from infinite loops, I think :)
           $ancestor = array_pop($this->_parentStack);
@@ -194,7 +200,7 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    */
   public function _getNextParentlessGroup(&$group = NULL) {
     $lastParentlessGroup = $this->_lastParentlessGroup;
-    $nextGroup           = new CRM_Contact_BAO_Group();
+    $nextGroup = new CRM_Contact_BAO_Group();
     $nextGroup->order_by = 'title ' . self::$_sortOrder;
     $nextGroup->find();
     if ($group == NULL) {
@@ -259,10 +265,10 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
     }
     else {
       /* if we get here, it could be because we're out of siblings
-             * (in which case we return null) or because we're at the
-             * top level groups which do not have parents but may still
-             * have siblings, so check for that first.
-             */
+       * (in which case we return null) or because we're at the
+       * top level groups which do not have parents but may still
+       * have siblings, so check for that first.
+       */
 
       $nextGroup = $this->_getNextParentlessGroup($group);
       if ($nextGroup) {
@@ -277,8 +283,10 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * Adds a new child group identified by $childGroupId to the group
    * identified by $groupId
    *
-   * @param int $parentID id of the group to add the child to
-   * @param int $childID id of the new child group
+   * @param int $parentID
+   *   Id of the group to add the child to.
+   * @param int $childID
+   *   Id of the new child group.
    *
    *
    * @return void
@@ -295,11 +303,12 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * identified by $groupId; does not delete child group, just the
    * association between the two
    *
-   * @param            $parentID         The id of the group to remove the child from
-   * @param            $childID          The id of the child group being removed
-   *
-   * @return           void
+   * @param $parentID
+   *   The id of the group to remove the child from.
+   * @param $childID
+   *   The id of the child group being removed.
    *
+   * @return void
    */
   public static function remove($parentID, $childID) {
     $dao = new CRM_Contact_DAO_GroupNesting();
@@ -312,10 +321,10 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * identified by $groupId; does not delete child group, just the
    * association between the two
    *
-   * @param int $childID The id of the child group being removed
-   *
-   * @return           void
+   * @param int $childID
+   *   The id of the child group being removed.
    *
+   * @return void
    */
   public static function removeAllParentForChild($childID) {
     $dao = new CRM_Contact_DAO_GroupNesting();
@@ -327,11 +336,13 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * Returns true if the association between parent and child is present,
    * false otherwise.
    *
-   * @param            $parentID         The parent id of the association
-   * @param            $childID          The child id of the association
-   *
-   * @return           boolean           True if association is found, false otherwise.
+   * @param $parentID
+   *   The parent id of the association.
+   * @param $childID
+   *   The child id of the association.
    *
+   * @return bool
+   *   True if association is found, false otherwise.
    */
   public static function isParentChild($parentID, $childID) {
     $dao = new CRM_Contact_DAO_GroupNesting();
@@ -347,10 +358,11 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * Returns true if if the given groupId has 1 or more child groups,
    * false otherwise.
    *
-   * @param            $groupId               The id of the group to check for child groups
-   *
-   * @return           boolean                True if 1 or more child groups are found, false otherwise.
+   * @param $groupId
+   *   The id of the group to check for child groups.
    *
+   * @return bool
+   *   True if 1 or more child groups are found, false otherwise.
    */
   public static function hasChildGroups($groupId) {
     $dao = new CRM_Contact_DAO_GroupNesting();
@@ -367,10 +379,11 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * Returns true if the given groupId has 1 or more parent groups,
    * false otherwise.
    *
-   * @param            $groupId               The id of the group to check for parent groups
-   *
-   * @return           boolean                True if 1 or more parent groups are found, false otherwise.
+   * @param $groupId
+   *   The id of the group to check for parent groups.
    *
+   * @return bool
+   *   True if 1 or more parent groups are found, false otherwise.
    */
   public static function hasParentGroups($groupId) {
     $dao = new CRM_Contact_DAO_GroupNesting();
@@ -386,11 +399,13 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * Returns true if checkGroupId is a parent of one of the groups in
    * groupIds, false otherwise.
    *
-   * @param            $groupIds              Array of group ids (or one group id) to serve as the starting point
-   * @param            $checkGroupId         The group id to check if it is a parent of the $groupIds group(s)
-   *
-   * @return           boolean                True if $checkGroupId points to a group that is a parent of one of the $groupIds groups, false otherwise.
+   * @param array $groupIds
+   *   of group ids (or one group id) to serve as the starting point.
+   * @param $checkGroupId
+   *   The group id to check if it is a parent of the $groupIds group(s).
    *
+   * @return bool
+   *   True if $checkGroupId points to a group that is a parent of one of the $groupIds groups, false otherwise.
    */
   public static function isParentGroup($groupIds, $checkGroupId) {
     if (!is_array($groupIds)) {
@@ -403,8 +418,8 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
       $parentGroupId = $dao->parent_group_id;
       if ($parentGroupId == $checkGroupId) {
         /* print "One of these: <pre>";
-                print_r($groupIds);
-                print "</pre> has groupId $checkGroupId as an ancestor.<br/>"; */
+        print_r($groupIds);
+        print "</pre> has groupId $checkGroupId as an ancestor.<br/>"; */
 
         return TRUE;
       }
@@ -416,11 +431,13 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * Returns true if checkGroupId is a child of one of the groups in
    * groupIds, false otherwise.
    *
-   * @param            $groupIds              Array of group ids (or one group id) to serve as the starting point
-   * @param            $checkGroupId         The group id to check if it is a child of the $groupIds group(s)
-   *
-   * @return           boolean                True if $checkGroupId points to a group that is a child of one of the $groupIds groups, false otherwise.
+   * @param array $groupIds
+   *   of group ids (or one group id) to serve as the starting point.
+   * @param $checkGroupId
+   *   The group id to check if it is a child of the $groupIds group(s).
    *
+   * @return bool
+   *   True if $checkGroupId points to a group that is a child of one of the $groupIds groups, false otherwise.
    */
   public static function isChildGroup($groupIds, $checkGroupId) {
 
@@ -435,8 +452,8 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
       $childGroupId = $dao->child_group_id;
       if ($childGroupId == $checkGroupId) {
         /* print "One of these: <pre>";
-                 print_r($groupIds);
-                 print "</pre> has groupId $checkGroupId as a descendent.<br/><br/>"; */
+        print_r($groupIds);
+        print "</pre> has groupId $checkGroupId as a descendent.<br/><br/>"; */
 
         return TRUE;
       }
@@ -448,11 +465,13 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * Returns true if checkGroupId is an ancestor of one of the groups in
    * groupIds, false otherwise.
    *
-   * @param            $groupIds              Array of group ids (or one group id) to serve as the starting point
-   * @param            $checkGroupId         The group id to check if it is an ancestor of the $groupIds group(s)
-   *
-   * @return           boolean                True if $checkGroupId points to a group that is an ancestor of one of the $groupIds groups, false otherwise.
+   * @param array $groupIds
+   *   of group ids (or one group id) to serve as the starting point.
+   * @param $checkGroupId
+   *   The group id to check if it is an ancestor of the $groupIds group(s).
    *
+   * @return bool
+   *   True if $checkGroupId points to a group that is an ancestor of one of the $groupIds groups, false otherwise.
    */
   public static function isAncestorGroup($groupIds, $checkGroupId) {
     if (!is_array($groupIds)) {
@@ -468,8 +487,8 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
       $parentGroupId = $dao->parent_group_id;
       if ($parentGroupId == $checkGroupId) {
         /* print "One of these: <pre>";
-                print_r($groupIds);
-                print "</pre> has groupId $checkGroupId as an ancestor.<br/>"; */
+        print_r($groupIds);
+        print "</pre> has groupId $checkGroupId as an ancestor.<br/>"; */
 
         return TRUE;
       }
@@ -487,11 +506,13 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
    * Returns true if checkGroupId is a descendent of one of the groups in
    * groupIds, false otherwise.
    *
-   * @param            $groupIds              Array of group ids (or one group id) to serve as the starting point
-   * @param            $checkGroupId         The group id to check if it is a descendent of the $groupIds group(s)
-   *
-   * @return           boolean                True if $checkGroupId points to a group that is a descendent of one of the $groupIds groups, false otherwise.
+   * @param array $groupIds
+   *   of group ids (or one group id) to serve as the starting point.
+   * @param $checkGroupId
+   *   The group id to check if it is a descendent of the $groupIds group(s).
    *
+   * @return bool
+   *   True if $checkGroupId points to a group that is a descendent of one of the $groupIds groups, false otherwise.
    */
   public static function isDescendentGroup($groupIds, $checkGroupId) {
     if (!is_array($groupIds)) {
@@ -507,8 +528,8 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
       $childGroupId = $dao->child_group_id;
       if ($childGroupId == $checkGroupId) {
         /* print "One of these: <pre>";
-                print_r($groupIds);
-                print "</pre> has groupId $checkGroupId as a descendent.<br/><br/>"; */
+        print_r($groupIds);
+        print "</pre> has groupId $checkGroupId as a descendent.<br/><br/>"; */
 
         return TRUE;
       }
@@ -525,11 +546,13 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
   /**
    * Returns array of group ids of ancestor groups of the specified group.
    *
-   * @param             $groupIds             An array of valid group ids (passed by reference)
+   * @param array $groupIds
+   *   An array of valid group ids (passed by reference).
    *
    * @param bool $includeSelf
    *
-   * @return array $groupIdArray         List of groupIds that represent the requested group and its ancestors@access public
+   * @return array
+   *   List of groupIds that represent the requested group and its ancestors
    */
   public static function getAncestorGroupIds($groupIds, $includeSelf = TRUE) {
     if (!is_array($groupIds)) {
@@ -561,10 +584,12 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
   /**
    * Returns array of ancestor groups of the specified group.
    *
-   * @param             $groupIds     An array of valid group ids (passed by reference)
+   * @param array $groupIds
+   *   An array of valid group ids (passed by reference).
    *
    * @param bool $includeSelf
-   * @return \An $groupArray   List of ancestor groups@access public
+   * @return array
+   *   List of ancestor groups
    */
   public static function getAncestorGroups($groupIds, $includeSelf = TRUE) {
     $groupIds = self::getAncestorGroupIds($groupIds, $includeSelf);
@@ -575,9 +600,11 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
   /**
    * Returns array of group ids of child groups of the specified group.
    *
-   * @param             $groupIds     An array of valid group ids (passed by reference)
+   * @param array $groupIds
+   *   An array of valid group ids (passed by reference).
    *
-   * @return array $groupIdArray List of groupIds that represent the requested group and its children@access public
+   * @return array
+   *   List of groupIds that represent the requested group and its children
    */
   public static function getChildGroupIds($groupIds) {
     if (!is_array($groupIds)) {
@@ -596,9 +623,11 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
   /**
    * Returns array of group ids of parent groups of the specified group.
    *
-   * @param             $groupIds               An array of valid group ids (passed by reference)
+   * @param array $groupIds
+   *   An array of valid group ids (passed by reference).
    *
-   * @return array $groupIdArray         List of groupIds that represent the requested group and its parents@access public
+   * @return array
+   *   List of groupIds that represent the requested group and its parents
    */
   public static function getParentGroupIds($groupIds) {
     if (!is_array($groupIds)) {
@@ -617,10 +646,12 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
   /**
    * Returns array of group ids of descendent groups of the specified group.
    *
-   * @param             $groupIds               An array of valid group ids (passed by reference)
+   * @param array $groupIds
+   *   An array of valid group ids (passed by reference).
    *
    * @param bool $includeSelf
-   * @return array $groupIdArray         List of groupIds that represent the requested group and its descendents@access public
+   * @return array
+   *   List of groupIds that represent the requested group and its descendents
    */
   public static function getDescendentGroupIds($groupIds, $includeSelf = TRUE) {
     if (!is_array($groupIds)) {
@@ -650,10 +681,12 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
   /**
    * Returns array of descendent groups of the specified group.
    *
-   * @param             $groupIds     An array of valid group ids (passed by reference)
+   * @param array $groupIds
+   *   An array of valid group ids
    *
    * @param bool $includeSelf
-   * @return \An $groupArray   List of descendent groups@access public
+   * @return array
+   *   List of descendent groups
    */
   public static function getDescendentGroups($groupIds, $includeSelf = TRUE) {
     $groupIds = self::getDescendentGroupIds($groupIds, $includeSelf);
@@ -664,9 +697,11 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
   /**
    * Returns array of group ids of valid potential child groups of the specified group.
    *
-   * @param             $groupId              The group id to get valid potential children for
+   * @param $groupId
+   *   The group id to get valid potential children for.
    *
-   * @return array $groupIdArray         List of groupIds that represent the valid potential children of the group@access public
+   * @return array
+   *   List of groupIds that represent the valid potential children of the group
    */
   public static function getPotentialChildGroupIds($groupId) {
     $groups = CRM_Contact_BAO_Group::getGroups();
@@ -704,4 +739,5 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting implemen
 
     return $containingGroups;
   }
+
 }