This documentation is powered by the Dispute component based on the pj DataProvider and the pj DataProvider Framework respectively.

Basic Concepts:

  • The pj DataProvider is a general usage framework usable in any PHP environment;
  • IDataProvider defines a function set the actual database engine interface must provide;
  • MySqlDataProvider is the IDataProvider layer to the MySql database engine (mysqli).
    Other database layers have only to be developed (e.g. PostgreDataProvider, SqlServerDataProvider, OracleDataProvider etc.) and implemented in the place of MySqlDataProvider with no effects for the application code itself;
  • InfoBase, representing one single database table row, is a base class for extension's classes with specific functionality related to application's database tables.

Usage:

The developer writes own DataProvider class, which instantiates and opens a singleton IDataProvider database connection (MySqlDataProvider) and eventually implemments specific business layer functions.

Then, he/she designs business layer classes extending InfoBase corresponding to the database model and registers them at start-up in the DataProvider. It is not necessary to add any code to bare class declaration, although it is convenient to outsource specific  functionality there.

The framework offers full database access for registered InfoBase classes, including retrieving by ID or by queries passed either by string or by SearchKey structure. It recognizes changes of instance data and inserts, updates and deletes instances together with corresponding table rows, optionally in nested transactions. It ensures that at any time, there exists at most one unique instance of InfoBase class representing one database table row.

Abstract database query construct.

SearchKey class, together with RelatedKey and SearchRelation classes, are located in the file /libraries/pj/data/SearchKey.php.

The groundwork is based on three member variables: field, value and comparator, representing one simple query condition performed on one database table. Optionally, the member variable orderBy may set the result ordering.

More SearchKey instances can be dynamically chained to a complex query using member variables andKey and orKey, which may contain further SearchKey conditions themselves and so on. Thus it is possible to construct a query of unlimited complexity, passed by just one single root SearchKey instance. Functions AddAndKey (SearchKey $key) and AddOrKey (SearchKey $key) help by creation as they care for chaining the $key on the end of the chain.

RelatedKey class enhances the SearchKey for queries on related database tables.

See SearchKey Properties, Methods and Examples for more details.

Extends the SearchKey to relational query construct.

The class SearchRelation is a simple help class used in the RelatedKey structure only. It stays for one SQL JOIN clause.

RelatedKey and SearchRelation classes are both located in the file /libraries/pj/data/SearchKey.php.

API

class SearchRelation

$leftField The searched class field referenced by related class
$rightClass Related class name or class instance
$rightField The field the related class references the searched class by
$joinType Type of join
function __construct ($leftField, $rightClass, $rightField, $joinType = 'INNER')

Constructor.

$leftField: The searched class field referenced by related class
$rightClass: Related class name or class instance
$rightField: The field the related class references the searched class by
$joinType: Type of join, one of 'LEFT', 'INNER', 'RIGHT'

RelatedKey properties

$field Database field name, inherited from SearchKey. It applies to the last class in the $relations property.
$value Value to be compared, inherited from SearchKey. See SearchKey Properties, Methods and Examples for explanation.
$comparator field : value comparator, inherited. See SearchKey Properties, Methods and Examples for explanation.
$orderBy

Optional ordering field, inherited from SearchKey.

The $orderBy property applies to the last class in the $relations property.

Multiple $orderBy ordering is given by the SearchKey structure maybe not fitting the ordering desired. Therefore, it is possible to fix it by explicite setting the $orderBy position like "(1)name", "(2)created desc" etc.
$andKey Optional another SearchKey related with SQL "AND", inherited from SearchKey
$orKey Optional another SearchKey related with SQL "OR", inherited from SearchKey
$relations An instance or an array of SearchRelation
$relatedAndKey Optional another SearchKey related with SQL "AND", applying to the last class in the $relations propery.
$relatedOrKey Optional another SearchKey related with SQL "OR", applying to the last class in the $relations propery.

RelatedKey Methods

function __construct ($relation, $field = '', $value = 0, $cmp = self::CMP_EQUAL, $partial = false)

Constructor

$relation: An instance or an array of SearchRelation. In latter case, $relatedAndKey and $relatedOrKey concern the table defined by the last element;
Arguments $field, $value and $cmp set corresponding fields. The argument $partial isused with string values and if true, it inserts SearchKey::STRING_WILDCARD before and after the value.
function AddAndKey (SearchKey $key) Inserts the $key as the last element of the andKey chain, inherited from SearchKey
function AddOrKey (SearchKey $key) Inserts the $key as the last element of the orKey chain, inherited from SearchKey
function AddRelatedAndKey (SearchKey $key) Inserts the $key as the last element of the relaterAndKey chain.
function AddRelatedOrKey (SearchKey $key) Inserts the $key as the last element of the relaterOrKey chain.

See also RelatedKey Examples.