Menu

## CrudContract

CrudContract.php : 11

### 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()

CrudContract.php : 92

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()

CrudContract.php : 217

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()

CrudContract.php : 283
`protected checkIfFieldPassesAllValidations(mixed $field) : mixed`

##### Parameters

$field : mixed

##### Tags

throws
  Exception

#### createItem()

CrudContract.php : 309

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

`protected createItem() : object|null`

##### Tags

throws
  Exception

##### Return values

object|null

#### deleteItem()

CrudContract.php : 254

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()

CrudContract.php : 145

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()

CrudContract.php : 377

Retrieve all with pagination

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

##### Tags

throws
  Exception

##### Return values

array<string|int, mixed>|null

#### getOne()

CrudContract.php : 174

Retrieve in CRUD, returns on Item at a time.

`protected getOne() : object|null`

##### Tags

throws
  Exception

##### Return values

object|null

#### hasLimit()

CrudContract.php : 200
`protected hasLimit() : mixed`

#### hasOffset()

CrudContract.php : 205
`protected hasOffset() : mixed`

#### isInJoinMode()

CrudContract.php : 240
`protected isInJoinMode() : bool`

##### Return values

bool

#### paginate()

CrudContract.php : 353
`protected paginate() : array<string|int, mixed>|null`

##### Tags

throws
  BaseDatabaseException
throws
  Exception

##### Return values

array<string|int, mixed>|null

#### randomItem()

CrudContract.php : 390
`protected randomItem() : mixed`

##### Tags

throws
  Exception

#### updateItem()

CrudContract.php : 419

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()

CrudContract.php : 47

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()

CrudContract.php : 19

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()

CrudContract.php : 79

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()

CrudContract.php : 192

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()

CrudContract.php : 403

Returns the primary key field

`private primaryKey() : bool|string`

##### Tags

throws
  Exception

##### Return values

bool|string

## Search results