Base class for models.

Models don't share that much, so most implementations will be adding methods onto this class. This class simply provides helper methods for common actions.

package XenForo_Mvc

 Methods

Constructor.

__construct() 
Inherited

Use create() statically unless you know what you're doing.

inherited_from \XenForo_Model::__construct()

Adds a join to the set of fetch options.

addFetchOptionJoin(array $fetchOptions, integer $join) 
Inherited

Join should be one of the constants.

inherited_from \XenForo_Model::addFetchOptionJoin()

Parameters

$fetchOptions

array

$join

integer

Adds the equivalent of a limit clause using position-based limits.

addPositionLimit(string $table, integer $limit, integer $offset, string $column) : string
Inherited

It no limit value is specified, nothing will be returned.

This must be added within a WHERE clause. If a clause is required, it will begin with "AND", so ensure there is a condition before it.

inherited_from \XenForo_Model::addPositionLimit()

Parameters

$table

string

Name of the table alias to prefix. May be blank for no table reference.

$limit

integer

Number of records to limit to; ignored if <= 0

$offset

integer

Offset from the start of the records. 0+

$column

string

Name of the column that is storing the position

Returns

stringPosition limit clause if needed

Ensures that a valid cut-off operator is passed.

assertValidCutOffOperator(string $operator) 
Inherited
inherited_from \XenForo_Model::assertValidCutOffOperator()

Parameters

$operator

string

Factory method to get the named model.

create(string $class) : \XenForo_Model
InheritedStatic

The class must exist or be autoloadable or an exception will be thrown.

inherited_from \XenForo_Model::create()

Parameters

$class

string

Class to load

Returns

Deletes all child nodes of the specified parent node

deleteChildNodes(mixed $parentNode, boolean $rebuildCaches) : null

Parameters

$parentNode

mixed

Parent node: Either node array or node id

$rebuildCaches

boolean

Rebuild caches afterwards

Returns

null

Fetches results from the database with each row keyed according to preference.

fetchAllKeyed(string $sql, string $key, mixed $bind, string $nullPrefix) : array
Inherited

The 'key' parameter provides the column name with which to key the result. For example, calling fetchAllKeyed('SELECT item_id, title, date FROM table', 'item_id') would result in an array keyed by item_id: [$itemId] => array('item_id' => $itemId, 'title' => $title, 'date' => $date)

Note that the specified key must exist in the query result, or it will be ignored.

inherited_from \XenForo_Model::fetchAllKeyed()

Parameters

$sql

string

SQL to execute

$key

string

Column with which to key the results array

$bind

mixed

Parameters for the SQL

$nullPrefix

string

If the key is null, prefix the counter with this

Returns

array

Filters a set of grouped node data to only include nodes up to a certain depth from the specified root node.

filterGroupedNodesToDepth(integer $parentNodeId, array $groupedNodes, integer $depth) : array

Parameters

$parentNodeId

integer

Root of the sub-tree or the whole tree (0)

$groupedNodes

array

Nodes, grouped by parent: [parent node id][node id] => info

$depth

integer

Depth to filter to; should be at least 1

Returns

arrayFiltered, grouped nodes

Filters a tree of nodes to show only the specified node types and their children.

filterNodeTypesInTree(array $nodes, array $nodeTypes) : array

Children of an excluded node type will be removed, even if they are an included type.

Parameters

$nodes

array

Flattened, ordered node tree in order (by lft). Must include depth and node_type_id. Keyed by ID.

$nodeTypes

[Category, Forum, ... ] or [Category => 1, Forum => 1,...]

Returns

array

Filters orphaned nodes out of a list.

filterOrphanNodes(array $nodes) : array

Note the caveats: * The list must be in lft order * The nodes must be keyed by their ID

Parameters

$nodes

array

Returns

array

Gets an array of all node types from the DB

getAllNodeTypes() : array

Returns

arrayFormat: [node type id] => type info

