Back to Category class

Method _getAssetParentId

protected int
_getAssetParentId
(\Joomla\CMS\Table\Table $table = null, mixed $id = null)
Get the parent asset id for the record
Parameters
  • \Joomla\CMS\Table\Table $table A Table object for the asset parent.
  • int $id The id for the asset
Returns
  • int The id of the asset's parent
Since
  • 1.6
Class: Category
Project: Joomla

Method _getAssetParentId - Source code

/**
 * Get the parent asset id for the record
 *
 * @param   Table    $table  A Table object for the asset parent.
 * @param   integer  $id     The id for the asset
 *
 * @return  integer  The id of the asset's parent
 *
 * @since   1.6
 */
protected function _getAssetParentId(Table $table = null, $id = null)
{
    $assetId = null;
    // This is a category under a category.
    if ($this->parent_id > 1) {
        // Build the query to get the asset id for the parent category.
        $query = $this->_db->getQuery(true)->select($this->_db->quoteName('asset_id'))->from($this->_db->quoteName('#__categories'))->where($this->_db->quoteName('id') . ' = :parentId')->bind(':parentId', $this->parent_id, ParameterType::INTEGER);
        // Get the asset id from the database.
        $this->_db->setQuery($query);
        if ($result = $this->_db->loadResult()) {
            $assetId = (int) $result;
        }
    } elseif ($assetId === null) {
        // Build the query to get the asset id for the parent category.
        $query = $this->_db->getQuery(true)->select($this->_db->quoteName('id'))->from($this->_db->quoteName('#__assets'))->where($this->_db->quoteName('name') . ' = :extension')->bind(':extension', $this->extension);
        // Get the asset id from the database.
        $this->_db->setQuery($query);
        if ($result = $this->_db->loadResult()) {
            $assetId = (int) $result;
        }
    }
    // Return the asset id.
    if ($assetId) {
        return $assetId;
    } else {
        return parent::_getAssetParentId($table, $id);
    }
}