Nextcloud PHP API (stable18)

Mapper

Simple parent class for inheriting your data access layer from. This class may be subject to change in the future

Tags
since
7.0.0
deprecated
14.0.0

Move over to QBMapper

Table of Contents

$db  : mixed
$entityClass  : mixed
$tableName  : mixed
__construct()  : mixed
delete()  : Entity
Deletes an entity from the table
getTableName()  : string
insert()  : Entity
Creates a new entry in the db from an entity
update()  : Entity
Updates an entry in the db from an entity
execute()  : PDOStatement
Runs an sql query
findEntities()  : array
Runs a sql query and returns an array of entities
findEntity()  : Entity
Returns an db result and throws exceptions when there are more or less results
findOneQuery()  : array
Returns an db result and throws exceptions when there are more or less results
mapRowToEntity()  : Entity
Creates an entity from a row. Automatically determines the entity class from the current mapper name (MyEntityMapper -> MyEntity)
buildDebugMessage()  : string
Builds an error message by prepending the $msg to an error message which has the parameters
getPDOType()  : int
Returns the correct PDO constant based on the value type
isAssocArray()  : bool
Checks if an array is associative

Properties

$entityClass

protected mixed $entityClass

$tableName

protected mixed $tableName

Methods

__construct()

public __construct(IDBConnection $db, string $tableName[, string $entityClass = null ]) : mixed
Parameters
$db : IDBConnection

Instance of the Db abstraction layer

$tableName : string

the name of the table. set this to allow entity

$entityClass : string = null

the name of the entity that the sql should be mapped to queries without using sql

Tags
since
7.0.0
deprecated
14.0.0

Move over to QBMapper

Return values
mixed

delete()

Deletes an entity from the table

public delete(Entity $entity) : Entity
Parameters
$entity : Entity

the entity that should be deleted

Tags
since
7.0.0
  • return value added in 8.1.0
deprecated
14.0.0

Move over to QBMapper

Return values
Entity

the deleted entity

getTableName()

public getTableName() : string
Tags
since
7.0.0
deprecated
14.0.0

Move over to QBMapper

Return values
string

the table name

insert()

Creates a new entry in the db from an entity

public insert(Entity $entity) : Entity
Parameters
$entity : Entity

the entity that should be created

Tags
since
7.0.0
deprecated
14.0.0

Move over to QBMapper

Return values
Entity

the saved entity with the set id

update()

Updates an entry in the db from an entity

public update(Entity $entity) : Entity
Parameters
$entity : Entity

the entity that should be created

Tags
throws
InvalidArgumentException

if entity has no id

since
7.0.0
  • return value was added in 8.0.0
deprecated
14.0.0

Move over to QBMapper

Return values
Entity

the saved entity with the set id

execute()

Runs an sql query

protected execute(string $sql[, array $params = [] ][, int $limit = null ][, int $offset = null ]) : PDOStatement
Parameters
$sql : string

the prepare string

$params : array = []

the params which should replace the ? in the sql query

$limit : int = null

the maximum number of rows

$offset : int = null

from which row we want to start

Tags
since
7.0.0
deprecated
14.0.0

Move over to QBMapper

Return values
PDOStatement

the database query result

findEntities()

Runs a sql query and returns an array of entities

protected findEntities(string $sql[, array $params = [] ][, int $limit = null ][, int $offset = null ]) : array
Parameters
$sql : string

the prepare string

$params : array = []

the params which should replace the ? in the sql query

$limit : int = null

the maximum number of rows

$offset : int = null

from which row we want to start

Tags
since
7.0.0
deprecated
14.0.0

Move over to QBMapper

Return values
array

all fetched entities

findEntity()

Returns an db result and throws exceptions when there are more or less results

protected findEntity(string $sql[, array $params = [] ][, int $limit = null ][, int $offset = null ]) : Entity
Parameters
$sql : string

the sql query

$params : array = []

the parameters of the sql query

$limit : int = null

the maximum number of rows

$offset : int = null

from which row we want to start

Tags
throws
DoesNotExistException

if the item does not exist

throws
MultipleObjectsReturnedException

if more than one item exist

since
7.0.0
deprecated
14.0.0

Move over to QBMapper

Return values
Entity

the entity

findOneQuery()

Returns an db result and throws exceptions when there are more or less results

protected findOneQuery(string $sql[, array $params = [] ][, int $limit = null ][, int $offset = null ]) : array
Parameters
$sql : string

the sql query

$params : array = []

the parameters of the sql query

$limit : int = null

the maximum number of rows

$offset : int = null

from which row we want to start

Tags
see
findEntity
throws
DoesNotExistException

if the item does not exist

throws
MultipleObjectsReturnedException

if more than one item exist

since
7.0.0
deprecated
14.0.0

Move over to QBMapper

Return values
array

the result as row

mapRowToEntity()

Creates an entity from a row. Automatically determines the entity class from the current mapper name (MyEntityMapper -> MyEntity)

protected mapRowToEntity(array $row) : Entity
Parameters
$row : array

the row which should be converted to an entity

Tags
since
7.0.0
deprecated
14.0.0

Move over to QBMapper

Return values
Entity

the entity

buildDebugMessage()

Builds an error message by prepending the $msg to an error message which has the parameters

private buildDebugMessage(mixed $msg, string $sql[, array $params = [] ][, int $limit = null ][, int $offset = null ]) : string
Parameters
$msg : mixed
$sql : string

the sql query

$params : array = []

the parameters of the sql query

$limit : int = null

the maximum number of rows

$offset : int = null

from which row we want to start

Tags
see
findEntity
since
9.1.0
deprecated
14.0.0

Move over to QBMapper

Return values
string

formatted error message string

getPDOType()

Returns the correct PDO constant based on the value type

private getPDOType( $value) : int
Parameters
$value :
Tags
since
8.1.0
deprecated
14.0.0

Move over to QBMapper

Return values
int

PDO constant

isAssocArray()

Checks if an array is associative

private isAssocArray(array $array) : bool
Parameters
$array : array
Tags
since
8.1.0
deprecated
14.0.0

Move over to QBMapper

Return values
bool

true if associative

Search results