Gets an array of all node types from the DB

getAllNodeTypesFromDb() : array

Returns

arrayFormat: [node type id] => type info

Gets all nodes from the database

getAllNodes(boolean $ignoreNestedSetOrdering, boolean $listView) : array

Parameters

$ignoreNestedSetOrdering

boolean

If true, ignore nested set infor for ordering and use display_order instead

$listView

boolean

If true, only includes nodes viewable in list

Returns

array

Gets an array of all nodes that are decendents of the specified node

getChildNodes(array $node, boolean $listView) : mixed

Parameters

$node

array

$listView

boolean

If true, only nodes that are visible in the list view are included

Returns

mixed

Gets all child nodes for each node ID.

getChildNodesForNodeIds(array $nodeIds) : array

The child nodes are not grouped.

Parameters

$nodeIds

array

Returns

arrayChild nodes, [node id] => node

Gets an array of all nodes that are decendents of the specified node up to $depth levels of nesting

getChildNodesToDepth(array $node, integer $depth, boolean $listView) : mixed

Parameters

$node

array

$depth

integer

$listView

boolean

If true, only nodes that are visible in the list view are included

Returns

mixed

Gets a list of SQL conditions in the format for a clause.

getConditionsForClause(array $sqlConditions) : string
Inherited

This always returns a value that can be used in a clause such as WHERE.

inherited_from \XenForo_Model::getConditionsForClause()

Parameters

$sqlConditions

array

Returns

string

Gets the specified field from a content type, if specified for that type.

getContentTypeField(string $contentType, string $fieldName) : string | false
Inherited
inherited_from \XenForo_Model::getContentTypeField()

Parameters

$contentType

string

$fieldName

string

Returns

stringfalse

Gets the value of the specified field for each content type that has that field.

getContentTypesWithField(string $fieldName) : array
Inherited
inherited_from \XenForo_Model::getContentTypesWithField()

Parameters

$fieldName

string

Returns

arrayFormat: [content type] => field value

Gets the specified model object from the cache.

getModelFromCache(string $class) : \XenForo_Model
Inherited

If it does not exist, it will be instantiated.

inherited_from \XenForo_Model::getModelFromCache()

Parameters

$class

string

Name of the class to load

Returns

Builds lft, rgt and depth values for all nodes, based on the parent_node_id and display_order information in the database.

getNewNestedSetInfo(array | null $nodeHierarchy, integer $parentNodeId, integer $depth, integer $lft, integer $effectiveStyleId) : array

Also rebuilds the effective style ID.

Parameters

$nodeHierarchy

arraynull
  • will be fetched automatically when NULL is provided

$parentNodeId

integer

$depth

integer

$lft

integer

The entry left value; note that this will be changed and returned as the rgt value

$effectiveStyleId

integer

The effective style ID from the parent

Returns

array[node_id] => array(lft => int, rgt => int)...

Get all ancestors for the given node, from the root of the tree down the the node's direct parent.

getNodeAncestors(array $node) : array

Parameters

$node

array

Returns

arrayList of ancestor nodes, from root down; format: [node id] => info

Gets the bread crumb nodes for the specified node.

getNodeBreadCrumbs(array $node, boolean $includeSelf) : array

Parameters

$node

array

$includeSelf

boolean

If true, includes itself as the last entry

Returns

arrayList of nodes that form bread crumbs, root down; [node id] => node info

Gets a single node record specified by its ID

getNodeById(integer $nodeId, array $fetchOptions) : array

Parameters

$nodeId

integer

node_id

$fetchOptions

Returns

arrayNode

Gets a node of the specified type that has a given name.

getNodeByName(string $nodeName, string $nodeTypeId, array $fetchOptions) : array | false

Parameters

$nodeName

string

$nodeTypeId

string

$fetchOptions

array

Returns

arrayfalse

Gets all the node data required for a node list display (eg, a forum list) from a given point.

