Back to Access class

Method preloadPermissions

protected static void
preloadPermissions
(mixed $assetType, mixed $reload = false)
Method to retrieve the Asset Rule strings for this particular Asset Type and stores them for later usage in getAssetRules().
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').
  • bool $reload Reload the preloaded assets.
Returns
  • void
Since
  • 1.6
Class: Access
Project: Joomla

Method preloadPermissions - Source code

/**
 * Method to retrieve the Asset Rule strings for this particular
 * Asset Type and stores them for later usage in getAssetRules().
 * Stores 2 arrays: one where the list has the Asset ID as the key
 * and a second one where the Asset Name is the key.
 *
 * @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   boolean  $reload     Reload the preloaded assets.
 *
 * @return  void
 *
 * @since   1.6
 */
protected static function preloadPermissions($assetType, $reload = false)
{
    // Get the extension name from the $assetType provided
    $extensionName = self::getExtensionNameFromAsset($assetType);
    // If asset is a component, make sure that all the component assets are preloaded.
    if ((isset(self::$preloadedAssetTypes[$extensionName]) || isset(self::$preloadedAssetTypes[$assetType])) && !$reload) {
        return;
    }
    !JDEBUG ?: Profiler::getInstance('Application')->mark('Before Access::preloadPermissions (' . $extensionName . ')');
    // Get the database connection object.
    $db = Factory::getDbo();
    $assetKey = $extensionName . '.%';
    // Get a fresh query object.
    $query = $db->getQuery(true)->select($db->quoteName(array('id', 'name', 'rules', 'parent_id')))->from($db->quoteName('#__assets'))->where([$db->quoteName('name') . ' LIKE :asset', $db->quoteName('name') . ' = :extension', $db->quoteName('parent_id') . ' = 0'], 'OR')->bind(':extension', $extensionName)->bind(':asset', $assetKey);
    // Get the permission map for all assets in the asset extension.
    $assets = $db->setQuery($query)->loadObjectList();
    self::$assetPermissionsParentIdMapping[$extensionName] = array();
    foreach ($assets as $asset) {
        self::$assetPermissionsParentIdMapping[$extensionName][$asset->id] = $asset;
        self::$preloadedAssets[$asset->id] = $asset->name;
    }
    // Mark asset type and it's extension name as preloaded.
    self::$preloadedAssetTypes[$assetType] = true;
    self::$preloadedAssetTypes[$extensionName] = true;
    !JDEBUG ?: Profiler::getInstance('Application')->mark('After Access::preloadPermissions (' . $extensionName . ')');
}