Pionia Core

CrudContract

Table of Contents

Methods

_checkPaginationInternal()  : bool
Detects if we have pagination params anywhere in the request.
allItems()  : array<string|int, mixed>|null
Retrieve all in CRUD
checkIfFieldPassesAllValidations()  : mixed
createItem()  : object|null
Create in CRUD Saves in transactions, runs pre and post create events
deleteItem()  : mixed
Delete in CRUD Handles both post and pre delete events Deletes in joined mode if defined too, but will delete only from the main table
detectPagination()  : bool
Detect if our pagination params are defined anywhere in the request.
getAllWithPagination()  : array<string|int, mixed>|null
Retrieve all with pagination
getOne()  : object|null
Retrieve in CRUD, returns on Item at a time.
hasLimit()  : mixed
hasOffset()  : mixed
isInJoinMode()  : bool
paginate()  : array<string|int, mixed>|null
randomItem()  : mixed
updateItem()  : object|array<string|int, mixed>|null
Updated an item in the db.
cleanRelationColumns()  : void
If the fields are already in the format of relationships, this method reverses that including removing duplicates.
detectAndAddColumns()  : void
Checks if the frontend has defined columns we should query by.
getListColumns()  : array<string|int, mixed>|string
Returns the columns we shall query from the db while querying
getOneInternal()  : null|array<string|int, mixed>|object
Gets one item from the database. Can be overridden by defining a getOne method in the service
primaryKey()  : bool|string
Returns the primary key field

Methods

_checkPaginationInternal()

Detects if we have pagination params anywhere in the request.

protected _checkPaginationInternal(array<string|int, mixed> $data) : bool

For pagination to kick-in, both offset and limit must be defined at any of the levels defined by $this->detectPagination()

Parameters
$data : array<string|int, mixed>
Tags
see

$this->detectPagination()

Return values
bool

allItems()

Retrieve all in CRUD

protected allItems() : array<string|int, mixed>|null

Can be overridden by defining a getItems method in the service

Tags
throws
BaseDatabaseException
throws
Exception
Return values
array<string|int, mixed>|null

checkIfFieldPassesAllValidations()

protected checkIfFieldPassesAllValidations(mixed $field) : mixed
Parameters
$field : mixed
Tags
throws
Exception

createItem()

Create in CRUD Saves in transactions, runs pre and post create events

protected createItem() : object|null
Tags
throws
Exception
Return values
object|null

deleteItem()

Delete in CRUD Handles both post and pre delete events Deletes in joined mode if defined too, but will delete only from the main table

protected deleteItem() : mixed
Tags
throws
Exception

detectPagination()

Detect if our pagination params are defined anywhere in the request.

protected detectPagination(array<string|int, mixed> $reqData) : bool

Remember these can in defined in one of the following:-

On the request root level

Parameters
$reqData : array<string|int, mixed>
Tags
example
{
    SERVICE: "ourService",
    ACTION: "ourAction",
    LIMIT: 10, // can also be `limit: 10`
    OFFSET: 5 // can also be `offset: 5`
}

Or they can be defined under the PAGINATION/pagination key
example
{
    SERVICE: "ourService",
    ACTION: "ourAction",
    PAGINATION:{ // can also be `pagination`
         LIMIT: 10, // can also be `limit: 10`
         OFFSET: 5 // can also be `offset: 5`
     }
}

Or in the SEARCH/search param
example

{ SERVICE: "ourService", ACTION: "ourAction", SEARCH:{ // can also be search LIMIT: 10, // can also be limit: 10 OFFSET: 5 // can also be offset: 5 } } }

Return values
bool

getAllWithPagination()

Retrieve all with pagination

protected getAllWithPagination() : array<string|int, mixed>|null
Tags
throws
Exception
Return values
array<string|int, mixed>|null

getOne()

Retrieve in CRUD, returns on Item at a time.

protected getOne() : object|null
Tags
throws
Exception
Return values
object|null

isInJoinMode()

protected isInJoinMode() : bool
Return values
bool

randomItem()

protected randomItem() : mixed
Tags
throws
Exception

updateItem()

Updated an item in the db.

protected updateItem() : object|array<string|int, mixed>|null

If updateColumns are defined, it only updates those.

It also calls both preUpdate and postUpdate hooks if defined

Tags
throws
Exception
Return values
object|array<string|int, mixed>|null

cleanRelationColumns()

If the fields are already in the format of relationships, this method reverses that including removing duplicates.

private cleanRelationColumns() : void
Tags
example
$this->listColumns = ["alias2.name", "alias1.name(category_name), "alias1.id"];
// this will become
$this->listColumns = ["name", "name(category_name), "id"];

by the time of querying name(category_name) will take precedence of name thus we shall end up with category_name and id in the response

detectAndAddColumns()

Checks if the frontend has defined columns we should query by.

private detectAndAddColumns() : void

Works for both joined and non-joined querying. It pays respect to aliases defined, so, don't forget to respect them too!

getListColumns()

Returns the columns we shall query from the db while querying

private getListColumns() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|string

getOneInternal()

Gets one item from the database. Can be overridden by defining a getOne method in the service

private getOneInternal(mixed $id) : null|array<string|int, mixed>|object
Parameters
$id : mixed
Tags
throws
Exception
Return values
null|array<string|int, mixed>|object

primaryKey()

Returns the primary key field

private primaryKey() : bool|string
Tags
throws
Exception
Return values
bool|string

        
On this page

Search results