SimpleTable
class SimpleTable extends FlatTable
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. | from FlatTable |
string | $modelName | It's the name of the model associated with the table | from FlatTable |
Methods
Build a Table model. $table is the name of the table in the database.
Returns the name of the identification field of the record. By default it will be name.
Returns the name of the main key field of the table (PK-Primary Key). By default it will be id.
Execute a magic method of the setField or getField style
Get the name of the table (with prefix)
TODO: Undocummented.
Return an array with the current active record.
Execute a call to setTableStructure with an array containing 3 arrays with the fields, keys and default values for the table.
Save the structure of the table in a static array, so that it is available at all times.
A raw array is built with all the information available in the table, configuration files and code.
Return a list of fields and their table structure. Each final model that needed, must overwrite it.
Returns a new instance of the table with the requested record.
This method is private. Use getBy instead.
Returns the structure of the normalized table
Get an array with all data in table.
Count all registers in table.
Get an array with all data per page.
Do a search to a table.
Return the main part of the search SQL query.
Do a search to a table.
Details
at line 28
__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)
in
Entity
at line 106
string
getId()
Return the value of id.
in
Entity
at line 116
string
getNameField()
Returns the name of the identification field of the record. By default it will be name.
in
Entity
at line 128
$this
setData(array $data)
Assign newData from $data.
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.
in
Entity
at line 153
array
getData()
Return newData details.
in
Entity
at line 163
array
getOldData()
Return oldData details.
in
Entity
at line 175
$this
setOldData(array $data)
Assign oldData from an array.
in
Entity
at line 191
$this|mixed|null
__call(string $method, array $params)
Execute a magic method of the setField or getField style
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.
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'.
in
Entity
at line 252
bool
__isset(string $propertyName)
Magic isset.
in
FlatTable
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.
in
FlatTable
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.
in
FlatTable
at line 102
string
getQuotedTableName(bool $usePrefix = true)
Get the name of the table (with prefix)
in
FlatTable
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.
at line 105
array
defaultData()
TODO: Undocummented.
in
FlatTable
at line 139
string
getTableName(bool $usePrefix = true)
Get the name of the table (with prefix)
in
FlatTable
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.
in
FlatTable
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.
in
FlatTable
at line 180
bool
save()
Saves the changes made to the active record.
in
FlatTable
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.
in
FlatTable
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.
in
FlatTable
at line 281
bool
delete()
Deletes the active record.
at line 54
setStructure()
Execute a call to setTableStructure with an array containing 3 arrays with the fields, keys and default values for the table.
The development will be more ambitious than what is defined.
Currently Table includes a single table, but the idea is to be able to relate tables to form complex data models.
at line 67
protected
setTableStructure(string $table, array $structure)
Save the structure of the table in a static array, so that it is available at all times.
at line 79
protected array
getStructureArray()
A raw array is built with all the information available in the table, configuration files and code.
at line 95
array
getFieldsFromTable()
Return a list of fields and their table structure. Each final model that needed, must overwrite it.
at line 124
bool
getBy(string $key, mixed $value)
Returns a new instance of the table with the requested record.
As a previous step, a getDataBy of the current instance is made, so both will point to the same record. Makes a getDataBy and returns a new instance of the model.
at line 140
private bool
getDataBy(string $key, mixed $value)
This method is private. Use getBy instead.
Establishes a record as an active record. If found the pair $key-$value the data will be in $this->newData. If it is not found, $this->id will contain '' and $this->newData will contain the data by default.
at line 161
array
getStructure()
Returns the structure of the normalized table
at line 172
array
getAllRecords()
Get an array with all data in table.
WARNING: This could be dangerous with a big table.
at line 183
int
countAllRecords()
Count all registers in table.
at line 198
array
getAllRecordsPaged(int $offset = 0)
Get an array with all data per page.
at line 216
array
search(string $query, array $columns = [], int $offset = 0, string $order =
'')
Do a search to a table.
Returns the result per page.
at line 234
string
searchQuery(string $query, array $columns = [])
Return the main part of the search SQL query.
at line 268
int
searchCount(string $query, array $columns = [])
Do a search to a table.
Returns the result per page.