This class is used as base class for all DAO objects and defines all usefull functions

abstract
uses the database link
uses a request sent to the database
uses a DB\Result from the database
uses the exceptions handler
uses transforms an object to an associative array
uses translate errors
package OWR
used_by \OWR\CLI\Controller
used_by \OWR\Model\Objects
used_by \OWR\Model\Users
used_by \OWR\Model\News
used_by \OWR\Model\News\Tags
used_by \OWR\Model\Streams
used_by \OWR\Model\Streams\Groups
used_by \OWR\REST\Controller
used_by \OWR\Controller
used_by \OWR\DAO\Objects
used_by \OWR\DAO\Users
used_by \OWR\DAO\News
used_by \OWR\DAO\news\Contents
used_by \OWR\DAO\news\relations\Tags
used_by \OWR\DAO\news\Relations
used_by \OWR\DAO\news\Tags
used_by \OWR\DAO\Streams
used_by \OWR\DAO\Sessions
used_by \OWR\DAO\users\Tokens
used_by \OWR\DAO\streams\Contents
used_by \OWR\DAO\streams\relations\Name
used_by \OWR\DAO\streams\Groups
used_by \OWR\DAO\streams\Relations

 Methods

Counts row(s) from the database

count(mixed $args, string $select, string $groupby, string $selectAdd) : mixed
access public
author Pierre-Alain Mignot

Parameters

$args

mixed

parameters, can be null, a string (if an $_idField has been declared), or an array

$select

string

select fields, by default all

$groupby

string

the groupby clause

$selectAdd

string

additional fields to fetch, optionnal

Returns

mixednull if any, an object of the current DAO name if only one DBResult, or an array if more

Deletes row(s) from the database

delete(mixed $args, string $limit) : boolean
access public
author Pierre-Alain Mignot

Parameters

$args

mixed

parameters, can be a string (if an $_idField has been declared), an object or an array, optionnal

$limit

string

the limit clause

Returns

booleantrue on success

Gets rows from the database

get(mixed $args, string $select, string $order, string $groupby, string $limit) : mixed
access public
author Pierre-Alain Mignot

Parameters

$args

mixed

parameters, can be a string (if an $_idField has been declared), an object or an array, optionnal

$select

string

select fields, by default all

$order

string

the order clause

$groupby

string

the groupby clause

$limit

string

the limit clause

Returns

mixednull if any, an object of the current DAO name if only one DBResult, or an array if more

Returns all the relations

getAllRelations() : array
access public
author Pierre-Alain Mignot

Returns

arrayall the relations for this table

Returns the specified DAO object This function accepts an ID and will return the DAO for the corresponding type

getById(int $id) : mixed
Static
access public
static
author Pierre-Alain Mignot

Parameters

$id

int

the id of the object

Returns

mixedthe DAO object if found, else false

Returns the specified DAO object from cache

getCachedDAO(string $dao) : mixed
Static
access public
static
author Pierre-Alain Mignot

Parameters

$dao

string

the name of the DAO

Returns

mixedthe DAO object

Returns the specified DAO object

getDAO(string $dao) : mixed
Static
access public
static
author Pierre-Alain Mignot

Parameters

$dao

string

the name of the DAO

Returns

mixedthe DAO object

Returns the fields

getFields() : array
access public
author Pierre-Alain Mignot

Returns

arraythe fields for this object

Returns the id field

getIdField() : string
access public
author Pierre-Alain Mignot

Returns

stringthe id field for this object

Returns the relations

getRelations() : array
access public
author Pierre-Alain Mignot

Returns

arraythe relations for this table

Returns the name of the table for $this

getTableName() : string
access public
author Pierre-Alain Mignot

Returns

stringthe name of the table relative to $this

Returns the type relative to the specified id This method also checks for user rights to read it

getType(int $id) : mixed
Static
author Pierre-Alain Mignot
access public
static

Parameters

