Contao Utils Bundle

ModelUtil
in package

Table of Contents

Properties

$framework  : ContaoFramework
$insertTagParser  : InsertTagParser
$tokenChecker  : TokenChecker

Methods

__construct()  : mixed
addPublishedCheckToModelArrays()  : void
Adds an published check to your model query.
findModelInstanceByIdOrAlias()  : Model|null
Returns model instance by given table and id or alias.
findModelInstanceByPk()  : Model|null
Find a single model instance for given table by its primary key (id).
findModelInstancesBy()  : array<string|int, Model>|Collection|null
Returns model instances by given table and search criteria.
findMultipleModelInstancesByIds()  : Collection|Model|null
Returns multiple model instances by given table and ids.
findOneModelInstanceBy()  : Model|null
Return a single model instance by table and search criteria.
findParentsRecursively()  : array<string|int, T>
Returns an array of a model instance's parents in ascending order, i.e. the root parent comes first.

Properties

$framework read-only

private ContaoFramework $framework

$insertTagParser read-only

private InsertTagParser $insertTagParser

$tokenChecker read-only

private TokenChecker $tokenChecker

Methods

__construct()

public __construct(ContaoFramework $framework, InsertTagParser $insertTagParser, TokenChecker $tokenChecker) : mixed
Parameters
$framework : ContaoFramework
$insertTagParser : InsertTagParser
$tokenChecker : TokenChecker

addPublishedCheckToModelArrays()

Adds an published check to your model query.

public addPublishedCheckToModelArrays(string $table, array<string|int, mixed> &$columns[, array{publishedField?: string, startField?: string, stopField?: string, invertPublishedField?: bool, invertStartStopFields?: bool, ignoreFePreview?: bool} $options = [] ]) : void

Options:

  • publishedField: The name of the published field. Default: "published"
  • startField: The name of the start field. Default: "start"
  • stopField: The name of the stop field. Default: "stop"
  • invertPublishedField: Set to true, if the published field should be evaluated inverted (for "hidden" or "invisible" fields. Default: false
  • invertStartStopFields: Set to true, if the start and stop fields should be evaluated in an inverted manner. Default: false
  • ignoreFePreview: Set to true, frontend preview should be ignored. Default: false
Parameters
$table : string

The table name

$columns : array<string|int, mixed>

The columns array

$options : array{publishedField?: string, startField?: string, stopField?: string, invertPublishedField?: bool, invertStartStopFields?: bool, ignoreFePreview?: bool} = []

pass additional options

findModelInstanceByIdOrAlias()

Returns model instance by given table and id or alias.

public findModelInstanceByIdOrAlias(string $table, int|string $idOrAlias[, array<string|int, mixed> $options = [] ]) : Model|null
Parameters
$table : string
$idOrAlias : int|string
$options : array<string|int, mixed> = []
Return values
Model|null

findModelInstanceByPk()

Find a single model instance for given table by its primary key (id).

public findModelInstanceByPk(string $table, int|string $pk[, array<string|int, mixed> $options = [] ]) : Model|null
Parameters
$table : string

The table

$pk : int|string

The property value

$options : array<string|int, mixed> = []

An optional options array

Return values
Model|null

The model or null if the result is empty

findModelInstancesBy()

Returns model instances by given table and search criteria.

public findModelInstancesBy(string $table, array<string|int, mixed>|string|null $columns, int|string|array<string|int, mixed>|null $values[, array{skipReplaceInsertTags?: bool} $options = [] ]) : array<string|int, Model>|Collection|null

Options:

  • skipReplaceInsertTags: (bool) Skip the replacement of inserttags. Default: false
Parameters
$table : string
$columns : array<string|int, mixed>|string|null
$values : int|string|array<string|int, mixed>|null
$options : array{skipReplaceInsertTags?: bool} = []
Return values
array<string|int, Model>|Collection|null

findMultipleModelInstancesByIds()

Returns multiple model instances by given table and ids.

public findMultipleModelInstancesByIds(string $table, array<string|int, mixed> $ids[, array<string|int, mixed> $options = [] ]) : Collection|Model|null
Parameters
$table : string
$ids : array<string|int, mixed>
$options : array<string|int, mixed> = []
Return values
Collection|Model|null

findOneModelInstanceBy()

Return a single model instance by table and search criteria.

public findOneModelInstanceBy(string $table, array<string|int, mixed> $columns, array<string|int, mixed> $values[, array{skipReplaceInsertTags?: bool} $options = [] ]) : Model|null

Options:

  • skipReplaceInsertTags: Skip the replacement of inserttags. Default: false
Parameters
$table : string
$columns : array<string|int, mixed>
$values : array<string|int, mixed>
$options : array{skipReplaceInsertTags?: bool} = []
Return values
Model|null

findParentsRecursively()

Returns an array of a model instance's parents in ascending order, i.e. the root parent comes first.

public findParentsRecursively(T $instance[, string $parentProperty = 'pid' ]) : array<string|int, T>
Parameters
$instance : T
$parentProperty : string = 'pid'
Tags
template

T of Model

Return values
array<string|int, T>

        
On this page

Search results