applications/vanilla/models/class.categorymodel.php
public static function GetAncestors($CategoryID, $CheckPermissions = TRUE) {
      $Categories = self::Categories();
      $Result = array();
      
      // Grab the category by ID or url code.
      if (is_numeric($CategoryID)) {
         if (isset($Categories[$CategoryID]))
            $Category = $Categories[$CategoryID];
      } else {
         foreach ($Categories as $ID => $Value) {
            if ($Value['UrlCode'] == $CategoryID) {
               $Category = $Categories[$ID];
               break;
            }
         }
      }

      if (!isset($Category))
         return $Result;

      // Build up the ancestor array by tracing back through parents.
      $Result[$Category['CategoryID']] = $Category;
      $Max = 20;
      while (isset($Categories[$Category['ParentCategoryID']])) {
         // Check for an infinite loop.
         if ($Max <= 0)
            break;
         $Max--;
         
         if ($CheckPermissions && !$Category['PermsDiscussionsView']) {
            $Category = $Categories[$Category['ParentCategoryID']];
            continue;
         }
         
         if ($Category['CategoryID'] == -1)
            break;

         // Return by ID or code.
         if (is_numeric($CategoryID))
            $ID = $Category['CategoryID'];
         else
            $ID = $Category['UrlCode'];

         $Result[$ID] = $Category;

         $Category = $Categories[$Category['ParentCategoryID']];
      }
      $Result = array_reverse($Result, TRUE); // order for breadcrumbs
      return $Result;
   }
public static function GetAncestors($CategoryID, $CheckPermissions = TRUE) {
      $Categories = self::Categories();
      $Result = array();
      
      // Grab the category by ID or url code.
      if (is_numeric($CategoryID)) {
         if (isset($Categories[$CategoryID]))
            $Category = $Categories[$CategoryID];
      } else {
         foreach ($Categories as $ID => $Value) {
            if ($Value['UrlCode'] == $CategoryID) {
               $Category = $Categories[$ID];
               break;
            }
         }
      }

      if (!isset($Category))
         return $Result;

      // Build up the ancestor array by tracing back through parents.
      $Result[$Category['CategoryID']] = $Category;
      $Max = 20;
      while (isset($Categories[$Category['ParentCategoryID']])) {
         // Check for an infinite loop.
         if ($Max <= 0)
            break;
         $Max--;
         
         if ($CheckPermissions && !$Category['PermsDiscussionsView']) {
            $Category = $Categories[$Category['ParentCategoryID']];
            continue;
         }
         
         if ($Category['CategoryID'] == -1)
            break;

         // Return by ID or code.
         if (is_numeric($CategoryID))
            $ID = $Category['CategoryID'];
         else
            $ID = $Category['UrlCode'];

         $Result[$ID] = $Category;

         $Category = $Categories[$Category['ParentCategoryID']];
      }
      $Result = array_reverse($Result, TRUE); // order for breadcrumbs
      return $Result;
   }
public static function GetAncestors ( $ CategoryID , $ CheckPermissions = TRUE ) { $ Categories = self :: Categories ( ) ; $ Result = array ( ) ; // Grab the category by ID or url code. if ( is_numeric ( $ CategoryID ) ) { if ( isset ( $ Categories [ $ CategoryID ] ) ) $ Category = $ Categories [ $ CategoryID ] ; } else { foreach ( $ Categories as $ ID => $ Value ) { if ( $ Value [ 'UrlCode' ] == $ CategoryID ) { $ Category = $ Categories [ $ ID ] ; break ; } } } if ( ! isset ( $ Category ) ) return $ Result ; // Build up the ancestor array by tracing back through parents. $ Result [ $ Category [ 'CategoryID' ] ] = $ Category ; $ Max = 20 ; while ( isset ( $ Categories [ $ Category [ 'ParentCategoryID' ] ] ) ) { // Check for an infinite loop. if ( $ Max <= 0 ) break ; $ Max -- ; if ( $ CheckPermissions && ! $ Category [ 'PermsDiscussionsView' ] ) { $ Category = $ Categories [ $ Category [ 'ParentCategoryID' ] ] ; continue ; } if ( $ Category [ 'CategoryID' ] == - 1 ) break ; // Return by ID or code. if ( is_numeric ( $ CategoryID ) ) $ ID = $ Category [ 'CategoryID' ] ; else $ ID = $ Category [ 'UrlCode' ] ; $ Result [ $ ID ] = $ Category ; $ Category = $ Categories [ $ Category [ 'ParentCategoryID' ] ] ; } $ Result = array_reverse ( $ Result , TRUE ) ; // order for breadcrumbs return $ Result ; }
Get all of the ancestor categories above this one.
@param int|string $Category The category ID or url code.
@param bool $CheckPermissions Whether or not to only return the categories with view permission.
@return array
Get all of the ancestor categories above this one .