PHP 클래스 CategoryModel, vanilla

상속: extends Model
파일 보기 프로젝트 열기: vanilla/vanilla 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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