\Hylax_SQL_Attributes

This class provides attributes methods for any existing SQL class.

Copyright 1999-2017 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Summary

Methods
Properties
Constants
Hylax_SQL_Attributes()
getAttributes()
getByAttributes()
insertAttributes()
deleteAttributes()
updateAttributes()
_buildAttributeQuery()
_getAlias()
$_db
$_params
$_table_count
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$_db

$_db : \DB

The PEAR::DB object to run queries with.

Type

\DB

$_params

$_params : array

Parameters to use when generating queries: id_column - The primary id column to use in joins.

primary_table - The main table name. attribute_table - The table that the attributes are stored in.

Type

array

$_table_count

$_table_count : integer

The number of copies of the attributes table that we need to join on in the current query.

Type

integer

Methods

Hylax_SQL_Attributes()

Hylax_SQL_Attributes(\DB  $dbh, array  $params) 

Constructor.

Parameters

\DB $dbh

A PEAR::DB object.

array $params

The id column, table names, etc.

getAttributes()

getAttributes(  $id) : array

Returns all attributes for a given id or multiple ids.

Parameters

$id

Returns

array —

A hash of attributes, or a multi-level hash of ids => their attributes.

getByAttributes()

getByAttributes(array  $criteria) 

Return a set of ids based on a set of attribute criteria.

Parameters

array $criteria

The array of criteria. Example: $criteria['OR'] = array( array('field' => 'name', 'op' => '=', 'test' => 'foo'), array('field' => 'name', 'op' => '=', 'test' => 'bar')); This would return all ids for which the field attribute_name is either 'foo' or 'bar'.

insertAttributes()

insertAttributes(integer  $id, array  $attributes) 

Given a new attribute set and an id, insert each into the DB. If anything fails in here, rollback the transaction, return the relevant error and bail out.

Parameters

integer $id

The id of the record for which attributes are being inserted.

array $attributes

An hash containing the attributes.

deleteAttributes()

deleteAttributes(integer  $id) 

Given an id, delete all attributes for that id from the attributes table.

Parameters

integer $id

The id of the record for which attributes are being deleted.

updateAttributes()

updateAttributes(integer  $id, array  $attributes) 

Given an id, update all attributes for that id in the attributes table with the new attributes.

Parameters

integer $id

The id of the record for which attributes are being deleted.

array $attributes

An hash containing the attributes.

_buildAttributeQuery()

_buildAttributeQuery(string  $glue, array  $criteria, boolean  $join = false) : string

Build a piece of an attribute query.

Parameters

string $glue

The glue to join the criteria (OR/AND).

array $criteria

The array of criteria.

boolean $join

Should we join on a clean attributes table?

Returns

string —

An SQL fragment.

_getAlias()

_getAlias(boolean  $increment = false) 

Get an alias to an attributes table, incrementing it if necessary.

Parameters

boolean $increment

Increment the alias count? Defaults to false.