class FlatTable extends Entity

Class SimpleTable has all the basic methods to access and manipulate information, but without modifying its structure.

Properties

DebugTool $debugTool The debug tool used. from Entity
string $shortName Class short name. from Entity
bool $exists from Entity
string $id from Entity
string $idField from Entity
string $nameField from Entity
array $newData from Entity
array $oldData from Entity
string $tableName It is the name of the table.
string $modelName It's the name of the model associated with the table

Methods

__construct(string $tableName, array $params = [])

Build a Table model. $table is the name of the table in the database.

string
getId()

Return the value of id.

from Entity
string
getNameField()

Returns the name of the identification field of the record. By default it will be name.

from Entity
$this
setData(array $data)

Assign newData from $data.

from Entity
string
getIdField()

Returns the name of the main key field of the table (PK-Primary Key). By default it will be id.

from Entity
array
getData()

Return newData details.

from Entity
array
getOldData()

Return oldData details.

from Entity
$this
setOldData(array $data)

Assign oldData from an array.

from Entity
$this|mixed|null
__call(string $method, array $params)

Execute a magic method of the setField or getField style

from Entity
mixed
__get(string $propertyName)

Magic getter.

from Entity
$this
__set(string $propertyName, mixed $propertyValue)

Magic setter.

from Entity
bool
__isset(string $propertyName)

Magic isset.

from Entity
get(string $id)

Returns a new instance of the table with the requested record.

bool
getDataById(string $id)

This method is private. Use load instead.

string
getQuotedTableName(bool $usePrefix = true)

Get the name of the table (with prefix)

newRecord(string|null $id = null)

Sets the active record in a new record.

array
defaultData()

TODO: Undocummented.

string
getTableName(bool $usePrefix = true)

Get the name of the table (with prefix)

array
getDataArray(string $id = null)

Return an array with the current active record.

bool
load(string $id)

Establishes a record as an active record.

bool
save()

Saves the changes made to the active record.

bool
updateRecord(array $data)

Update the modified fields in the active record.

bool
insertRecord(array $values)

Insert a new record.

bool
delete()

Deletes the active record.

Details

at line 41
__construct(string $tableName, array $params = [])

Build a Table model. $table is the name of the table in the database.

$params is a parameters array: - create is true if the table is to be created if it does not exist (false by default) - idField is the name of the primary key (default id) - nameField is the name of the descriptive field (name by default)

Parameters

string $tableName
array $params

in Entity at line 106
string getId()

Return the value of id.

Return Value

string

in Entity at line 116
string getNameField()

Returns the name of the identification field of the record. By default it will be name.

Return Value

string

in Entity at line 128
$this setData(array $data)

Assign newData from $data.

Parameters

array $data

Return Value

$this

in Entity at line 143
string getIdField()

Returns the name of the main key field of the table (PK-Primary Key). By default it will be id.

Return Value

string

in Entity at line 153
array getData()

Return newData details.

Return Value

array

in Entity at line 163
array getOldData()

Return oldData details.

Return Value

array

in Entity at line 175
$this setOldData(array $data)

Assign oldData from an array.

Parameters

array $data

Return Value

$this

in Entity at line 191
$this|mixed|null __call(string $method, array $params)

Execute a magic method of the setField or getField style

Parameters

string $method
array $params

Return Value

$this|mixed|null

Exceptions

RuntimeException

in Entity at line 220
mixed __get(string $propertyName)

Magic getter.

It allows access to a field of the record using the attribute. To access the name field, we should use $this->getName(), but thanks to this, we can also use $this->name.

Parameters

string $propertyName

Return Value

mixed

in Entity at line 236
$this __set(string $propertyName, mixed $propertyValue)

Magic setter.

Allows you to assign value to a field in the record using the attribute. To assign a value to the name field, we should use $this->setName('Pepe'), but thanks to this, we can also use $this->name='Pepe'.

Parameters

string $propertyName
mixed $propertyValue

Return Value

$this

in Entity at line 252
bool __isset(string $propertyName)

Magic isset.

Parameters

string $propertyName

Return Value

bool

at line 61
SimpleTable get(string $id)

Returns a new instance of the table with the requested record.

As a previous step, a getData of the current instance is made, so both will point to the same record. Makes a getData and returns a new instance of the model.

Parameters

string $id

Return Value

SimpleTable

at line 80
private bool getDataById(string $id)

This method is private. Use load instead.

Establishes a record as an active record. If found, return true and the $id will be in $this->id and the data in $this->newData. If it is not found, return false, and have not effect into the instance.

Parameters

string $id

Return Value

bool

at line 102
string getQuotedTableName(bool $usePrefix = true)

Get the name of the table (with prefix)

Parameters

bool $usePrefix

Return Value

string

at line 111
newRecord(string|null $id = null)

Sets the active record in a new record.

Note that changes made to the current active record will be lost.

Parameters

string|null $id

at line 127
array defaultData()

TODO: Undocummented.

Return Value

array

at line 139
string getTableName(bool $usePrefix = true)

Get the name of the table (with prefix)

Parameters

bool $usePrefix

Return Value

string

at line 153
array getDataArray(string $id = null)

Return an array with the current active record.

If an $id is indicated, it searches to change the active record before returning the value. Warning: If an $id is set, any unsaved data will be lost when searching for the new record.

Parameters

string $id

Return Value

array

at line 170
bool load(string $id)

Establishes a record as an active record.

If found, the $id will be in $this->id and the data in $this->newData. If it is not found, $this->id will contain '' and $this->newData will contain the data by default.

Parameters

string $id

Return Value

bool

at line 180
bool save()

Saves the changes made to the active record.

Return Value

bool

at line 213
private bool updateRecord(array $data)

Update the modified fields in the active record.

$data is an array of assignments of type field=value.

Parameters

array $data

Return Value

bool

at line 239
private bool insertRecord(array $values)

Insert a new record.

$fields is an array of fields and $values an array with the values for each field in the same order.

Parameters

array $values

Return Value

bool

at line 281
bool delete()

Deletes the active record.

Return Value

bool