PHP Class CategoryCollection, vanilla

This is a bridge class to aid in refactoring. This functionality will be rolled into the {@link CategoryModel}.
Show file Open project: vanilla/vanilla Class Usage Examples

Public Methods

Method Description
__construct ( Gdn_SQLDriver $sql = null, Gdn_Cache $cache = null ) Initialize a new instance of the {@link CategoryCollection} class.
flattenTree ( array $categories ) : array Flatten a tree that was returned from {@link getTree}.
flushCache ( ) Flush the entire category cache.
get ( integer $categoryID ) : array | null Lookup a category by either ID or slug.
getAncestors ( integer | string $categoryID, boolean $includeHeadings = false ) : array Get all of the ancestor categories above this one.
getByUrlCode ( string $code ) : array | null Lookup a category by its URL slug.
getChildren ( integer $categoryID ) : array Get the children of a category.
getConfig ( ) : Gdn_Configuration Get the config.
getMulti ( array $categoryIDs ) : array Get several categories by ID.
getStaticCalculator ( ) : callable Get the calculator.
getTree ( integer $parentID, array $options = [] ) : array Get all of the categories from a root.
getUserCalculator ( ) : callable Get the dynamic calculator.
insert ( array $category ) Insert a new category, handling its tree properties and caching.
refreshCache ( integer $categoryID ) : boolean Refresh a category in the cache from the database.
setConfig ( Gdn_Configuration $config ) : CategoryCollection Set the config.
setStaticCalculator ( callable $staticCalculator ) : CategoryCollection Set the calculator.
setUserCalculator ( callable $userCalculator ) : CategoryCollection Set the dynamic calculator.
update ( array $category ) : boolean Update an existing category, handling its tree properties and caching.

Private Methods

Method Description
cacheKey ( string $type, string | integer $id ) : string Generate a full cache key.
calculateDynamic ( &$category ) Calculate request-specific data on a category.
calculateStatic ( &$category ) Calculate static data on a category.
calculateTreeCounts ( array &$categories ) Calculate aggregate tree counts.
config ( string $key, mixed $default = null ) : mixed Get a value from the config.
defaultCalculator ( &$category ) Calculate dynamic data on a category.
flattenTreeInternal ( array $category, array &$result ) Internal implementation support for {@link CategoryCollection::flattenTree()}.
getCacheInc ( ) Get the cache increment.
getChildrenByParents ( array $parentIDs, string $permission = 'PermsDiscussionsView' ) : array Get all of the children of a parent category.
getSchema ( ) : Gdn_Schema Get the schema.

Method Details

__construct() public method

Initialize a new instance of the {@link CategoryCollection} class.
public __construct ( Gdn_SQLDriver $sql = null, Gdn_Cache $cache = null )
$sql Gdn_SQLDriver The database layer dependency.
$cache Gdn_Cache The cache layer dependency.

flattenTree() public method

Flatten a tree that was returned from {@link getTree}.
public flattenTree ( array $categories ) : array
$categories array The array of root categories.
return array Returns an array of categories.

flushCache() public method

Flush the entire category cache.
public flushCache ( )

get() public method

Lookup a category by either ID or slug.
public get ( integer $categoryID ) : array | null
$categoryID integer The category ID to get.
return array | null Returns a category or **null** if one isn't found.

getAncestors() public method

Get all of the ancestor categories above this one.
public getAncestors ( integer | string $categoryID, boolean $includeHeadings = false ) : array
$categoryID integer | string The category ID or url code.
$includeHeadings boolean Whether or not to include heading categories.
return array

getByUrlCode() public method

Lookup a category by its URL slug.
public getByUrlCode ( string $code ) : array | null
$code string The URL slug of the category.
return array | null Returns a category or **null** if one isn't found.

getChildren() public method

Get the children of a category.
public getChildren ( integer $categoryID ) : array
$categoryID integer The category to get the children for.
return array Returns an array of categories.

getConfig() public method

Get the config.
public getConfig ( ) : Gdn_Configuration
return Gdn_Configuration Returns the config.

getMulti() public method

Get several categories by ID.
public getMulti ( array $categoryIDs ) : array
$categoryIDs array An array of category IDs.
return array Returns an array of categories, indexed by ID.

getStaticCalculator() public method

Get the calculator.
public getStaticCalculator ( ) : callable
return callable Returns the calculator.

getTree() public method

Get all of the categories from a root.
public getTree ( integer $parentID, array $options = [] ) : array
$parentID integer The ID of the parent category.
$options array An array of options to affect the fetching. - maxdepth: The maximum depth of the tree. - collapsed: Stop when looking at a category of a certain type. - permission: The permission to use when looking at the tree.
return array

getUserCalculator() public method

Get the dynamic calculator.
public getUserCalculator ( ) : callable
return callable Returns the dynamicCalculator.

insert() public method

This method is currently only to to be used in a support role.
public insert ( array $category )
$category array The new category.

refreshCache() public method

This function is public for now, but should only be called from within the {@link CategoryModel}. Eventually it will be privatized.
public refreshCache ( integer $categoryID ) : boolean
$categoryID integer The category to refresh.
return boolean Returns **true** if the category was refreshed or **false** otherwise.

setConfig() public method

Set the config.
public setConfig ( Gdn_Configuration $config ) : CategoryCollection
$config Gdn_Configuration The config.
return CategoryCollection Returns `$this` for fluent calls.

setStaticCalculator() public method

Set the calculator.
public setStaticCalculator ( callable $staticCalculator ) : CategoryCollection
$staticCalculator callable The new calculator.
return CategoryCollection Returns `$this` for fluent calls.

setUserCalculator() public method

Set the dynamic calculator.
public setUserCalculator ( callable $userCalculator ) : CategoryCollection
$userCalculator callable The new dynamic calculator.
return CategoryCollection Returns `$this` for fluent calls.

update() public method

Update an existing category, handling its tree properties and caching.
public update ( array $category ) : boolean
$category array The category to update.
return boolean Returns **true** if the category updated or **false** otherwise.