getNodeDataForListDisplay(array | false $parentNode, integer $displayDepth, array $nodePermissions) : array

Returns 3 pieces of data: * nodesGrouped - nodes, grouped by parent, with all data integrated * nodeHandlers - list of node handlers by node type * nodePermissions - the node permissions passed on

Parameters

$parentNode

arrayfalse

Root node of the tree to display from; false for the entire tree

$displayDepth

integer

Number of levels of nodes to display below the root, 0 for all

$nodePermissions

arraynull

List of node permissions, [node id] => permissions; if null, get's current visitor's permissions

Returns

arrayEmpty, or with keys: nodesGrouped, parentNodeId, nodeHandlers, nodePermissions

Gets a node handler object for each node type in the list.

getNodeHandlersForNodeTypes(array $nodeTypeIds) : array

Parameters

$nodeTypeIds

array

List of node type IDs

Returns

arrayFormat: [node type id] => node handler object

Gets an array representing the node hierarchy that can be traversed recursively Format: item[parent_id][node_id] = node

getNodeHierarchy(array | null $nodes) : array

Parameters

$nodes

arraynull

Node list from getAllNodes()

Returns

arrayNode hierarchy

Get an array of node_ids from the specified array of node_names

getNodeIdsFromNames(array $nodeNames) : array

Parameters

$nodeNames

array

Node names

Returns

array[node_name] => node_id

Fetches an array suitable as source for admin template 'options' tag from nodes array

getNodeOptionsArray(array $nodes, integer $selectedNodeId, mixed $includeRoot) : array

Parameters

$nodes

array

Array of nodes, including node_id, title, parent_node_id and depth keys

$selectedNodeId

integer

NodeId of selected node

$includeRoot

mixed

Add root as the first option, and increment all depths by 1 to show indenting. If 'true', the root node will be entitled '(root node)', alternatively, specify a string to use as the option text.

Returns

array

Gets all the node permissions for a given permission combination ID.

getNodePermissionsForPermissionCombination(integer | null $permissionCombinationId) : array

Parameters

$permissionCombinationId

integernull

If null, uses current visitor permissions

Returns

array

Gets item counts across all nodes (or all nodes in a sub-tree).

getNodeTotalItemCounts(array $parentNode) : array

This does not respect permissions.

Parameters

$parentNode

arrayfalse

Returns

arrayKeys: discussions, messages

Fetch all information for the specified node type

getNodeTypeById(string $nodeTypeId) : array

Parameters

$nodeTypeId

string

node_type_id

Returns

array

Fetches all information for the node type attached to a particular node

getNodeTypeByNodeId(integer $nodeId) : \arrayf

Parameters

$nodeId

integer

Returns

\arrayf

Gets the human-readable name of the node type specified by its id

getNodeTypeNameById(string $nodeTypeId) : string

Parameters

$nodeTypeId

string

Returns

string

Returns a list of node type names for use in <xen:option> tags

getNodeTypeOptionsArray(array $nodes) : array

Parameters

$nodes

array

Array of nodes including node_type_id key

Returns

array

Gets all node types, grouped by their permission group.

getNodeTypesGroupedByPermissionGroup() : array

Returns

arrayFormat: [permission group id][node type id] => node type info

Return results for admin quick search

getNodesForAdminQuickSearch(string $searchText) : array

Parameters

$searchText

string

Keywords for which to search

Returns

array

Gets all nodes up to a specified depth from the root of the tree.

getNodesToDepthFromRoot(integer $depth) : array

Parameters

$depth

integer

Returns

arrayFormat: [node id] => node info

Gets the order by clause for an SQL query.

getOrderByClause(array $choices, array $fetchOptions, string $defaultOrderSql) : string
Inherited
inherited_from \XenForo_Model::getOrderByClause()

Parameters

$choices

array

$fetchOptions

array

$defaultOrderSql

string

Returns

