PHP Класс CategoryModel, vanilla

Наследование: extends Model
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$Categories Merged Category data, including Pure + UserCategory.
$JoinRecentUsers Whether or not to join users to recent posts. Forums with a lot of categories may need to optimize using this setting and simpler views.
$ShardCache Whether or not to explicitly shard the categories cache.
$Watching boolean

Открытые методы

Метод Описание
__construct ( ) Class constructor. Defines the related database table name.
addCategoryColumns ( object $Data ) Modifies category data before it is returned.
allowedDiscussionTypes ( array $PermissionCategory, array $category = [] ) : array Checks the allowed discussion types on a category.
applyUpdates ( ) If looking at the root node, make sure it exists and that the nested set columns exist in the table.
calculateDisplayAs ( &$category ) Maintains backwards compatibilty with DisplayAs: Default-type categories by calculating the DisplayAs property into an expected DisplayAs type: Categories, Heading, or Discussions. Respects the now-deprecated config setting Vanilla.Categories.DoHeadings. Once we can be sure that all instances have their categories' DisplayAs properties explicitly set in the database (i.e., not Default) we can deprecate/remove this function.
categories ( integer | string | boolean $ID = false ) : array Gets either all of the categories or a single category.
categoryUrl ( $Category, string $Page = '', boolean | true $WithDomain = true ) : string Build URL to a category page.
categoryWatch ( $AllDiscussions = true ) : array
checkPermission ( array $category, string $permission ) : boolean Check a category's permission.
clearCache ( )
clearUserCache ( )
counts ( $Column ) : array
createCollection ( Gdn_SQLDriver $sql = null, Gdn_Cache $cache = null ) : CategoryCollection Create a new category collection tied to this model.
defaultCategory ( ) : mixed
delete ( $where = [], $options = [] ) Delete a category.
deleteAndReplace ( object $category, integer $newCategoryID ) Delete a single category and assign its discussions to another.
deleteID ( integer $categoryID, array $options = [] ) : boolean Delete a category.
filterCategoryPermissions ( array $categoryIDs ) : array Remove categories that a user does not have permission to view.
filterChildren ( array &$categories, string $childField = 'Children' ) Recursively remove children from categories configured to display as "Categories" or "Flat".
filterFollowing ( array $categories ) : array Filter a category tree to only the followed categories.
flattenTree ( array $categories ) : array Return a flattened version of a tree.
get ( string $OrderFields = '', string $OrderDirection = 'asc', integer $Limit = false, integer $Offset = false ) : Gdn_DataSet Get list of categories (respecting user permission).
getAll ( ) : object Get list of categories (disregarding user permission for admins).
getAncestors ( $categoryID, boolean $checkPermissions = true, boolean $includeHeadings = false ) : array Get all of the ancestor categories above this one.
getByCode ( $Code ) : object Get data for a single category selected by Url Code. Disregards permissions.
getByPermission ( string $Permission = 'Discussions.Add', null $CategoryID = null, array $Filter = [], array $PermFilter = [] ) : array
getChildTree ( integer | string $id, array $options = [] ) : array Get a category tree based on, but not including a parent category.
getChildren ( integer $categoryID ) Get the child categories of a category.
getDescendantCountByCode ( $Code ) Return the number of descendants for a specific category.
getDescendantsByCode ( string $Code ) : object
getDisplayAsOptions ( ) : array
getFiltered ( array $RestrictIDs = false, string $Permissions = false, array $ExcludeWhere = false ) : Gdn_DataSet Get a list of categories, considering several filters
getFull ( $CategoryID = false, $Permissions = false )
getFullByUrlCode ( string $UrlCode ) : object Get full data for a single category by its URL slug. Respects permissions.
getID ( integer $categoryID, string $datasetType = DATASET_TYPE_OBJECT, array $options = [] ) : object | array Get data for a single category selected by ID. Disregards permissions.
getMaxDisplayDepth ( ) : integer Get the maximum display depth for categories.
getNavDepth ( ) : integer Get the category nav depth.
getRolePermissions ( integer $categoryID ) : array Get the role specific permissions for a category.
getRootDisplayAs ( ) : string Get the display type for the root category.
getSubtree ( string $parentCategory, boolean $includeParent = true ) : array Get the subtree starting at a given parent.
getTreeAsFlat ( integer | string $id, integer | null $offset = null, integer | null $limit = null, string | null $filter = null, string $orderFields = 'Name', string $orderDirection = 'asc' ) : array
getWhereCache ( array $Where ) : array A simplified version of GetWhere that polls the cache instead of the database.
givePoints ( integer $UserID, integer $Points, string $Source = 'Other', integer $CategoryID, integer $Timestamp = false ) Give a user points specific to this category.
hasChildren ( string $CategoryID ) : boolean Check whether category has any children categories.
instance ( ) : CategoryModel The shared instance of this object.
joinCategories ( &$Data, string $Column = 'CategoryID', array $Options = [] )
joinModerators ( array $Data, string $Permission = 'Vanilla.Comments.Edit', string $Column = 'Moderators' )
joinRecent ( &$categoryTree ) Join recent posts and users to a category tree.
joinRecentChildPosts ( null &$Category = null, null &$Categories = null )
joinRecentPosts ( &$Data, null $CategoryID = null ) : boolean
joinUserCategory ( ) : boolean Whether or not to join information from GDN_UserCategory in {@link CategoryModel::calculateUser()}.
joinUserData ( &$Categories, boolean $AddUserCategory = true ) Add UserCategory modifiers
makeTree ( $Categories, null $Root = null ) : array
permissionCategory ( mixed $Category ) Return the category that contains the permissions for the given category.
rebuildTree ( boolean $BySort = false ) Rebuilds the category tree. We are using the Nested Set tree model.
recalculateTree ( ) Recalculate the dynamic tree columns in the category.
save ( $FormPostValues, array | false $Settings = false ) : integer Saves the category.
saveSubtree ( array $subtree, $parentID ) Save a subtree.
saveTree ( array $TreeArray ) Saves the category tree based on a provided tree array. We are using the Nested Set tree model.
saveUserTree ( integer $CategoryID, mixed $Set ) Grab the Category IDs of the tree.
setCache ( integer | boolean $ID = false, array | boolean $Data = false ) Grab and update the category cache
setField ( integer $ID, array | string $Property, boolean | false $Value = false ) : array | string Set a property on a category.
setJoinUserCategory ( boolean $joinUserCategory ) : CategoryModel Set whether or not to join information from GDN_UserCategory in {@link CategoryModel::calculateUser()}.
setLocalField ( $ID, $Property, $Value ) : boolean Set a property of a currently-loaded category in memory.
setRecentPost ( $CategoryID )
setStopHeadingsCalculation ( boolean $stopHeadingCalculation ) : CategoryModel Checks to see if the passed category depth is greater than the NavDepth and if so, stops calculating Headings as a DisplayAs property in the calculateDisplayAs method. Once we can be sure that all instances have their categories' DisplayAs properties explicitly set in the database (i.e., not Default) we can deprecate/remove this function.
where ( $Row, $Where ) : boolean

