StateRestore
extends Ext
in package
Base class for DataTables classes.
Table of Contents
Methods
- __construct() : mixed
- Constructor.
- columnDefault() : mixed
- Get / set the column name for the default state flag.
- columnId() : mixed
- Get / set the column name for the table's primary key.
- columnName() : mixed
- Get / set the column name for the state name.
- columnPath() : mixed
- Get / set the column name for the URL (path) of where the state applies.
- columnShared() : mixed
- Get / set the column name for the shared flag.
- columnState() : mixed
- Get / set the column name for where the state itself is stored.
- columnTable() : mixed
- Get / set the column name for where the name of the host DataTable is stored.
- columnUser() : mixed
- Get / set the column name for where the user identifier is stored.
- data() : array<string|int, mixed>
- Get the data constructed in this instance.
- db() : mixed
- Get / set the database connection instance.
- inst() : static
- Static method to instantiate a new instance of a class (shorthand of 'instantiate').
- instantiate() : static
- Static method to instantiate a new instance of a class.
- json() : mixed
- Get the JSON for the data constructed in this instance.
- process() : $this
- Process a request from the StateRestore client-side to get / set data.
- set() : mixed
- Get / set extra column name / value properties to store in the db. These are _set only_ - they are not read back from the db when loading a state.
- table() : mixed
- Get / set the table name that will be used for state storage in the database.
- user() : mixed
- Get / set the value for the current user identifier. This is usually a user id, but it could be any other unique identifier.
- where() : mixed
- Where condition to add to the query used to get data from the database.
- _getSet() : mixed
- Common getter / setter function for DataTables classes.
- _propExists() : bool
- Determine if a property is available in a data set (allowing `null` to be a valid value).
- _proxy() : mixed
- Execute a method from a given instance. If the return is that instance, then return self instead, otherwise give the returned value.
- _readProp() : mixed
- Read a value from a data structure, using Javascript dotted object notation. This is the inverse of the `_writeProp` method and provides the same support, matching DataTables' ability to read nested JSON data objects.
- _writeProp() : mixed
- Write the field's value to an array structure, using Javascript dotted object notation to indicate JSON data structure. For example `name.first` gives the data structure: `name: { first: ... }`. This matches DataTables own ability to do this on the client-side, although this doesn't implement implement quite such a complex structure (no array / function support).
Methods
__construct()
Constructor.
public
__construct([Database $db = null ][, string $table = null ][, string $pkey = null ]) : mixed
Parameters
- $db : Database = null
-
An instance of the DataTables Database class that we can use for the DB connection. Can be given here or with the 'db' method.
- $table : string = null
-
The table name in the database to read and write information from and to. Can be given here or with the 'table' method.
- $pkey : string = null
-
Primary key column name in the table given in the $table parameter. Can be given here or with the 'pkey' method.
columnDefault()
Get / set the column name for the default state flag.
public
columnDefault([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
Column name
Return values
mixed —Column name.
columnId()
Get / set the column name for the table's primary key.
public
columnId([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
Primary key column name
Return values
mixed —Column name.
columnName()
Get / set the column name for the state name.
public
columnName([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
Column name
Return values
mixed —Column name.
columnPath()
Get / set the column name for the URL (path) of where the state applies.
public
columnPath([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
Column name
Return values
mixed —Column name.
columnShared()
Get / set the column name for the shared flag.
public
columnShared([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
Column name
Return values
mixed —Column name.
columnState()
Get / set the column name for where the state itself is stored.
public
columnState([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
Column name
Return values
mixed —Column name.
columnTable()
Get / set the column name for where the name of the host DataTable is stored.
public
columnTable([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
Column name
Return values
mixed —Column name.
columnUser()
Get / set the column name for where the user identifier is stored.
public
columnUser([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
Column name
Return values
mixed —Column name.
data()
Get the data constructed in this instance.
public
data() : array<string|int, mixed>
This will get the PHP array of data that has been constructed for the command that has been processed by this instance. Therefore only useful after process has been called.
Return values
array<string|int, mixed> —Processed data array.
db()
Get / set the database connection instance.
public
db([Database $_ = null ]) : mixed
Parameters
- $_ : Database = null
-
Database instance
Return values
mixed —Database instance.
inst()
Static method to instantiate a new instance of a class (shorthand of 'instantiate').
public
static inst() : static
This method performs exactly the same actions as the 'instantiate' static method, but is simply shorter and easier to type!
Return values
static —class
instantiate()
Static method to instantiate a new instance of a class.
public
static instantiate() : static
A factory method that will create a new instance of the class that has extended 'Ext'. This allows classes to be instantiated and then chained - which otherwise isn't available until PHP 5.4. If using PHP 5.4 or later, simply create a 'new' instance of the target class and chain methods as normal.
Return values
static —Instantiated class
json()
Get the JSON for the data constructed in this instance.
public
json([bool $print = true ][, int $options = 0 ]) : mixed
Basically the same as the StateRestore->data() method, but in this case we echo, or return the JSON string of the data.
Parameters
- $print : bool = true
-
Echo the JSON string out (true, default) or return it (false).
- $options : int = 0
-
JSON encode option https://www.php.net/manual/en/json.constants.php
Return values
mixed —JSON representation of the processed data if false is given as the first parameter.
process()
Process a request from the StateRestore client-side to get / set data.
public
process(array<string|int, mixed> $data) : $this
Parameters
- $data : array<string|int, mixed>
-
Typically $_POST or $_GET as required by what is sent by StateRestore
Return values
$thisset()
Get / set extra column name / value properties to store in the db. These are _set only_ - they are not read back from the db when loading a state.
public
set([array<string|int, mixed> $_ = null ]) : mixed
They can however be used for auditing information or for extra query conditions.
Parameters
- $_ : array<string|int, mixed> = null
-
Column name / value pairs
Return values
mixed —Column values
table()
Get / set the table name that will be used for state storage in the database.
public
table([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
Table name
Return values
mixed —Table name.
user()
Get / set the value for the current user identifier. This is usually a user id, but it could be any other unique identifier.
public
user([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
User id
Return values
mixed —Column name.
where()
Where condition to add to the query used to get data from the database.
public
where([string|callable(Query): void $key = null ][, string $value = null ][, string $op = '=' ]) : mixed
Can be used in two different ways:
- Simple case:
where( field, value, operator ) - Complex:
where( fn )
The simple case is fairly self explanatory, a condition is applied to the
data that looks like field operator value (e.g. name = 'Allan'). The
complex case allows full control over the query conditions by providing a
closure function that has access to the database Query that Editor is
using, so you can use the where(), or_where(), and_where() and
where_group() methods as you require.
Please be very careful when using this method! If an edit made by a user using Editor removes the row from the where condition, the result is undefined (since Editor expects the row to still be available, but the condition removes it from the result set).
Parameters
- $key : string|callable(Query): void = null
-
Single field name or a closure function
- $value : string = null
-
Single field value.
- $op : string = '='
-
Condition operator: <, >, = etc
Return values
mixed —Where condition array.
_getSet()
Common getter / setter function for DataTables classes.
protected
_getSet(mixed &$prop, mixed $val[, bool $array = false ]) : mixed
This getter / setter method makes building getter / setting methods easier, by abstracting everything to a single function call.
Parameters
- $prop : mixed
-
The property to set
- $val : mixed
-
The value to set - if given as null, then we assume that the function is being used as a getter.
- $array : bool = false
-
Treat the target property as an array or not (default false). If used as an array, then values passed in are added to the $prop array.
_propExists()
Determine if a property is available in a data set (allowing `null` to be a valid value).
protected
_propExists(string $name, array<string|int, mixed> $data) : bool
Parameters
- $name : string
-
Javascript dotted object name to write to
- $data : array<string|int, mixed>
-
Data source array to read from
Return values
bool —true if present, false otherwise
_proxy()
Execute a method from a given instance. If the return is that instance, then return self instead, otherwise give the returned value.
protected
_proxy(mixed $inst, string $method, array<string|int, mixed> $args) : mixed
Parameters
- $inst : mixed
-
Class instance
- $method : string
-
Method to execute
- $args : array<string|int, mixed>
-
The arguments from the function
Return values
mixed —Value from the executed function or self.
_readProp()
Read a value from a data structure, using Javascript dotted object notation. This is the inverse of the `_writeProp` method and provides the same support, matching DataTables' ability to read nested JSON data objects.
protected
_readProp(string $name, array<string|int, mixed> $data) : mixed
Parameters
- $name : string
-
Javascript dotted object name to write to
- $data : array<string|int, mixed>
-
Data source array to read from
Return values
mixed —The read value, or null if no value found.
_writeProp()
Write the field's value to an array structure, using Javascript dotted object notation to indicate JSON data structure. For example `name.first` gives the data structure: `name: { first: ... }`. This matches DataTables own ability to do this on the client-side, although this doesn't implement implement quite such a complex structure (no array / function support).
protected
_writeProp(array<string|int, mixed> &$out, string $name, mixed $value) : mixed
Parameters
- $out : array<string|int, mixed>
-
Array to write the data to
- $name : string
-
Javascript dotted object name to write to
- $value : mixed
-
Value to write