Documentation

CrudServiceModel extends DbServiceModel
in package
Uses WhereUtilities, OrderUtilities, DeleteFilteredTrait

Crud service's default model

Tags
author

Dodonov A.A.

Table of Contents

$entityName  : string
Entity name
$fieldsSet  : FieldsSet
Fields algorithms
$tableName  : string
Table name
__construct()  : mixed
Constructor
deleteFiltered()  : int
Method deletes filtered records
fetchRecordsByIds()  : array<string|int, mixed>
Method fetches records bythe specified fields
getApropriateConnection()  : PdoCrud
Method returns appropriate connections
getEntityName()  : string
Method returns entity name
getFields()  : array<string|int, string>
Method returns fields list
getFieldsNames()  : string
Method returns list of all fields as string
getFieldType()  : string
Method returns field type
getRecords()  : array<string|int, mixed>
Method fetches records after transformation
getSimpleRecords()  : array<string|int, mixed>
Method fetches records before transformation
getTableName()  : string
Method returns table name
hasCustomFields()  : bool
Method returns true if the custom field exists
hasField()  : bool
Method returns true if the field exists
insertBasicFields()  : array<string|int, mixed>
Method inserts basic fields
lastRecords()  : array<string|int, mixed>
Method returns last $count records
newRecordsSince()  : array<string|int, mixed>
Method returns all records created since $date
recordsCount()  : int
Method returns amount of records in table
recordsCountByField()  : array<string|int, mixed>
Method returns amount of records in table, grouped by the specified field
updateBasicFields()  : array<string|int, mixed>
Method updates records
validateFieldExistance()  : void
Method validates if the field $field exists
addDomainIdCondition()  : array<string|int, mixed>
Method adds domain conditions
fetchRecordsByIdsTransformer()  : void
Method transforms record before it will be returned with the fetchRecordsByIds method
getDefaultOrder()  : array<string|int, mixed>
Method defaults empty order to the default one
getRecordsTransformer()  : void
Method transforms record before it will be returned with the getRecords method
lastNewRecordsSince()  : void
Method transforms record before it will be returned with the newRecordsSince method
lastRecordsTransformer()  : void
Method transforms record before it will be returned with the lastRecords method
setTableName()  : void
Method sets table name
compileSelectQuery()  : string
Method compiles select query

Properties

Methods

__construct()

Constructor

public __construct([string $tableName = '' ]) : mixed
Parameters
$tableName : string = ''

name of the table

Tags
psalm-suppress

MissingParamType

Return values
mixed

deleteFiltered()

Method deletes filtered records

public deleteFiltered(int|false $domainId, array<string|int, string> $where) : int
Parameters
$domainId : int|false

Domain id

$where : array<string|int, string>

Filtration conditions

Return values
int

fetchRecordsByIds()

Method fetches records bythe specified fields

public fetchRecordsByIds(int|false $domainId, string $ids) : array<string|int, mixed>
Parameters
$domainId : int|false

domain id

$ids : string

ids of records to be fetched

Return values
array<string|int, mixed>

list of records

getEntityName()

Method returns entity name

public getEntityName() : string
Return values
string

entity name

getFields()

Method returns fields list

public getFields() : array<string|int, string>
Return values
array<string|int, string>

fields list

getFieldsNames()

Method returns list of all fields as string

public getFieldsNames() : string
Return values
string

list of all fields as string

getFieldType()

Method returns field type

public getFieldType(string $fieldName) : string
Parameters
$fieldName : string

field name

Return values
string

field type

getRecords()

Method fetches records after transformation

public getRecords(int|bool $domainId, int $from, int $limit[, array<string|int, string> $where = ['1=1'] ][, array<string|int, mixed> $order = [] ]) : array<string|int, mixed>
Parameters
$domainId : int|bool

id of the domain

$from : int

starting record

$limit : int

fetch limit

$where : array<string|int, string> = ['1=1']

fetch condition

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

sorting condition

Tags
psalm-suppress

MixedArgumentTypeCoercion

Return values
array<string|int, mixed>

of records

getSimpleRecords()

Method fetches records before transformation

public getSimpleRecords(int|bool $domainId, int $from, int $limit, array<string|int, string> $where[, array<string|int, mixed> $order = [] ]) : array<string|int, mixed>
Parameters
$domainId : int|bool

id of the domain

$from : int

starting record

$limit : int

fetch limit

$where : array<string|int, string>

fetch condition

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

sorting condition

Tags
psalm-suppress

MixedArgumentTypeCoercion

Return values
array<string|int, mixed>

array of records

getTableName()

Method returns table name

public getTableName() : string
Return values
string

table name

hasCustomFields()

Method returns true if the custom field exists

public hasCustomFields() : bool
Return values
bool