Защищенные методы

Метод Описание
_MakeTreeChildren ( $Category, $Categories, null $DepthAdj = null ) : array
_SetTree ( array &$Node, integer $Left = 1, integer $Depth )
_treeSort ( $A, $B ) : integer Utility method for sorting via usort.
buildCache ( integer $CategoryID = null ) Build and augment the category cache.
rebuildLock ( boolean $release = false ) : boolean Request rebuild mutex.

Приватные методы

Метод Описание
calculate ( &$category ) Calculate the dynamic fields of a category.
calculateData ( array &$Data ) Build calculated category data on the passed set.
calculateUser ( &$category, $addUserCategory = null ) Calculate the user-specific information on a category.
castID ( integer | string | null $category ) : integer | string | null Cast a category ID or slug to be passed to the various {@link CategoryCollection} methods.
gatherLastIDs ( array $categoryTree, &$result = null ) Gather all of the last discussion and comment IDs from the categories.
getOne ( string | integer $id ) Get a single category from the collection.
getUserCategories ( ) : array | mixed Get the per-category information for the current user.
joinRecentInternal ( &$categoryTree, array $discussions, array $comments ) This method supports {@link CategoryModel::joinRecent()}.
loadAllCategories ( ) Load all of the categories from the cache or the database.
saveSubtreeInternal ( array $subtree, integer | null $parentID = null, boolean $rebuild = true ) Save a subtree.

