Mjoin
extends Join
in package
The `Mjoin` class extends the `Join` class with the join data type set to 'array', whereas the `Join` default is `object` which has been rendered obsolete by the `Editor->leftJoin()` method. The API API is otherwise identical.
This class is recommended over the Join
class.
Table of Contents
Methods
- __construct() : mixed
- Join instance constructor.
- aliasParentTable() : mixed
- Get / set parent table alias.
- field() : mixed
- Get / set field instances.
- fields() : mixed
- Get / set field instances.
- get() : mixed
- Get / set get attribute.
- 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.
- join() : mixed
- Get / set join properties.
- leftJoin() : $this
- Set up a left join operation for the Mjoined data.
- link() : $this
- Create a join link between two tables. The order of the fields does not matter, but each field must contain the table name as well as the field name.
- name() : mixed
- Get / set name.
- order() : mixed
- Specify the property that the data will be sorted by.
- set() : mixed
- Get / set set attribute.
- table() : mixed
- Get / set join table name.
- type() : mixed
- Get / set the join type.
- validator() : $this
- Set a validator for the array of data (not on a field basis).
- where() : mixed
- Where condition to add to the query used to get data from the database.
- whereSet() : mixed
- Get / set if the WHERE conditions should be included in the create and edit actions.
- _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).
- _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()
Join instance constructor.
public
__construct([string $table = null ][, string $type = 'object' ]) : mixed
Parameters
- $table : string = null
-
Table name to get the joined data from.
- $type : string = 'object'
-
Work with a single result ('object') or an array of results ('array') for the join.
aliasParentTable()
Get / set parent table alias.
public
aliasParentTable([string $_ = null ]) : mixed
When working with a self referencing table (i.e. a column in the table contains a primary key value from its own table) it can be useful to set an alias on the parent table's name, allowing a self referencing Join. For example:
SELECT p2.publisher
FROM publisher as p2
JOIN publisher on (publisher.idPublisher = p2.idPublisher)
Where, in this case, publisher
is the table that is used by the Editor instance,
and you want to use Join
to link back to the table (resolving a name for example).
This method allows that alias to be set. Fields can then use standard SQL notation
to select a field, for example p2.publisher
or publisher.publisher
.
Parameters
- $_ : string = null
-
Table alias to use
Return values
mixed —Table alias set (which is null by default).
field()
Get / set field instances.
public
field([Field $_ = null ]) : mixed
The list of fields designates which columns in the table that will be read from the joined table.
Parameters
- $_ : Field = null
-
Instances of the Field class, given as a single instance of Field, an array of Field instances, or multiple Field instance parameters for the function.
Tags
Return values
mixed —Array of fields.
fields()
Get / set field instances.
public
fields([Field $_ = null ]) : mixed
An alias of field, for convenience.
Parameters
- $_ : Field = null
-
Instances of the Field class, given as a single instance of Field, an array of Field instances, or multiple Field instance parameters for the function.
Tags
Return values
mixed —Array of fields.
get()
Get / set get attribute.
public
get([bool $_ = null ]) : mixed
When set to false no read operations will occur on the join tables.
Parameters
- $_ : bool = null
-
Value
Return values
mixed —Name
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
join()
Get / set join properties.
public
join([string|array<string|int, string> $parent = null ][, string|array<string|int, string> $child = null ][, string $table = null ]) : mixed
Define how the SQL will be performed, on what columns. There are basically two types of join that are supported by Editor here, a direct foreign key reference in the join table to the parent table's primary key, or a link table that contains just primary keys for the parent and child tables (this approach is usually used with a Join->type() of 'array' since you can often have multiple links between the two tables, while a direct foreign key reference will typically use a type of 'object' (i.e. a single entry).
Parameters
- $parent : string|array<string|int, string> = null
-
Parent table's primary key names. If used with a link table (i.e. third parameter to this method is given, then an array should be used, with the first element being the pkey's name in the parent table, and the second element being the key's name in the link table.
- $child : string|array<string|int, string> = null
-
Child table's primary key names. If used with a link table (i.e. third parameter to this method is given, then an array should be used, with the first element being the pkey's name in the child table, and the second element being the key's name in the link table.
- $table : string = null
-
Join table name, if using a link table
Tags
leftJoin()
Set up a left join operation for the Mjoined data.
public
leftJoin(string $table, string $field1, string $operator, string $field2) : $this
Parameters
- $table : string
-
to get the information from
- $field1 : string
-
the first field to get the information from
- $operator : string
-
the operation to perform on the two fields
- $field2 : string
-
the second field to get the information from
Return values
$thislink()
Create a join link between two tables. The order of the fields does not matter, but each field must contain the table name as well as the field name.
public
link(string $field1, string $field2) : $this
This method can be called a maximum of two times for an Mjoin instance:
- First time, creates a link between the Editor host table and a join table
- Second time creates the links required for a link table.
Please refer to the Editor Mjoin documentation for further details: https://editor.datatables.net/manual/php
Parameters
- $field1 : string
-
Table and field name
- $field2 : string
-
Table and field name
Return values
$thisname()
Get / set name.
public
name([string $_ = null ]) : mixed
The name
of the Join is the JSON property key that is used when
'getting' the data, and the HTTP property key (in a JSON style) when
'setting' data. Typically the name of the db table will be used here,
but this method allows that to be overridden.
Parameters
- $_ : string = null
-
Field name
Return values
mixed —Name
order()
Specify the property that the data will be sorted by.
public
order([string $_ = null ]) : mixed
Parameters
- $_ : string = null
-
SQL column name to order the data by
set()
Get / set set attribute.
public
set([bool $_ = null ]) : mixed
When set to false no write operations will occur on the join tables. This can be useful when you want to display information which is joined, but want to only perform write operations on the parent table.
Parameters
- $_ : bool = null
-
Value
Return values
mixed —Name
table()
Get / set join table name.
public
table([string $_ = null ]) : mixed
Please note that this will also set the Join->name() used by the Join as well. This is for convenience as the JSON output / HTTP input will typically use the same name as the database name. If you want to set a custom name, the Join->name() method must be called after this one.
Parameters
- $_ : string = null
-
Name of the table to read the join data from
Return values
mixed —Name of the join table.
type()
Get / set the join type.
public
type([string $_ = null ]) : mixed
The join type allows the data that is returned from the join to be given as an array (i.e. working with multiple possibly results for each record from the parent table), or as an object (i.e. working which one and only one result for each record form the parent table).
Parameters
- $_ : string = null
-
Join type ('object') or an array of results ('array') for the join.
Return values
mixed —Join type.
validator()
Set a validator for the array of data (not on a field basis).
public
validator(string $fieldName, mixed $fn) : $this
Parameters
- $fieldName : string
-
Name of the field that any error should be shown against on the client-side
- $fn : mixed
Return values
$thiswhere()
Where condition to add to the query used to get data from the database.
public
where([mixed $key = null ][, string|array<string|int, string> $value = null ][, string $op = '=' ]) : mixed
Note that this is applied to the child table.
Can be used in two different ways:
- Simple case:
where( field, value, operator )
- Complex:
where( fn )
Parameters
- $key : mixed = null
- $value : string|array<string|int, string> = null
-
Single field value, or an array of values.
- $op : string = '='
-
Condition operator: <, >, = etc
Return values
mixed —Where condition array.
whereSet()
Get / set if the WHERE conditions should be included in the create and edit actions.
public
whereSet([bool $_ = null ]) : mixed
This means that the fields which have been used as part of the 'get'
WHERE condition (using the where()
method) will be set as the values
given.
This is default false (i.e. they are not included).
Parameters
- $_ : bool = null
-
Include (
true
), or not (false
)
Return values
mixed —Current value
_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
_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