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

Prepares the list of steps with extra info about each step, such as whether or not it has already been run.

addImportStateToSteps(array $steps, array $runSteps) : array

Parameters

$steps

array

$runSteps

array

Returns

array

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

Renames the import log table before creating a new empty version.

archiveImportLog(string $archiveTableName, mixed $error) : boolean

Parameters

$archiveTableName

string

Archive table name

$error

mixed

Error phrase reference

Returns

boolean

Ensures that a valid cut-off operator is passed.

assertValidCutOffOperator(string $operator) 
Inherited

inherited_from \XenForo_Model::assertValidCutOffOperator()

Parameters

$operator

string

Determines whether or not the specified step can be run at this time.

canRunStep(string $step, array $steps, array $runSteps) : boolean

Parameters

$step

string

$steps

array

$runSteps

array

Returns

boolean

Factory method to get the named model.

create(string $class) : \XenForo_Model
Inherited

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

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

Fetches an array of all possible admin permissions

getAdminPermissionIds() : array

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 an import content map to map old IDs to new IDs for the given content type.

getImportContentMap(string $contentType, array $ids) : array

Parameters

$contentType

string

$ids

array

Returns

array

Gets the specified importer.

getImporter(string $key) : \XenForo_Importer_Abstract

Parameters

$key

string

Name of importer (key); just last part of name, not full path.

Returns

Fetches a list of available importers

getImporterList() : array

Returns

array

Gets the name of the specied importer

getImporterName(string $key) : string

Parameters

$key

string

Importer ID

Returns

string

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

Fetches node permissions

getNodePermissionsGrouped() : array

Returns

array

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

Grabs post IDs from the source array and returns a map with their new/imported ID values

getPostIdsMapFromArray(array $source, string $key) : array

Parameters

$source

array

$key

string

Name of the key in $source that identifies the post IDs

Returns

array

Grabs thread IDs from the source array and returns a map with their new/imported ID values

getThreadIdsMapFromArray(array $source, string $key) : array

Parameters

$source

array

$key

string

Name of the key in $source that identifies the thread IDs

Returns

array

Alters the given $fieldId in order to avoid conflicts with keys from $existing

getUniqueFieldId(string $fieldId, array $existing, integer $maxLength) : string

Parameters

$fieldId

string

$existing

array

$maxLength

integer

Returns

string

Fetches definitions for all XenForo custom user fields

getUserFieldDefinitions() : array

Returns

array

Fetches a XenForo user ID based on their email address

getUserIdByEmail(string $email) : integer

Parameters

$email

string

Returns

integer

Fetches a XenForo user ID based on their user name

getUserIdByUserName(string $name) : integer

Parameters

$name

string

Returns

integer

Gets the user IDs of the XenForo users with the specified email addresses

getUserIdsByEmails(array $emails) : array

Parameters

$emails

array

Returns

array

Gets the user IDs of the XenForo users with the specified usernames

getUserIdsByNames(array $names) : array

Parameters

$names

array

Returns

array

Grabs user IDs from the source array and returns a map with their new/imported ID values

getUserIdsMapFromArray(array $source, string | array $key) : array

Parameters

$source

array

$key

stringarray

Name of the key in $source that identifies the user IDs

Returns

array

Gets the user IDs of the users that meet the specified conditions

getUserIdsWithKey(array $conditions, string $key, string $lowerKey) : array

Parameters

$conditions

array

$key

string

$lowerKey

string

Returns

array

Returns true if there is data that has been imported;

hasImportedData() : boolean

Returns

boolean

Imports a custom user avatar

importAvatar(integer $oldUserId, integer $userId, string $fileName) : mixed

Parameters

$oldUserId

integer

Source user ID

$userId

integer

Imported user ID

$fileName

string

Path to the avatar file

Returns

mixedUser ID on success, false on failure

Imports a ban for a user

importBan(array $info) : integer

Parameters

$info

array

User info

Returns

integerBan ID

Imports a category

importCategory(integer $oldId, array $info) : integer

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

integerImported node ID

Imports private messages etc.

importConversation(integer $oldId, array $conversation, array $recipients, array $messages) : integer

into a XenForo conversation

Parameters

$oldId

integer

Source ID

$conversation

array

Data for XenForo_DataWriter_ConversationMaster

$recipients

array

Recipient data

$messages

array