stringOrder by clause or empty string

Gets an array of all nodes that are not decendents of the specified node

getPossibleParentNodes(array $node) : array

Parameters

$node

array

Node

Returns

arrayNodes

Fetches a representation of the root node to be merged into an array of other nodes

getRootNode() : array

Returns

array

Gets all nodes that are siblings of this node

getSiblingNodes(array $node, boolean $includeSelf, boolean $listView) : array

Parameters

$node

array

$includeSelf

boolean

$listView

boolean

If true, only includes nodes viewable in list

Returns

array

Gets a unique list of node type IDs from a list of ungrouped nodes.

getUniqueNodeTypeIdsFromNodeList(array $nodes) : array

Parameters

$nodes

array

Returns

arrayList of node type IDs

Get a list of all nodes that are viewable.

getViewableNodeList(array $nodePermissions, boolean $listView) : array

Parameters

$nodePermissions

arraynull

List of node permissions, [node id] => permissions; if null, get's current visitor's permissions

$listView

boolean

Get nodes in list mode (respect display_in_list option for each node)

Returns

arrayList of viewable nodes: [node id] => info, ordered by lft

Gets the viewable nodes from a list of nodes.

getViewableNodesFromNodeList(array $nodes, array $nodeHandlers, array $nodePermissions) : array

Parameters

$nodes

array

Format: [node id] => info

$nodeHandlers

array

List of node handlers

$nodePermissions

array

Node permissions, [node id] => permissions

Returns

arrayList of nodes, [node id] => info

Groups a list of nodes by their parent node ID.

groupNodesByParent(array $nodes) : array

This allows for easier recursive traversal.

Parameters

$nodes

array

Format: [node id] => info

Returns

arrayFormat: [parent node id][node id] => info

If the specified node has a lft-rgt difference of more than 1, it must have child nodes.

hasChildNodes(array $node) : boolean

Parameters

$node

array

Node must include lft and rgt keys

Returns

boolean

Applies a limit clause to the provided query if a limit value is specified.

limitQueryResults(string $query, integer $limit, integer $offset) : string
Inherited

If the limit value is 0 or less, no clause is applied.

inherited_from \XenForo_Model::limitQueryResults()

Parameters

$query

string

SQL query to run

$limit

integer

Number of records to limit to; ignored if <= 0

$offset

integer

Offset from the start of the records. 0+

Returns

stringQuery with limit applied if necessary

Merges extra, node-specific data into a list of nodes.

mergeExtraNodeDataIntoNodeList(array $nodes, array $nodeHandlers) : array

Parameters

$nodes

array

List of nodes, [node id] => info

$nodeHandlers

array

List of node handlers

Returns

arrayNode list with extra data merged in

Merges pushable node data into a grouped node list and returns all the pushed data from this level.

mergePushableNodeData(integer $parentNodeId, array $groupedNodes, array $nodeHandlers, array $nodePermissions) : array

Parameters

$parentNodeId

integer

Parent node, all children traversed

$groupedNodes

array

List of grouped nodes. This will be modified by ref!

$nodeHandlers

array

List of node handlers

$nodePermissions

array

List of node permissions

Returns

arrayPushed data for the nodes traversed at this level; [node id] => pushed data

Moves all child nodes from one parent to another

moveChildNodes(mixed $fromNode, mixed $toNode, boolean $rebuildCaches) : null

Parameters

$fromNode

mixed

Source node: Either node array or node id

$toNode

mixed

Destination node: Either node array or node id

$rebuildCaches

boolean

Rebuild caches afterwards

Returns

null

Prepares the limit-related fetching options that can be applied to various queries.

prepareLimitFetchOptions(array $fetchOptions) : array
Inherited

Includes: limit, offset, page, and perPage.

inherited_from \XenForo_Model::prepareLimitFetchOptions()

Parameters

$fetchOptions

array

Unprepared options

Returns

