Model to handle inline mod-style actions on posts.

Generally, these are simply bulk actions. They can be applied to other circumstances if desired.

package XenForo_Post

 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

Approves the specified posts if permissions are sufficient.

approvePosts(array $postIds, array $options, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs to approve

$options

array

Options that control the action. Nothing supported at this time.

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

booleanTrue if permissions were ok

Ensures that a valid cut-off operator is passed.

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

Parameters

$operator

string

Determines if the selected post IDs can be approved/unapproved.

canApproveUnapprovePosts(array $postIds, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs check

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

Determines if the selected posts can be approved/unapproved.

canApproveUnapprovePostsData(array $posts, array $threads, array $forums, string $errorKey, array $viewingUser) : boolean

This is a slightly more "internal" version of the canApproveUnapprovePosts() function, as the required data must already be retrieved.

Parameters

$posts

array

List of information about posts to be checked

$threads

array

List of information about threads the posts are in

$forums

array

List of information about forums the threads/posts are in; must include unserialized permissions in 'nodePermissions' key

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

Determines if the selected post IDs can be deleted.

canDeletePosts(array $postIds, string $deleteType, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs check

$deleteType

string

The type of deletion being requested (soft or hard)

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

Determines if the selected posts can be deleted.

canDeletePostsData(array $posts, string $deleteType, array $threads, array $forums, string $errorKey, array $viewingUser) : boolean

This is a slightly more "internal" version of the canDeletePosts() function, as the required data must already be retrieved.

Parameters

$posts

array

List of information about posts to be deleted

$deleteType

string

Type of deletion (soft or hard)

$threads

array

List of information about threads the posts are in

$forums

array

List of information about forums the threads/posts are in; must include unserialized permissions in 'nodePermissions' key

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

Determines if the selected post IDs can be merged.

canMergePosts(array $postIds, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs check

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

Determines if the selected posts can be merged.

canMergePostsData(array $posts, array $threads, array $forums, string $errorKey, array $viewingUser) : boolean

This is a slightly more "internal" version of the canMergePosts() function, as the required data must already be retrieved.

Parameters

$posts

array

List of information about posts to be checked

$threads

array

List of information about threads the posts are in

$forums

array

List of information about forums the threads/posts are in; must include unserialized permissions in 'nodePermissions' key

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

Determines if the selected post IDs can be moved.

canMovePosts(array $postIds, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs check

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

Determines if the selected posts can be moved.

canMovePostsData(array $posts, array $threads, array $forums, string $errorKey, array $viewingUser) : boolean

This is a slightly more "internal" version of the canMovePosts() function, as the required data must already be retrieved.

Parameters

$posts

array

List of information about posts to be checked

$threads

array

List of information about threads the posts are in

$forums

array

List of information about forums the threads/posts are in; must include unserialized permissions in 'nodePermissions' key

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

Determines if the selected post IDs can be undeleted.

canUndeletePosts(array $postIds, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs check

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

Determines if the selected posts can be undeleted.

canUndeletePostsData(array $posts, array $threads, array $forums, string $errorKey, array $viewingUser) : boolean

This is a slightly more "internal" version of the canUndeletePosts() function, as the required data must already be retrieved.

Parameters

$posts

array

List of information about posts to be checked

$threads

array

List of information about threads the posts are in

$forums

array

List of information about forums the threads/posts are in; must include unserialized permissions in 'nodePermissions' key

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

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 the specified posts if permissions are sufficient.

deletePosts(array $postIds, array $options, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs to delete

$options

array

Options that control the delete. Supports deleteType (soft or hard).

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

booleanTrue if permissions were ok

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

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

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

From a list of post IDs, gets info about the posts, their threads, and the forums the threads are in.

getPostsAndParentData(array $postIds, array $viewingUser) : array

Parameters

$postIds

array

List of post IDs

$viewingUser

arraynull

Returns

arrayFormat: [0] => list of posts, [1] => list of threads, [2] => list of forums

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 the specified posts if permissions are sufficient.

mergePosts(array $postIds, array $options, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs to merge

$options

array

Options that control the action. Nothing supported at this time.

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

booleanTrue if permissions were ok

Moves the specified posts if permissions are sufficient.

movePosts(array $postIds, array $options, string $errorKey, array $viewingUser) : array | false

Parameters

$postIds

array

List of post IDs to move

$options

array

Options that control the action. Nothing supported at this time.

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

arrayfalseFalse if error; array of info about new thread otherwise

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 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

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

Unapproves the specified posts if permissions are sufficient.

unapprovePosts(array $postIds, array $options, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs to unapprove

$options

array

Options that control the action. Nothing supported at this time.

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

booleanTrue if permissions were ok

Undeletes the specified posts if permissions are sufficient.

undeletePosts(array $postIds, array $options, string $errorKey, array $viewingUser) : boolean

Parameters

$postIds

array

List of post IDs to undelete

$options

array

Options that control the action. Nothing supported at this time.

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

booleanTrue if permissions were ok

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

Checks a standard post permission against a collection of posts.

_checkPermissionOnPosts(string $permissionMethod, array $posts, array $threads, array $forums, string $errorKey, array $viewingUser) : boolean

True is returned only if the action is possible on all posts.

Parameters

$permissionMethod

string

Name of the permission method to call in the post model

$posts

array

List of posts to check

$threads

array

List of threads the posts are in

$forums

array

List of forums the threads are in

$errorKey

string

Modified by reference. If no permission, may include a key of a phrase that gives more info

$viewingUser

arraynull

Returns

boolean

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

_getForumModel()

_getForumModel() : \XenForo_Model_Forum

Gets the named entry from the local cache.

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

Parameters

$name

string

Returns

mixed

_getPostModel()

_getPostModel() : \XenForo_Model_Post

Gets information about the thread and forum a post belongs to, from the post's info.

_getThreadAndForumFromPost(array $post, array $threads, array $forums) : array

Parameters

$post

array

Info about the post

$threads

array

List of threads that the post could belong to

$forums

array

List of forums that the post's thread could be long to

Returns

arrayFormat: [0] => thread, [1] => forum

_getThreadModel()

_getThreadModel() : \XenForo_Model_Thread

Internal helper to update the message_state of a collection of posts.

_updatePostsMessageState(array $posts, array $threads, array $forums, string $newState, string | false $expectedOldState) 

Parameters

$posts

array

Information about the posts to update

$threads

array

Information about the threads that the posts are in

$forums

array

Information about the forums that the threads/posts are in

$newState

string

New message state (visible, moderated, deleted)

$expectedOldState

stringfalse

If specified, only updates if the old state matches

 Properties

 

$enableLogging 
 

$_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