Описание методов

_MakeTreeChildren() защищенный статический Метод

protected static _MakeTreeChildren ( $Category, $Categories, null $DepthAdj = null ) : array
$Category
$Categories
$DepthAdj null
Результат array

_SetTree() защищенный Метод

С версии: 2.0.18
protected _SetTree ( array &$Node, integer $Left = 1, integer $Depth )
$Node array
$Left integer
$Depth integer

__construct() публичный Метод

Class constructor. Defines the related database table name.
С версии: 2.0.0
public __construct ( )

_treeSort() защищенный Метод

Utility method for sorting via usort.
С версии: 2.0.18
protected _treeSort ( $A, $B ) : integer
$A First element to compare.
$B Second element to compare.
Результат integer -1, 1, 0 (per usort)

addCategoryColumns() публичный статический Метод

Adds CountAllDiscussions column to each category representing the sum of discussions within this category as well as all subcategories.
С версии: 2.0.17
public static addCategoryColumns ( object $Data )
$Data object SQL result.

allowedDiscussionTypes() публичный статический Метод

Checks the allowed discussion types on a category.
public static allowedDiscussionTypes ( array $PermissionCategory, array $category = [] ) : array
$PermissionCategory array The permission category of the category.
$category array The category we're checking the permission on.
Результат array The allowed discussion types on the category.

applyUpdates() публичный Метод

If looking at the root node, make sure it exists and that the nested set columns exist in the table.
С версии: 2.0.15
public applyUpdates ( )

buildCache() защищенный статический Метод

Build and augment the category cache.
protected static buildCache ( integer $CategoryID = null )
$CategoryID integer The category to

calculateDisplayAs() публичный статический Метод

Maintains backwards compatibilty with DisplayAs: Default-type categories by calculating the DisplayAs property into an expected DisplayAs type: Categories, Heading, or Discussions. Respects the now-deprecated config setting Vanilla.Categories.DoHeadings. Once we can be sure that all instances have their categories' DisplayAs properties explicitly set in the database (i.e., not Default) we can deprecate/remove this function.
public static calculateDisplayAs ( &$category )
$category The category to calculate the DisplayAs property for.

categories() публичный статический Метод

Gets either all of the categories or a single category.
С версии: 2.0.18
public static categories ( integer | string | boolean $ID = false ) : array
$ID integer | string | boolean Either the category ID or the category url code. If nothing is passed then all categories are returned.
Результат array Returns either one or all categories.

categoryUrl() публичный статический Метод

Build URL to a category page.
public static categoryUrl ( $Category, string $Page = '', boolean | true $WithDomain = true ) : string
$Category
$Page string
$WithDomain boolean | true
Результат string

categoryWatch() публичный статический Метод

С версии: 2.0.18
public static categoryWatch ( $AllDiscussions = true ) : array
Результат array Category IDs.

checkPermission() публичный статический Метод

Check a category's permission.
public static checkPermission ( array $category, string $permission ) : boolean
$category array The category to check.
$permission string The permission name to check.
Результат boolean Returns **true** if the current user has the permission or **false** otherwise.

clearCache() публичный статический Метод

public static clearCache ( )

clearUserCache() публичный статический Метод

public static clearUserCache ( )

counts() публичный Метод

public counts ( $Column ) : array
$Column
Результат array

createCollection() публичный Метод

Create a new category collection tied to this model.
public createCollection ( Gdn_SQLDriver $sql = null, Gdn_Cache $cache = null ) : CategoryCollection
$sql Gdn_SQLDriver
$cache Gdn_Cache
Результат CategoryCollection Returns a new collection.

defaultCategory() публичный статический Метод

public static defaultCategory ( ) : mixed
Результат mixed

delete() публичный Метод

public delete ( $where = [], $options = [] )

deleteAndReplace() публичный Метод

Delete a single category and assign its discussions to another.
С версии: 2.0.0
public deleteAndReplace ( object $category, integer $newCategoryID )
$category object
$newCategoryID integer Unique ID of category all discussion are being move to.

