Back to Access class

Method getAssetAncestors

protected static array
getAssetAncestors
(mixed $assetType, mixed $assetId)
Method to recursively retrieve the list of parent Asset IDs for a particular Asset.
Parameters
  • string $assetType The asset type, or the asset name, or the extension of the asset (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').
  • int $assetId The numeric asset id.
Returns
  • array List of ancestor ids (includes original $assetId).
Since
  • 1.6
Class: Access
Project: Joomla

Method getAssetAncestors - Source code

/**
 * Method to recursively retrieve the list of parent Asset IDs
 * for a particular Asset.
 *
 * @param   string   $assetType  The asset type, or the asset name, or the extension of the asset
 *                               (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').
 * @param   integer  $assetId    The numeric asset id.
 *
 * @return  array  List of ancestor ids (includes original $assetId).
 *
 * @since   1.6
 */
protected static function getAssetAncestors($assetType, $assetId)
{
    // Get the extension name from the $assetType provided
    $extensionName = self::getExtensionNameFromAsset($assetType);
    // Holds the list of ancestors for the Asset ID:
    $ancestors = array();
    // Add in our starting Asset ID:
    $ancestors[] = (int) $assetId;
    // Initialize the variable we'll use in the loop:
    $id = (int) $assetId;
    while ($id !== 0) {
        if (isset(self::$assetPermissionsParentIdMapping[$extensionName][$id])) {
            $id = (int) self::$assetPermissionsParentIdMapping[$extensionName][$id]->parent_id;
            if ($id !== 0) {
                $ancestors[] = $id;
            }
        } else {
            // Add additional case to break out of the while loop automatically in
            // the case that the ID is non-existent in our mapping variable above.
            break;
        }
    }
    return $ancestors;
}