Data for XenForo_DataWriter_ConversationMessage

Returns

integerImported conversation ID

Imports a buddy list / friend list etc.

importFollowing(integer $userId, array $followUserIds) 

as a XenForo 'following' list.

Parameters

$userId

integer

The user doing the following

$followUserIds

array

User IDs to follow

Imports a forum

importForum(integer $oldId, array $info) : integer

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

integerImported node ID

Imports a global moderator

importGlobalModerator(integer $oldId, array $info) : integer

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

integerID of moderating user

Imports an ignore list

importIgnored(integer $userId, array $ignoreUserIds) 

Parameters

$userId

integer

The user doing the ignoring

$ignoreUserIds

array

User IDs to ignore

Imports an IP log

importIp(integer $userId, string $contentType, string $contentId, string $action, integer $ipAddress, $date) : integer

Parameters

$userId

integer

User ID

$contentType

string

Content type

$contentId

string

Action

$action

string

IP address

$ipAddress

integer

Date

$date

Returns

integerIP ID

Import a content 'Like'

importLike(string $contentType, integer $contentId, integer $contentUserId, integer $likeUserId, integer $likeDate) 

Parameters

$contentType

string

$contentId

integer

$contentUserId

integer

$likeUserId

integer

$likeDate

integer

Imports a link forum

importLinkForum(integer $oldId, array $info) : integer

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

integerImported node ID

Imports a forum/node moderator

importNodeModerator(integer $oldNodeId, integer $oldUserId, array $info) : integer

Parameters

$oldNodeId

integer

$oldUserId

integer

$info

array

Returns

integerImported moderator ID

Imports a poll vote

importPollVote(integer $pollId, integer $userId, integer $responseId, integer $voteDate) 

Parameters

$pollId

integer

$userId

integer

$responseId

integer

$voteDate

integer

Imports a post

importPost(integer $oldId, array $info) : integer

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

integerImported post ID

Imports a post attachment

importPostAttachment(integer $oldAttachmentId, string $fileName, string $tempFile, integer $userId, integer $postId, integer $date, array $attach, \function $messageCallback, string $messageText) : \Imported

Parameters

$oldAttachmentId

integer

$fileName

string

$tempFile

string

$userId

integer

$postId

integer

$date

integer

$attach

array

data to import

$messageCallback

\function

$messageText

string

Returns

\Importedattachment ID

Imports a profile post

importProfilePost(integer $oldId, array $info) : integer

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

integerImported profile post ID

Imports a profile post comment

importProfilePostComment(integer $oldId, array $info) : \Imported

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

\Importedprofile post comment ID

Imports a thread

importThread(integer $oldId, array $info) : integer

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

integerImported thread ID

Imports a thread poll

importThreadPoll(integer $oldId, integer $threadId, array $info, array $responses, array $responseIds) : integer

Parameters

$oldId

integer

Source poll ID

$threadId

integer

Thread ID

$info

array

Data to import

$responses

array

Responses

$responseIds

array

Response IDs

Returns

integerImported poll ID

Imports a thread prefix definition

importThreadPrefix(mixed $oldId, array $info, string $title, array $nodeIds) : integer

Parameters

$oldId

mixed

$info

array

$title

string

$nodeIds

array

Returns

integerImported thread prefix id

Imports a thread prefix group definition

importThreadPrefixGroup(mixed $oldId, array $info) : integer

Parameters

$oldId

mixed

$info

array

Returns

integerImported thread prefix group id

Imports a thread watch/subscription

importThreadWatch(integer $userId, integer $threadId, string $emailSubscribe, boolean $deferred) : integer

Parameters

$userId

integer

User ID

$threadId

integer

Thread ID

$emailSubscribe

string

Subscription type

$deferred

boolean

Deferred

Returns

integerImported post ID

Imports a user

importUser(integer $oldId, array $info, $failedKey) : integer

Parameters

$oldId

integer

Source ID

$info

array

Data to import

$failedKey

Returns

integerImported user ID

Imports a custom user field definition

importUserField(integer $oldId, array $info) : string

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

stringImported user field ID

Imports a user group

importUserGroup(integer $oldId, array $info) : integer

Parameters

$oldId

integer

Source ID

$info

array

Data to import

Returns

integerImported user group ID

insertDeferredThreadWatch()

insertDeferredThreadWatch() 

Inserts global permission entries