deleteID() публичный Метод

Delete a category.
public deleteID ( integer $categoryID, array $options = [] ) : boolean
$categoryID integer The ID of the category to delete.
$options array An array of options to affect the behavior of the delete. - **newCategoryID**: The new category to point discussions to.
Результат boolean Returns **true** on success or **false** otherwise.

filterCategoryPermissions() публичный статический Метод

Remove categories that a user does not have permission to view.
public static filterCategoryPermissions ( array $categoryIDs ) : array
$categoryIDs array An array of categories to filter.
Результат array Returns an array of category IDs that are okay to view.

filterChildren() публичный статический Метод

Recursively remove children from categories configured to display as "Categories" or "Flat".
public static filterChildren ( array &$categories, string $childField = 'Children' )
$categories array
$childField string

filterFollowing() публичный Метод

Filter a category tree to only the followed categories.
public filterFollowing ( array $categories ) : array
$categories array The category tree to filter.
Результат array Returns a category tree.

flattenTree() публичный статический Метод

Return a flattened version of a tree.
public static flattenTree ( array $categories ) : array
$categories array The category tree.
Результат array Returns the flattened category tree.

get() публичный Метод

Get list of categories (respecting user permission).
С версии: 2.0.0
public get ( string $OrderFields = '', string $OrderDirection = 'asc', integer $Limit = false, integer $Offset = false ) : Gdn_DataSet
$OrderFields string Ignored.
$OrderDirection string Ignored.
$Limit integer Ignored.
$Offset integer Ignored.
Результат Gdn_DataSet SQL results.

getAll() публичный Метод

Get list of categories (disregarding user permission for admins).
С версии: 2.0.0
public getAll ( ) : object
Результат object SQL results.

getAncestors() публичный статический Метод

Get all of the ancestor categories above this one.
public static getAncestors ( $categoryID, boolean $checkPermissions = true, boolean $includeHeadings = false ) : array
$checkPermissions boolean Whether or not to only return the categories with view permission.
$includeHeadings boolean Whether or not to include heading categories.
Результат array

getByCode() публичный Метод

Get data for a single category selected by Url Code. Disregards permissions.
С версии: 2.0.0
public getByCode ( $Code ) : object
Результат object SQL results.

getByPermission() публичный статический Метод

public static getByPermission ( string $Permission = 'Discussions.Add', null $CategoryID = null, array $Filter = [], array $PermFilter = [] ) : array
$Permission string
$CategoryID null
$Filter array
$PermFilter array
Результат array

getChildTree() публичный Метод

Get a category tree based on, but not including a parent category.
public getChildTree ( integer | string $id, array $options = [] ) : array
$id integer | string The parent category ID or slug.
$options array See {@link CategoryCollection::getTree()}.
Результат array Returns an array of categories with child categories in the **Children** key.

getChildren() публичный статический Метод

Get the child categories of a category.
public static getChildren ( integer $categoryID )
$categoryID integer The category to get the children of.

getDescendantCountByCode() публичный Метод

Return the number of descendants for a specific category.
public getDescendantCountByCode ( $Code )

getDescendantsByCode() публичный Метод

С версии: 2.0.18
public getDescendantsByCode ( string $Code ) : object
$Code string Where condition.
Результат object DataSet

getDisplayAsOptions() публичный статический Метод

public static getDisplayAsOptions ( ) : array
Результат array

getFiltered() публичный Метод

Get a list of categories, considering several filters
public getFiltered ( array $RestrictIDs = false, string $Permissions = false, array $ExcludeWhere = false ) : Gdn_DataSet
$RestrictIDs array Optional list of category ids to mask the dataset
$Permissions string Optional permission to require. Defaults to Vanilla.Discussions.View.
$ExcludeWhere array Exclude categories with any of these flags
Результат Gdn_DataSet

getFull() публичный Метод

public getFull ( $CategoryID = false, $Permissions = false )

getFullByUrlCode() публичный Метод

Get full data for a single category by its URL slug. Respects permissions.
С версии: 2.0.0
public getFullByUrlCode ( string $UrlCode ) : object
$UrlCode string Unique category slug from URL.
Результат object SQL results.

