AbstractJoin is the abstract base class from which concrete join classes can be derived in order to provide support for different styles of relational join.
More...
|
| add ($class) |
| Adds a class to the join definition. More...
|
|
| setFilter ($class, $filter) |
| Sets an InclusionFilter or ExclusionFilter on the specified class. More...
|
|
| constrain ($class, $constraint) |
| Sets a query constraint on the given class. More...
|
|
| excludeKeyFromJoin ($class, $key) |
| By default joins are generated following the "most restrictive search" principle. More...
|
|
| xref ($xref, $xrefFieldMaps=null) |
| Adds a cross-reference class to the join definition. More...
|
|
| pseudo ($class, $items, $indexField) |
| Registers a class and indexed array as a pseudo-join item. More...
|
|
| generateQuery ($constraint="", $count=false) |
|
| count ($constraints="", $countExpr=true) |
|
| query ($constraints="", $page=-1, $size=-1) |
| Performs a query against the database returning an array of JoinResult objects. More...
|
|
| iteratedQuery ($constraints="") |
| Performs a query against the database returning an iterator of JoinResult objects. More...
|
|
| indexedQuery ($constraints="", $indexBy="") |
| Performs a query against the database, returning an array of DataItem objects of the specified class, indexed by a particular field. More...
|
|
| groupedQuery ($constraints="", $indexBy="") |
| Performs a query against the database, returning an array of arrays of DataItem objects of the specified class, grouped by a particular field. More...
|
|
AbstractJoin is the abstract base class from which concrete join classes can be derived in order to provide support for different styles of relational join.
- Author
- andy
Definition at line 232 of file join.inc.
◆ add()
AbstractJoin::add |
( |
|
$class | ) |
|
Adds a class to the join definition.
Classes added using this method are included in the eventual result set.
- Parameters
-
string | $class | the name of the class to add to the join |
Filter | $filter | (optional) InclusionFilter or ExclusionFilter object defining the sub-set of fields to include |
Definition at line 256 of file join.inc.
258 $this->classes[] = $class;
260 $this->protos[$class] =
new $class;
262 if (func_num_args() > 1)
266 if (func_get_arg(1) !==
false)
268 for($i = 1; $i < func_num_args(); ++$i)
270 $filter->add(func_get_arg($i));
274 $this->protos[$class]->filter = $filter;
Used to place a filter on the contents of a DataItem-derived object.
◆ constrain()
AbstractJoin::constrain |
( |
|
$class, |
|
|
|
$constraint |
|
) |
| |
Sets a query constraint on the given class.
- Parameters
-
string | $class | the class to be constrained |
string | $constraint | the SQL constraint to be applied |
Definition at line 296 of file join.inc.
298 $this->constraints[$class] = $constraint;
◆ count()
AbstractJoin::count |
( |
|
$constraints = "" , |
|
|
|
$countExpr = true |
|
) |
| |
Definition at line 356 of file join.inc.
363 $result = $db->prepare($query);
364 $result->execute($this->params);
366 if ($row = $result->fetch())
368 $value = $row[
'result'];
373 catch(PDOException $e)
375 throw FakoliException($e->getMessage());
$constraints
Class-specific constraints add via the constrain() method.
generateQuery($constraint="", $count=false)
static getConnection()
Retrieves a reference to the global database connection.
◆ excludeKeyFromJoin()
AbstractJoin::excludeKeyFromJoin |
( |
|
$class, |
|
|
|
$key |
|
) |
| |
By default joins are generated following the "most restrictive search" principle.
This means that all matching foreign key/primary key pairs are used in the join constraint. You can use this method to override this behavior for a member of the join, specifying that a given key should not be used as part of the join constraint.
- Parameters
-
Definition at line 311 of file join.inc.
313 if (!isset($this->excludedKeys[$class]))
315 $this->excludedKeys[$class] = array();
318 $this->excludedKeys[$class][$key] =
true;
320 trace(
"*** Excluding $key on $class", 3);
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
◆ generateQuery()
AbstractJoin::generateQuery |
( |
|
$constraint = "" , |
|
|
|
$count = false |
|
) |
| |
|
abstract |
◆ groupedQuery()
AbstractJoin::groupedQuery |
( |
|
$constraints = "" , |
|
|
|
$indexBy = "" |
|
) |
| |
Performs a query against the database, returning an array of arrays of DataItem objects of the specified class, grouped by a particular field.
If the indexing field has unique values, indexedQuery() might be more appropriate.
- Parameters
-
string | $constraints | optional constraint clause to apply to the query in the form "WHERE ... [ORDER BY ...]" |
string | $field | optional the name of the field by which to group the results |
Definition at line 560 of file join.inc.
567 list($idxClass, $field) = explode(
".", $indexBy);
571 $idxClass = $this->
class[0];
573 $field = $obj->primary_key;
576 trace(
"groupedQuery(): Group by $idxClass $field", 3);
583 $result = $db->prepare($query);
588 while($line = $result->fetch())
592 for($i = 0; $i <
count($this->classes); ++$i)
594 $class = $this->classes[$i];
595 $item->$class =
new $class;
596 $item->$class->populate($line, $this->aliases[$item->$class->table]);
598 foreach($this->pseudos as $class => $lookup)
600 foreach($this->aliases as $table => $prefix)
602 $keyAlias =
"{$prefix}.{$lookup['index']}";
604 $key = $line[$keyAlias];
606 if (array_key_exists($key, $lookup[
'items']))
608 $item->$class = $lookup[
'items'][$key];
615 $idx = $item->$idxClass->$field;
616 $items[$idx][] = $item;
623 catch(PDOException $e)
625 throw new FakoliException($e->getMessage());
count($constraints="", $countExpr=true)
JoinResult is an empty placeholder class.
◆ indexedQuery()
AbstractJoin::indexedQuery |
( |
|
$constraints = "" , |
|
|
|
$indexBy = "" |
|
) |
| |
Performs a query against the database, returning an array of DataItem objects of the specified class, indexed by a particular field.
If more than one item is found that matches the same value of the indexing field, the results entry is promoted to an array automatically. However, in cases where this is common, using groupedQuery() might simplify your calling code.
- Parameters
-
string | $constraints | optional constraint clause to apply to the query in the form "WHERE ... [ORDER BY ...]" |
string | $field | optional the name of the field by which to index the results (See InclusionFilter and ExclusionFilter) |
Definition at line 475 of file join.inc.
482 list($idxClass, $field) = explode(
".", $indexBy);
486 $idxClass = $this->
class[0];
488 $field = $obj->primary_key;
496 $result = $db->prepare($query);
501 while($line = $result->fetch())
505 for($i = 0; $i <
count($this->classes); ++$i)
507 $class = $this->classes[$i];
508 $item->$class =
new $class;
509 $item->$class->populate($line, $this->aliases[$item->$class->table]);
511 foreach($this->pseudos as $class => $lookup)
513 foreach($this->aliases as $table => $prefix)
515 $keyAlias =
"{$prefix}.{$lookup['index']}";
517 $key = $line[$keyAlias];
519 if (array_key_exists($key, $lookup[
'items']))
521 $item->$class = $lookup[
'items'][$key];
528 $idx = $item->$idxClass->$field;
529 if (array_key_exists($idx, $items))
532 if (!is_array($items[$idx]))
534 $items[$idx] = array($items[$idx]);
536 $items[$idx][] = $item;
540 $items[$idx] = $item;
548 catch(PDOException $e)
550 throw new FakoliException($e->getMessage());
◆ iteratedQuery()
AbstractJoin::iteratedQuery |
( |
|
$constraints = "" | ) |
|
Performs a query against the database returning an iterator of JoinResult objects.
- Parameters
-
Definition at line 461 of file join.inc.
◆ pseudo()
AbstractJoin::pseudo |
( |
|
$class, |
|
|
|
$items, |
|
|
|
$indexField |
|
) |
| |
Registers a class and indexed array as a pseudo-join item.
Pseudo-joins are joined into the result set based on the supplied index field.
- Parameters
-
string | $class | Class name for the items being joined |
array | $items | array of DataItems indexed by the joining key (usually the primary key) |
string | $indexField | the field to be joined on |
Definition at line 349 of file join.inc.
351 $this->pseudos[$class] = array(
"index" => $indexField,
"items" => $items);
◆ query()
AbstractJoin::query |
( |
|
$constraints = "" , |
|
|
|
$page = -1 , |
|
|
|
$size = -1 |
|
) |
| |
Performs a query against the database returning an array of JoinResult objects.
- Parameters
-
string | $constraints | |
integer | $page | |
integer | $size | |
Definition at line 387 of file join.inc.
394 $result = $db->prepare($query);
399 $count = ($page - 1) * $size;
408 while($line = $result->fetch())
412 for($i = 0; $i <
count($this->classes); ++$i)
414 $class = $this->classes[$i];
415 $item->$class =
new $class;
416 $item->$class->populate($line, $this->aliases[$item->$class->table]);
418 foreach($this->pseudos as $class => $lookup)
420 foreach($this->aliases as $table => $prefix)
422 $keyAlias =
"{$prefix}.{$lookup['index']}";
424 if (!array_key_exists($keyAlias, $line))
continue;
426 $key = $line[$keyAlias];
431 if (array_key_exists($key, $lookup[
'items']))
434 $item->$class = $lookup[
'items'][$key];
441 if ($size == 0)
break;
451 catch(PDOException $e)
453 throw new FakoliException($e->getMessage());
◆ setFilter()
AbstractJoin::setFilter |
( |
|
$class, |
|
|
|
$filter |
|
) |
| |
◆ xref()
AbstractJoin::xref |
( |
|
$xref, |
|
|
|
$xrefFieldMaps = null |
|
) |
| |
Adds a cross-reference class to the join definition.
Classes added using this method are NOT included in the eventual result set.
- Parameters
-
Definition at line 330 of file join.inc.
$xrefFieldMaps
Cross-reference field map (to support cross-referencing through fields with differing names)
◆ $aliases
AbstractJoin::$aliases = array() |
Field aliases for output.
Definition at line 240 of file join.inc.
◆ $classes
AbstractJoin::$classes = array() |
◆ $constraints
AbstractJoin::$constraints = array() |
◆ $excludedKeys
AbstractJoin::$excludedKeys = array() |
◆ $protos
AbstractJoin::$protos = array() |
Prototype instances of the DataItem classes being joined.
Definition at line 235 of file join.inc.
◆ $pseudos
AbstractJoin::$pseudos = array() |
Pseudo-join lookup tables.
Definition at line 248 of file join.inc.
◆ $tag
AbstractJoin::$tag = "join" |
◆ $unique
AbstractJoin::$unique = false |
true to output distinct rows only
Definition at line 244 of file join.inc.
◆ $xrefAliases
AbstractJoin::$xrefAliases = array() |
Cross-reference table aliases.
Definition at line 241 of file join.inc.
◆ $xrefFieldMaps
AbstractJoin::$xrefFieldMaps = array() |
Cross-reference field map (to support cross-referencing through fields with differing names)
Definition at line 238 of file join.inc.
◆ $xrefs
AbstractJoin::$xrefs = array() |
Cross-reference classes (i.e. classes that are part of the join, but not the result)
Definition at line 236 of file join.inc.
The documentation for this class was generated from the following file:
- C:/code/cms.sonjara.com/framework/join.inc