$id

int

the id to get type from

Returns

mixedfalse on error, or the type corresponding to the id

Returns the unique fields

getUniqueFields() : array
access public
author Pierre-Alain Mignot

Returns

arraythe unique fields for this object

Returns the relations related to the current user

getUserRelations() : array
access public
author Pierre-Alain Mignot

Returns

arraythe relations for the current user for this table

Returns the weight

getWeight() : int
access public
author Pierre-Alain Mignot

Returns

intthe weight for this table

Populates values into this object

populate(mixed $obj) : boolean
access public
author Pierre-Alain Mignot

Parameters

$obj

mixed

the values to populate

Returns

booleantrue on success

Saves a row into the database

save(boolean $ignore) : mixed
access public
author Pierre-Alain Mignot

Parameters

$ignore

boolean

if we must save with a INSERT IGNORE clause instead of REPLACE INTO if no $_idField has been declared

Returns

mixedif success true if no $_idField declared or the value of the $_idField

Constructor, sets the name/fullname of the instance, and set the DB obj Also it will try to fetch tablefields from cache, or generate what we need and cache it

__construct() 
access public
author Pierre-Alain Mignot

Fetches all results from DB, either in numerical array, associative array or object

_fetch(string $query, \OWR\DB\Request $request, string $fetchType, boolean $force) : mixed
author Pierre-Alain Mignot
access protected

Parameters

$query

string

the SQL query

$request

\OWR\OWR\DB\Request

DBRequest the request

$fetchType

string

can be assoc, array or object

$force

boolean

used to say to the DB object that we must use prepared query

Returns

mixedempty array or one result or an array of results

Returns the JOIN conditions This method tries to order the JOIN conditions to get better performance results

_optimizeJoins(array $joins) : array
author Pierre-Alain Mignot
access protected

Parameters

$joins

array

the tables to join

Returns

arraythe JOIN conditions

Finalize the building of the SQL query

_prepareQuery(string $query, array $wheres, array $joins, string $groupby, string $order, string $limit) 
author Pierre-Alain Mignot
access protected
todo clean up the code

Parameters

$query

string

the sql query

$wheres

array

the WHERE clause fields

$joins

array

the JOIN clause fields

$groupby

string

the GROUP BY clause

$order

string

the ORDER clause

$limit

string

the LIMIT clause

Prepares the SELECT clauses for a query

_prepareSelect(string $selects, array $joins, array $wheres) 
author Pierre-Alain Mignot
access protected
todo clean up the code

Parameters

$selects

string

select fields, by default all

$joins

array

&$joins the JOIN clause fields

$wheres

array

&$wheres the WHERE clause fields

Prepares the WHERE clauses for a query

_prepareWhere(array $args, array $request, array $fields, array $wheres, array $joins) 
author Pierre-Alain Mignot
access protected
todo clean up the code

Parameters

$args

array

parameters

$request

array

&$request the fields to SELECT

$fields

array

&$fields the fields definition

$wheres

array

&$wheres the WHERE fields

$joins

array

&$joins the JOIN conditions

 Properties

 

the DB instance

$_db : mixed
access protected
static
 

the list of fields of the table

$_fields : array
access protected
 

the class name

$_fullName : string
access protected
 

the name of the field used to have a unique ID

$_idField : string
access protected
 

the table name

$_name : string
access protected
 

associative array of name => field for each relations table

$_relations : array
access protected
 

associative array representing the SQL schema

$_tableFields : array
access protected
 

stored results of already processed queries about id=>type

$_types : array
access protected
static
 

the list of unique fields of the table

$_uniqueFields : array
access protected
 

associative array of name => field for each user's relations table

$_userRelations : array
access protected
 

weight of the table in the query, used to optimize joins

$_weight : int
access protected
 

stored already processed dao objects

$_cachedDaos : array
access private
static
 

stored already processed dao names

$_daos : array
access private
static