getID() публичный Метод

Get data for a single category selected by ID. Disregards permissions.
С версии: 2.0.0
public getID ( integer $categoryID, string $datasetType = DATASET_TYPE_OBJECT, array $options = [] ) : object | array
$categoryID integer The unique ID of category we're getting data for.
$datasetType string Not used.
$options array Not used.
Результат object | array SQL results.

getMaxDisplayDepth() публичный Метод

Get the maximum display depth for categories.
public getMaxDisplayDepth ( ) : integer
Результат integer Returns the display depth as an integer.

getNavDepth() публичный Метод

Get the category nav depth.
public getNavDepth ( ) : integer
Результат integer Returns the nav depth as an integer.

getRolePermissions() публичный Метод

Get the role specific permissions for a category.
public getRolePermissions ( integer $categoryID ) : array
$categoryID integer The ID of the category to get the permissions for.
Результат array Returns an array of permissions.

getRootDisplayAs() публичный статический Метод

Get the display type for the root category.
public static getRootDisplayAs ( ) : string
Результат string

getSubtree() публичный статический Метод

Get the subtree starting at a given parent.
С версии: 2.0.18
public static getSubtree ( string $parentCategory, boolean $includeParent = true ) : array
$parentCategory string The ID or url code of the parent category.
$includeParent boolean Whether or not to include the parent in the result.
Результат array An array of categories.

getTreeAsFlat() публичный Метод

public getTreeAsFlat ( integer | string $id, integer | null $offset = null, integer | null $limit = null, string | null $filter = null, string $orderFields = 'Name', string $orderDirection = 'asc' ) : array
$id integer | string The parent category ID or slug.
$offset integer | null Offset results by given value.
$limit integer | null Total number of results should not exceed this value.
$filter string | null Restrict results to only those with names matching this value, if provided.
$orderFields string
$orderDirection string
Результат array

getWhereCache() публичный Метод

A simplified version of GetWhere that polls the cache instead of the database.
С версии: 2.2.2
public getWhereCache ( array $Where ) : array
$Where array
Результат array

givePoints() публичный статический Метод

Give a user points specific to this category.
public static givePoints ( integer $UserID, integer $Points, string $Source = 'Other', integer $CategoryID, integer $Timestamp = false )
$UserID integer The user to give the points to.
$Points integer The number of points to give.
$Source string The source of the points.
$CategoryID integer The category to give the points for.
$Timestamp integer The time the points were given.

hasChildren() публичный Метод

Check whether category has any children categories.
С версии: 2.0.0
public hasChildren ( string $CategoryID ) : boolean
$CategoryID string Unique ID for category being checked.
Результат boolean

instance() публичный статический Метод

The shared instance of this object.
public static instance ( ) : CategoryModel
Результат CategoryModel Returns the instance.

joinCategories() публичный статический Метод

С версии: 2.0.18
public static joinCategories ( &$Data, string $Column = 'CategoryID', array $Options = [] )
$Column string Name of database column.
$Options array The 'Join' key may contain array of columns to join on.

joinModerators() публичный статический Метод

С версии: 2.0.0
public static joinModerators ( array $Data, string $Permission = 'Vanilla.Comments.Edit', string $Column = 'Moderators' )
$Data array
$Permission string
$Column string

joinRecent() публичный Метод

Join recent posts and users to a category tree.
public joinRecent ( &$categoryTree )

joinRecentChildPosts() публичный статический Метод

public static joinRecentChildPosts ( null &$Category = null, null &$Categories = null )
$Category null
$Categories null

joinRecentPosts() публичный статический Метод

public static joinRecentPosts ( &$Data, null $CategoryID = null ) : boolean
$Data
$CategoryID null
Результат boolean

joinUserCategory() публичный Метод

You only need the information from this table when looking at categories in a list. Controllers should set this flag if they are going to be sending read/unread information with the category.
public joinUserCategory ( ) : boolean
Результат boolean Returns the joinUserCategory.

joinUserData() публичный статический Метод

Update &$Categories in memory by applying modifiers from UserCategory for the currently logged-in user.
С версии: 2.0.18
public static joinUserData ( &$Categories, boolean $AddUserCategory = true )
$AddUserCategory boolean