arrayLimit options; keys: limit, offset

Prepares the raw data of a node into human-readable information for use in the admin area.

prepareNodeForAdmin(array $node) : array

Parameters

$node

array

Raw node data

Returns

arrayPrepared node

Calls prepareNodeForAdmin() on each member of the input array

prepareNodesForAdmin(array $nodes) : array

Parameters

$nodes

array

Raw nodes

Returns

arrayPrepared nodes

Prepare nodes using the type-specific handlers.

prepareNodesWithHandlers(array $nodes, array $nodeHandlers) : array

Parameters

$nodes

array

Unprepared data

$nodeHandlers

array

List of node handlers

Returns

arrayPrepared data

Prepares state related fetch limits, based on the list of conditions.

prepareStateLimitFromConditions(array $fetchOptions, string $table, string $stateField, string $userField) : string
Inherited

Looks for keys "deleted" and "moderated".

inherited_from \XenForo_Model::prepareStateLimitFromConditions()

Parameters

$fetchOptions

array

$table

string

Name of the table to prefix the state and user fields with

$stateField

string

Name of the field that holds the state

$userField

string

Name of the field that holds the user ID

Returns

stringSQL condition to limit state

Pushes applicable child node data up the tree.

pushNodeDataUpTree(integer $parentNodeId, array $groupedNodes, array $nodeHandlers, array $nodePermissions) : array

This is used for things like last post data.

Parameters

$parentNodeId

integer

ID to start traversing at; all children will be handled

$groupedNodes

array

Nodes grouped by parent, [parent node id][node id] => info

$nodeHandlers

array

List of node handlers

$nodePermissions

array

List of node permissions, [node id] => permissions

Returns

arrayGrouped node list with data pushed up as necessary

Rebuilds the cache of node types.

rebuildNodeTypeCache() : array

Returns

arrayNode type cache [node type id] => type info

Reset an entry or the entire local cache.

resetLocalCacheData($name) 
Inherited

This can be used if you know when some cached data has expired.

inherited_from \XenForo_Model::resetLocalCacheData()

Parameters

$name

Sets whether we're allowed to read values from the cache on a model-level.

setAllowCachedRead(boolean $allowCachedRead) 
Inherited

This may be controllable on an individual level basis, if the implementation allows it.

inherited_from \XenForo_Model::setAllowCachedRead()

Parameters

$allowCachedRead

boolean

Injects a local cache value.

setLocalCacheData(string $name, $value) 
Inherited

This should only be used if you know what you're doing or for testing purposes!

Note that you cannot get the existing data via the public interface. If you think you need the set data, use a new object. It defaults to empty. :)

inherited_from \XenForo_Model::setLocalCacheData()

Parameters

$name

string

$value

Standardizes a set of node permissions and a user ID to always have appropriate data.

standardizeNodePermissionsAndUserId(integer $nodeId, array | null $permissions, integer | null $userId) 
Inherited

If an invalid permission set or user ID is provided, the current visitor's will be used.

inherited_from \XenForo_Model::standardizeNodePermissionsAndUserId()

Parameters

$nodeId

integer

Node permissions are for

$permissions

arraynull

Permissions for node or null to use current visitor's permissions

$userId

integernull

User permissions belong to or null to use current visitor

Standardizes a permission combination and user ID to always have appropriate data.

standardizePermissionCombinationIdAndUserId(integer | null $permissionCombinationId, integer | null $userId) 
Inherited

If null, users current visitor's values.

inherited_from \XenForo_Model::standardizePermissionCombinationIdAndUserId()

Parameters

$permissionCombinationId

integernull

Permission combination ID or null to use current visitor

$userId

integernull

User permissions belong to or null to use current visitor

Standardizes a set of permissions and a user ID to always have appropriate data.

standardizePermissionsAndUserId(array | null $permissions, integer | null $userId) 
Inherited

If an invalid permission set or user ID is provided, the current visitor's will be used.