insertGlobalPermissionEntries(integer $userGroupId, integer $userId, array $perms) 

Parameters

$userGroupId

integer

$userId

integer

$perms

array

Inserts node permissions

insertNodePermissionEntries(integer $nodeId, integer $userGroupId, integer $userId, array $perms) 

Parameters

$nodeId

integer

$userGroupId

integer

$userId

integer

$perms

array

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

Writes a log of old id and new id for an imported item of content

logImportData(string $contentType, integer $oldId, integer $newId) 

Parameters

$contentType

string

$oldId

integer

$newId

integer

Maps an old attachment ID to a new/imported attachment ID

mapAttachmentId(integer $id, integer $default) : integer

Parameters

$id

integer

$default

integer

Returns

integer

Maps an old node/forum ID to a new/imported node ID

mapNodeId(integer $id, integer $default) : integer

Parameters

$id

integer

$default

integer

Returns

integer

Maps an old post ID to a new/imported post ID

mapPostId(integer $id, integer $default) : integer

Parameters

$id

integer

$default

integer

Returns

integer

Maps an old thread ID to a new/imported thread ID

mapThreadId(integer $id, integer $default) : integer

Parameters

$id

integer

$default

integer

Returns

integer

Maps an old user ID to a new/imported user ID

mapUserId(integer $id, integer $default) : integer

Parameters

$id

integer

$default

integer

Returns

integer

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

Resets the import log table.

resetImportLog() 

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

Attempts to convert a time zone offset into a location string

resolveTimeZoneOffset(float $offset, boolean $useDst) : string

Parameters

$offset

float

Offset (in hours) from UTC

$useDst

boolean

Apply daylight savings

Returns

stringLocation string, such as Europe/London

Sets the value of the $_retainKeys option, in order to retain the existing keys where possible

retainKeys(boolean $retainKeys) 

Parameters

$retainKeys

boolean

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

setAllowCachedRead($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

Converts data from the $info array into data keys for a datawriter, then removes the keys from the $info array

_convertKeysToExtraData(array $info, array $keys) 

Parameters

$info

array

$keys

array

[DataWriterInfoConst => keyName,...]

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

_getUserModel()

_getUserModel() : \XenForo_Model_User

Wrapper for the XenForo DataWriter system to allow content to be imported.

_importData(string $oldId, string $dwName, string $contentKey, string $idKey, array $info, string $errorHandler, boolean $update) : integer

Parameters

$oldId

string

$dwName

string

Name of the XenForo_DataWriter that will write the data

$contentKey

string

$idKey

string

$info

array

$errorHandler

string

$update

boolean

Attempt to force an update rather than an insert

Returns

integerImported content ID

 Properties

 

Static array listing extra importers that aren't in the right directory.

$extraImporters : array

 

List of content type IDs that can be retained if $_retainKeys is true

$retainableKeys : array

 

Array to store admin permissions as they are loaded

$_adminPermissions : array

 

Controls whether a cached read is allowed.

$_allowCachedRead : boolean
Inherited

If not, it should be retrieved from the source.

inherited_from \XenForo_Model::$$_allowCachedRead
 

Cache object

$_cache : \Zend_Cache_Core | \Zend_Cache_Frontend
Inherited

inherited_from \XenForo_Model::$$_cache
 

Array to store content maps as they are loaded

$_contentMapCache : array

 

Database object

$_db : \Zend_Db_Adapter_Abstract
Inherited

inherited_from \XenForo_Model::$$_db
 

Stores local, instance-specific cached data for each model.

$_localCacheData : array
Inherited

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

inherited_from \XenForo_Model::$$_localCacheData
 

Standard approach to caching other model objects for the lifetime of the model.

$_modelCache : array
Inherited

inherited_from \XenForo_Model::$$_modelCache
 

If true, wherever possible, keep the existing data primary key

$_retainKeys : boolean

 

Array to store recognised / supported Like types for XenForo_Model_Import::importLike()

$_supportedLikeTypes : array

 

$_threadWatchDeferred

$_threadWatchDeferred 

 

$_uniqueFieldIds

$_uniqueFieldIds 

 

$_userFieldDefinitions

$_userFieldDefinitions 

 Constants

 

EXTRA_DATA_KEY

EXTRA_DATA_KEY 

 

USER_FIELD_KEY

USER_FIELD_KEY