makeTree() публичный статический Метод

public static makeTree ( $Categories, null $Root = null ) : array
$Categories
$Root null
Результат array

permissionCategory() публичный статический Метод

Return the category that contains the permissions for the given category.
С версии: 2.2
public static permissionCategory ( mixed $Category )
$Category mixed

rebuildLock() защищенный статический Метод

Allows competing instances to "vote" on the process that gets to rebuild the category cache.
protected static rebuildLock ( boolean $release = false ) : boolean
$release boolean
Результат boolean whether we may rebuild

rebuildTree() публичный Метод

Rebuilds the category tree. We are using the Nested Set tree model.
С версии: 2.0.0
public rebuildTree ( boolean $BySort = false )
$BySort boolean Rebuild the tree by sort order instead of existing tree order.

recalculateTree() публичный Метод

Recalculate the dynamic tree columns in the category.
public recalculateTree ( )

save() публичный Метод

Saves the category.
С версии: 2.0.0
public save ( $FormPostValues, array | false $Settings = false ) : integer
$Settings array | false Additional settings to affect saving.
Результат integer ID of the saved category.

saveSubtree() публичный Метод

Save a subtree.
public saveSubtree ( array $subtree, $parentID )
$subtree array A nested array where each array contains a CategoryID and optional Children element.

saveTree() публичный Метод

TreeArray comes in the format: '0' ... 'item_id' => "root" 'parent_id' => "none" 'depth' => "0" 'left' => "1" 'right' => "34" '1' ... 'item_id' => "1" 'parent_id' => "root" 'depth' => "1" 'left' => "2" 'right' => "3" etc...
С версии: 2.0.16
public saveTree ( array $TreeArray )
$TreeArray array A fully defined nested set model of the category tree.

saveUserTree() публичный Метод

Grab the Category IDs of the tree.
С версии: 2.0.18
public saveUserTree ( integer $CategoryID, mixed $Set )
$CategoryID integer
$Set mixed

setCache() публичный статический Метод

Grab and update the category cache
С версии: 2.0.18
public static setCache ( integer | boolean $ID = false, array | boolean $Data = false )
$ID integer | boolean
$Data array | boolean

setField() публичный Метод

Set a property on a category.
public setField ( integer $ID, array | string $Property, boolean | false $Value = false ) : array | string
$ID integer
$Property array | string
$Value boolean | false
Результат array | string

setJoinUserCategory() публичный Метод

Set whether or not to join information from GDN_UserCategory in {@link CategoryModel::calculateUser()}.
public setJoinUserCategory ( boolean $joinUserCategory ) : CategoryModel
$joinUserCategory boolean The new value to set.
Результат CategoryModel Returns `$this` for fluent calls.

setLocalField() публичный статический Метод

Set a property of a currently-loaded category in memory.
public static setLocalField ( $ID, $Property, $Value ) : boolean
$ID
$Property
$Value
Результат boolean

setRecentPost() публичный Метод

public setRecentPost ( $CategoryID )
$CategoryID

setStopHeadingsCalculation() публичный Метод

Checks to see if the passed category depth is greater than the NavDepth and if so, stops calculating Headings as a DisplayAs property in the calculateDisplayAs method. Once we can be sure that all instances have their categories' DisplayAs properties explicitly set in the database (i.e., not Default) we can deprecate/remove this function.
public setStopHeadingsCalculation ( boolean $stopHeadingCalculation ) : CategoryModel
$stopHeadingCalculation boolean
Результат CategoryModel

where() публичный статический Метод

public static where ( $Row, $Where ) : boolean
$Row
$Where
Результат boolean

Описание свойств

$Categories публичное статическое свойство

Merged Category data, including Pure + UserCategory.
public static $Categories

$JoinRecentUsers публичное свойство

Whether or not to join users to recent posts. Forums with a lot of categories may need to optimize using this setting and simpler views.
public $JoinRecentUsers

$ShardCache публичное статическое свойство

Whether or not to explicitly shard the categories cache.
public static $ShardCache

$Watching публичное свойство

public bool $Watching
Результат boolean