model/modx/modresource.class.php
- package
- modx
- Classes
- modResource
Description
Represents a web resource managed by the modX framework.
\modResource
- Extends from
- \modAccessibleSimpleObject
- package
- modx
- Properties
- $_cacheKey
- $_content
- $_contextKey
- $_isForward
- $_jscripts
- $_loadedjscripts
- $_output
- $_processed
- $_refreshCache
- $_sjscripts
- Methods
- __construct
- addLock
- addOne
- cleanAlias
- duplicate
- findPolicy
- getAliasPath
- getCacheKey
- getContent
- getGroupsList
- getLock
- getMany
- getProcessed
- getTVValue
- getTemplateVarCollection
- getTemplateVars
- hasChildren
- isDuplicateAlias
- joinGroup
- leaveGroup
- listGroups
- process
- refreshURIs
- removeLock
- save
- set
- setContent
- setProcessed
- setTVValue
Description
Represents a web resource managed by the modX framework.
This is the basis for the entire xPDO object model, and can also be used by a class generator {@link xPDOGenerator}, ultimately allowing custom classes to be user-defined in a web interface and framework-generated at runtime.
Properties
$_cacheKey
string $_cacheKey = 'null'
The cache filename for the resource in the context.
Details
- string
- visibility
- public
- default
- null
- final
- false
- static
- false
$_content
string $_content = ''
Represents the cacheable content for a resource.
Note that this is not the raw source content, but the content that is the result of processing cacheable tags within the raw source content.
Details
- string
- visibility
- public
- default
- final
- false
- static
- false
$_contextKey
string $_contextKey = 'null'
The context the resource is requested from.
Note that this is different than the context_key field that describes a primary context for the resource.
Details
- string
- visibility
- public
- default
- null
- final
- false
- static
- false
$_isForward
boolean $_isForward = 'false'
Indicates if this Resource was generated from a forward.
Details
- boolean
- visibility
- public
- default
- false
- final
- false
- static
- false
$_jscripts
$_jscripts = 'array'
Details
- visibility
- public
- default
- array
- final
- false
- static
- false
$_loadedjscripts
$_loadedjscripts = 'array'
Details
- visibility
- public
- default
- array
- final
- false
- static
- false
$_output
string $_output = ''
Represents the output the resource produces.
Details
- string
- visibility
- public
- default
- final
- false
- static
- false
$_processed
boolean $_processed = 'false'
Indicates if the resource has already been processed.
Details
- boolean
- visibility
- protected
- default
- false
- final
- false
- static
- false
$_refreshCache
boolean $_refreshCache = 'true'
Indicates if the site cache should be refreshed when saving changes.
Details
- boolean
- visibility
- protected
- default
- true
- final
- false
- static
- false
$_sjscripts
$_sjscripts = 'array'
Details
- visibility
- public
- default
- array
- final
- false
- static
- false
Methods
__construct
__construct(
\xPDO $xpdo
)
:
\xPDOObject
Creates a modTemplateVar instance, and sets the token of the class to *
{@inheritdoc}
Arguments
- $xpdo
- \xPDO
&$xpdo A reference to a valid xPDO instance.
Output
Details
- visibility
- public
- final
- false
- static
- false
addLock
addLock(
integer $user
=
0, array $options
=
array
)
:
boolean
Adds a lock on the Resource
Arguments
- $user
- integer
- $options
- array
An array of options for the lock.
Output
- boolean
- True if the lock was successful.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
addOne
addOne(
mixed $obj, string $alias
)
:
boolean
Adds an object related to this modResource by a foreign key relationship.
{@inheritdoc}
Adds legacy support for keeping the existing contentType field in sync when a modContentType is set using this function.
Arguments
- $obj
- mixed
&$obj A single object to be related to this instance. - $alias
- string
The relation alias of the related object (only required if more than one relation exists to the same foreign class).
Output
- boolean
- True if the related object was added to this object.
Details
- visibility
- public
- final
- false
- static
- false
cleanAlias
cleanAlias(
string $alias, array $options
=
array
)
:
string
Transforms a string to form a valid URL representation.
Arguments
- $alias
- string
A string to transform into a valid URL representation. - $options
- array
Options to append to or override configuration settings.
Output
- string
- The transformed string.
Details
- visibility
- public
- final
- false
- static
- false
duplicate
duplicate(
array $options
=
array
)
:
mixed
Duplicate the Resource.
Arguments
- $options
- array
An array of options.
Output
- mixed
- Returns either an error message, or the newly created modResource object.
Details
- visibility
- public
- final
- false
- static
- false
findPolicy
findPolicy(
string $context
)
:
array
Loads the access control policies applicable to this resource.
{@inheritdoc}
Arguments
- $context
- string
A key identifying a specific context to use when searching for the applicable policies. If not provided, the current context is used.
Output
- array
- An array of access policies for this object; an empty array is returned if no policies are assigned to the object.
Details
- visibility
- public
- final
- false
- static
- false
getAliasPath
getAliasPath(
string $alias, array $fields
=
array
)
:
string
Get the Resource's full alias path.
Arguments
- $alias
- string
Optional. The alias to check. If not set, will then build it from the pagetitle if automatic_alias is set to true. - $fields
- array
Optional. An array of field values to use instead of using the current modResource fields.
Output
- string
Details
- visibility
- public
- final
- false
- static
- false
getCacheKey
getCacheKey(
)
:
string
Returns the cache key for this instance in the current context.
Output
- string
- The cache key.
Details
- visibility
- public
- final
- false
- static
- false
getContent
getContent(
array $options
=
array
)
:
string
Gets the raw, unprocessed source content for a resource.
{@inheritdoc}
Arguments
- $options
- array
An array of options implementations can use to accept language, revision identifiers, or other information to alter the behavior of the method.
Output
- string
- The raw source content for the resource.
Details
- visibility
- public
- final
- false
- static
- false
getGroupsList
getGroupsList(
array $sort
=
array, int $limit
=
0, int $offset
=
0
)
:
array
Gets a sortable, limitable collection (and total count) of Resource Groups for the Resource.
Arguments
- $sort
- array
An array of sort columns in column => direction format. - $limit
- int
A limit of records to retrieve in the collection. - $offset
- int
A record offset for a limited collection.
Output
- array
- An array containing the collection and total.
Details
- visibility
- public
- final
- false
- static
- false
getLock
getLock(
)
:
int
Gets the lock on the Resource.
Output
- int
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
getMany
getMany(
string $alias, object $criteria
=
null, boolean|integer $cacheFlag
=
false
)
:
array
Gets a collection of objects related by aggregate or composite relations.
{@inheritdoc}
Includes special handling for related objects with alias {@link modTemplateVar}, respecting framework security unless specific criteria are provided.
Arguments
- $alias
- string
Alias of the foreign class representing the related object. - $criteria
- object
xPDOCriteria object to get the related objects - $cacheFlag
- booleaninteger
Indicates if the objects should be cached and optionally, by specifying an integer value, for how many seconds.
Output
- array
- A collection of related objects or an empty array.
Details
- visibility
- public
- final
- false
- static
- false
- todo
- Refactor to use the new ABAC security model.
getProcessed
getProcessed(
)
:
Return whether or not the resource has been processed.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
getTVValue
getTVValue(
mixed $pk
)
:
\null/mixed
Gets the value of a TV for the Resource.
Arguments
- $pk
- mixed
Either the ID of the TV, or the name of the TV.
Output
- \null/mixed
- The value of the TV for the Resource, or null if the TV is not found.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
getTemplateVarCollection
getTemplateVarCollection(
\modResource $resource
)
:
\A
Retrieve a collection of Template Variables for a Resource.
Arguments
- $resource
- \modResource
&$resource A reference to the modResource to retrieve TemplateVars for.
Output
- \A
- collection of modTemplateVar instances for the modResource.
Details
- visibility
- public
- final
- false
- static
- true
- static
getTemplateVars
getTemplateVars(
)
:
array
Get a collection of the Template Variable values for the Resource.
Output
- array
- A collection of TemplateVar values for this Resource.
Details
- visibility
- public
- final
- false
- static
- false
hasChildren
hasChildren(
)
:
integer
Checks to see if the Resource has children or not. Returns the number of children.
Output
- integer
- The number of children of the Resource
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
isDuplicateAlias
isDuplicateAlias(
string $aliasPath, string $contextKey
)
:
mixed
Tests to see if an alias is a duplicate.
Arguments
- $aliasPath
- string
The current full alias path. If none is passed, will build it from the Resource's currently set alias. - $contextKey
- string
The context to search for a duplicate alias in.
Output
- mixed
- The ID of the Resource using the alias, if a duplicate, otherwise false.
Details
- visibility
- public
- final
- false
- static
- false
joinGroup
joinGroup(
mixed $resourceGroupPk
)
:
boolean
Joins a Resource to a Resource Group
Arguments
- $resourceGroupPk
- mixed
Either the ID, name or object of the Resource Group
Output
- boolean
- True if successful.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
leaveGroup
leaveGroup(
mixed $resourceGroupPk
)
:
boolean
Removes a Resource from a Resource Group
Arguments
- $resourceGroupPk
- mixed
Either the ID, name or object of the Resource Group
Output
- boolean
- True if successful.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
listGroups
listGroups(
\modResource $resource, array $sort
=
array, int $limit
=
0, int $offset
=
0
)
:
array
Get a sortable, limitable collection (and total count) of Resource Groups for a given Resource.
Arguments
- $resource
- \modResource
&$resource A reference to the modResource to get the groups from. - $sort
- array
An array of sort columns in column => direction format. - $limit
- int
A limit of records to retrieve in the collection. - $offset
- int
A record offset for a limited collection.
Output
- array
- An array containing the collection and total.
Details
- visibility
- public
- final
- false
- static
- true
- static
process
process(
)
:
string
Process a resource, transforming source content to output.
{@inheritdoc}
Output
- string
- The processed cacheable content of a resource.
Details
- visibility
- public
- final
- false
- static
- false
refreshURIs
refreshURIs(
\modX $modx, int $parent
=
0, array $options
=
array
)
:
void
Refresh Resource URI fields for children of the specified parent.
Arguments
- $modx
- \modX
&$modx A reference to a valid modX instance. - $parent
- int
The id of a Resource parent to start from (default is 0, the root) - $options
- array
An array of various options for the method: - resetOverrides: if true, Resources with uri_override set to true will be included - contexts: an optional array of context keys to limit the refresh scope
Details
- visibility
- public
- final
- false
- static
- true
- static
removeLock
removeLock(
$user
=
0
)
:
boolean
Removes all locks on a Resource.
Arguments
- $user
Output
- boolean
- True if locks were removed.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
save
save(
boolean|integer $cacheFlag
=
null
)
:
boolean
Persist new or changed modResource instances to the database container.
{@inheritdoc}
If the modResource is new, the createdon and createdby fields will be set using the current time and user authenticated in the context.
If uri is empty or uri_overridden is not set and something has been changed which might affect the Resource's uri, it is (re-)calculated using getAliasPath(). This can be forced recursively by setting refreshURIs to true before calling save().
Arguments
- $cacheFlag
- booleaninteger
Indicates if the saved object(s) should be cached and optionally, by specifying an integer value, for how many seconds before expiring. Overrides the cacheFlag for the object(s).
Output
- boolean
- Returns true on success, false on failure.
Details
- visibility
- public
- final
- false
- static
- false
set
set(
string $k, mixed $v
=
null, string|\callable $vType
)
:
boolean
Set a field value by the field key or name.
{@inheritdoc}
Additional logic added for the following fields: -alias: Applies {@link modResource::cleanAlias()} -contentType: Calls {@link modResource::addOne()} to sync contentType -content_type: Sets the contentType field appropriately
Arguments
- $k
- string
The field key or name. - $v
- mixed
The value to set the field to. - $vType
- string\callable
A string indicating the format of the provided value parameter, or a callable function that should be used to set the field value, overriding the default behavior.
Output
- boolean
- Determines whether the value was set successfully and was determined to be dirty (i.e. different from the previous value).
Details
- visibility
- public
- final
- false
- static
- false
setContent
setContent(
mixed $content, array $options
=
array
)
:
boolean
Set the raw source content for this element.
{@inheritdoc}
Arguments
- $content
- mixed
The source content; implementations can decide if it can only be a string, or some other source from which to retrieve it. - $options
- array
An array of options implementations can use to accept language, revision identifiers, or other information to alter the behavior of the method.
Output
- boolean
- True indicates the content was set.
Details
- visibility
- public
- final
- false
- static
- false
setProcessed
setProcessed(
boolean $processed
)
:
Set the field indicating the resource has been processed.
Arguments
- $processed
- boolean
Pass true to indicate the Resource has been processed.
Details
- visibility
- public
- final
- false
- static
- false
setTVValue
setTVValue(
mixed $pk, string $value
)
:
bool
Sets a value for a TV for this Resource
Arguments
- $pk
- mixed
The TV name or ID to set - $value
- string
The value to set for the TV
Output
- bool
- Whether or not the TV saved successfully
Details
- visibility
- public
- final
- false
- static
- false