hasField()

Method returns true if the field exists

public hasField(string $fieldName) : bool
Parameters
$fieldName : string

field name

Return values
bool

insertBasicFields()

Method inserts basic fields

public insertBasicFields(array<string, mixed> $record, mixed $domainId) : array<string|int, mixed>
Parameters
$record : array<string, mixed>

record to be inserted

$domainId : mixed

id of the domain

Tags
psalm-suppress

MixedAssignment

Return values
array<string|int, mixed>

inserted record

lastRecords()

Method returns last $count records

public lastRecords(int|false $domainId, int $count, array<string|int, string> $where) : array<string|int, mixed>
Parameters
$domainId : int|false

id of the domain

$count : int

amount of records to be returned

$where : array<string|int, string>

filter conditions

Tags
psalm-suppress

MixedArgumentTypeCoercion

Return values
array<string|int, mixed>

list of the last $count records

newRecordsSince()

Method returns all records created since $date

public newRecordsSince(int|false $domainId, string $date) : array<string|int, mixed>
Parameters
$domainId : int|false

do we have domain limitations

$date : string

start of the period

Tags
psalm-suppress

MixedArgumentTypeCoercion

Return values
array<string|int, mixed>

list of records created since $date

recordsCount()

Method returns amount of records in table

public recordsCount([int|bool $domainId = false ][, array<string|int, string> $where = ['1=1'] ]) : int
Parameters
$domainId : int|bool = false

do we have domain limitations

$where : array<string|int, string> = ['1=1']

filter

Tags
psalm-suppress

MixedArgumentTypeCoercion

Return values
int

amount of records

recordsCountByField()

Method returns amount of records in table, grouped by the specified field

public recordsCountByField(int|false $domainId, string $fieldName, array<string|int, string> $where) : array<string|int, mixed>
Parameters
$domainId : int|false

domain id

$fieldName : string

grouping field

$where : array<string|int, string>

filtration conditions

Tags
psalm-suppress

MixedArgumentTypeCoercion

Return values
array<string|int, mixed>

records with stat

updateBasicFields()

Method updates records

public updateBasicFields(int|false $domainId, array<string|int, mixed> $record, array<string|int, string> $where) : array<string|int, mixed>
Parameters
$domainId : int|false

domain id. Pass false if we want to ignore domain_id security

$record : array<string|int, mixed>

new values for fields

$where : array<string|int, string>

condition

Tags
psalm-suppress

MixedArgumentTypeCoercion

Return values
array<string|int, mixed>

updated fields

validateFieldExistance()

Method validates if the field $field exists

public validateFieldExistance(string $field) : void
Parameters
$field : string

Field name

Return values
void

addDomainIdCondition()

Method adds domain conditions

protected addDomainIdCondition(int|bool $domainId[, array<string|int, mixed> $where = [] ]) : array<string|int, mixed>
Parameters
$domainId : int|bool

Do we have domain limitations

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

where condition

Return values
array<string|int, mixed>

where condition with domain_id limitations

fetchRecordsByIdsTransformer()

Method transforms record before it will be returned with the fetchRecordsByIds method

protected fetchRecordsByIdsTransformer(array<string|int, mixed> &$records) : void
Parameters
$records : array<string|int, mixed>

record to be transformed

Return values
void

getDefaultOrder()

Method defaults empty order to the default one

protected getDefaultOrder(array<string|int, mixed> $order) : array<string|int, mixed>
Parameters
$order : array<string|int, mixed>

order data to be defaulted

Return values
array<string|int, mixed>

defaulted order data

getRecordsTransformer()

Method transforms record before it will be returned with the getRecords method

protected getRecordsTransformer(array<string|int, mixed> &$records) : void
Parameters
$records : array<string|int, mixed>

record to be transformed

Tags
codeCoverageIgnore
Return values
void

lastNewRecordsSince()

Method transforms record before it will be returned with the newRecordsSince method

protected lastNewRecordsSince(array<string|int, mixed> &$records) : void
Parameters
$records : array<string|int, mixed>

record to be transformed

Return values
void

lastRecordsTransformer()

Method transforms record before it will be returned with the lastRecords method

protected lastRecordsTransformer(array<string|int, mixed> &$records) : void
Parameters
$records : array<string|int, mixed>

record to be transformed

Return values
void

setTableName()

Method sets table name

protected setTableName([string $tableName = '' ]) : void
Parameters
$tableName : string = ''

table name

Return values
void

compileSelectQuery()

Method compiles select query

private compileSelectQuery(array<string|int, string> $where) : string
Parameters
$where : array<string|int, string>

where conditions

Tags
psalm-suppress

MixedArgumentTypeCoercion

Return values
string

select query

Search results