inherited_from \XenForo_Model::standardizePermissionsAndUserId()

Parameters

$permissions

arraynull

Global pPermissions or null to use current visitor's permissions

$userId

integernull

User permissions belong to or null to use current visitor

Standardizes a viewing user reference array.

standardizeViewingUserReference(array $viewingUser) 
Inherited

This array must contain all basic user info (preferably all user info) and include global permissions in a "permissions" key. If not an array or missing a user_id, the visitor's values will be used.

inherited_from \XenForo_Model::standardizeViewingUserReference()

Parameters

$viewingUser

arraynull

Standardizes the viewing user reference for the specific node.

standardizeViewingUserReferenceForNode(integer $nodeId, array $viewingUser, array $nodePermissions) 
Inherited
inherited_from \XenForo_Model::standardizeViewingUserReferenceForNode()

Parameters

$nodeId

integer

$viewingUser

arraynull

Viewing user; if null, use visitor

$nodePermissions

arraynull

Permissions for this node; if null, use visitor's

Helper to unserialize permissions in a list of items.

unserializePermissionsInList(array $items, string $serializedKey, string $targetKey) : array
Inherited
inherited_from \XenForo_Model::unserializePermissionsInList()

Parameters

$items

array

List of items

$serializedKey

string

Key where serialized permissions are

$targetKey

string

Key where unserialized permissions will go

Returns

arrayList of items with permissions unserialized

Rebuilds and saves nested set info (lft, rgt, depth) for all nodes based on parent id and display order

updateNestedSetInfo() : array

Returns

arrayAll nodes

Helper method to get the cache object.

_getCache(boolean $forceCachedRead) : \Zend_Cache_Core | \Zend_Cache_Frontend | false
Inherited

If cache reads are disabled, this will return false.

inherited_from \XenForo_Model::_getCache()

Parameters

$forceCachedRead

boolean

If true, the global "allow cached read" value is ignored

Returns

\Zend_Cache_Core\Zend_Cache_Frontendfalse

Gets the data registry model.

_getDataRegistryModel() : \XenForo_Model_DataRegistry
Inherited
inherited_from \XenForo_Model::_getDataRegistryModel()

Returns

Helper method to get the database object.

_getDb() : \Zend_Db_Adapter_Abstract
Inherited
inherited_from \XenForo_Model::_getDb()

Returns

\Zend_Db_Adapter_Abstract

Gets the named entry from the local cache.

_getLocalCacheData(string $name) : mixed
Inherited
inherited_from \XenForo_Model::_getLocalCacheData()

Parameters

$name

string

Returns

mixed

Checks that the provided array is a node by checking that it contains node_id and parent_node_id keys

_isNode(array $node) : boolean
Static

Parameters

$node

array

Returns

boolean

Checks that the provided array is a node hierarchy by checking that the first child of the first element has a node_id key

_isNodeHierarchy(mixed $nodeHierarchy) : boolean
Static

Parameters

$nodeHierarchy

mixed

Returns

boolean

Checks that the provided array is a node array by checking that the first element is a node

_isNodesArray(mixed $nodes) : boolean
Static

Parameters

$nodes

mixed

Returns

boolean

 Properties

 

$_allowCachedRead : boolean
Inherited

If not, it should be retrieved from the source.

inherited_from \XenForo_Model::$$_allowCachedRead
 

$_cache : \Zend_Cache_Core | \Zend_Cache_Frontend
Inherited
inherited_from \XenForo_Model::$$_cache
 

$_db : \Zend_Db_Adapter_Abstract
Inherited
inherited_from \XenForo_Model::$$_db
 

$_localCacheData : array
Inherited

This data is generally treated as canonical, even if {$_allowCachedRead} is false.

inherited_from \XenForo_Model::$$_localCacheData
 

$_modelCache : array
Inherited
inherited_from \XenForo_Model::$$_modelCache