.

DBQueryJoined Class Reference
[Model]

A query that gets joined to another. More...

Inheritance diagram for DBQueryJoined:
DBQuerySelect DBQueryOrdered DBQueryLimited DBQuery IDBQuery IDBSqlBuilder IPolicyHolder IDBWhereHolder

List of all members.

Public Member Functions

  __construct (IDBTable $table, DBQuery $parent_query, $join_type=self::INNER, $policy=self::AUTODETECT_CONDITIONS)
  add_join_condition ($this_field, $parent_field, $mode=IDBWhere::LOGIC_AND)
  Add join condition.
  add_join_condition_object (IDBWhere $condition)
  Add join condition.
  get_join_conditions ()
  Returns Join Conditons.
  get_join_type ()
  Returns type of join.
  get_relation_type ()
  Returns type of relation, one of DBRelation's constant.
  set_join_type ($join_type)
  Sets join type.

Public Attributes

const  AUTODETECT_CONDITIONS = 128
  Policy to detect join condition fields.
const  INNER = 0
  INNER JOIN.
const  LEFT = 1
  LEFT JOIN.
const  RIGHT = 2
  RIGHT JOIN.

Protected Member Functions

  compute_join_conditions ()
  get_relations ()

Protected Attributes

  $join_conditions
  $join_type
  $parent_query
  $relations = false

Detailed Description

A query that gets joined to another.

Author:
Gerd Riesselmann

Definition at line 10 of file dbquery.joined.cls.php.


Constructor & Destructor Documentation

DBQueryJoined::__construct ( IDBTable table,
DBQuery parent_query,
join_type = self::INNER,
policy = self::AUTODETECT_CONDITIONS  
)

Definition at line 57 of file dbquery.joined.cls.php.

00057                                                                                                                                          {
00058                 parent::__construct($table, $policy);
00059                 $this->parent_query = $parent_query;
00060                 $this->join_type = $join_type;
00061                 $this->join_conditions = new DBWhereGroup($table);
00062         }

Member Function Documentation

DBQueryJoined::add_join_condition ( this_field,
parent_field,
mode = IDBWhere::LOGIC_AND  
)

Add join condition.

Parameters:
string  $this_field Field on this (the joined) table
string  $parent_field Field on parent table (the table joined to)
string  $mode Either AND or OR
Returns:
DBJoinCondition

Definition at line 90 of file dbquery.joined.cls.php.

00090                                                                                                   {
00091                 $condition = new DBJoinCondition($this->get_table(), $this_field, $this->parent_query->get_table(), $parent_field, $mode);
00092                 $this->add_join_condition_object($condition);
00093                 return $condition;
00094         }
DBQueryJoined::add_join_condition_object ( IDBWhere condition  ) 

Add join condition.

Parameters:
IDBWhere  $condition

Definition at line 101 of file dbquery.joined.cls.php.

00101                                                                        {
00102                 $this->join_conditions->add_where_object($condition); 
00103         }
DBQueryJoined::compute_join_conditions (  )  [protected]

Definition at line 118 of file dbquery.joined.cls.php.

00118                                                      {
00119                 $parent = $this->get_table();
00120                 $child = $this->parent_query->get_table();
00121                 
00122                 $ret = new DBWhereGroup($parent);
00123                 
00124                 $relations = $this->get_relations();
00125                 foreach($relations as $relation) {
00126                         foreach($relation->get_fields() as $fieldrelation) {
00127                                 $ret->add_where_object(
00128                                         new DBJoinCondition(
00129                                                 $parent,
00130                                                 $fieldrelation->get_source_field_name(),
00131                                                 $child,
00132                                                 $fieldrelation->get_target_field_name()
00133                                         )
00134                                 );                      
00135                         }
00136                 }
00137                 return $ret;
00138         }
DBQueryJoined::get_join_conditions (  ) 

Returns Join Conditons.

Returns:
DBWhereGroup

Definition at line 110 of file dbquery.joined.cls.php.

00110                                               {
00111                 $ret = $this->join_conditions;
00112                 if ($this->has_policy(self::AUTODETECT_CONDITIONS)) {
00113                         $ret->add_where_object($this->compute_join_conditions());
00114                 }
00115                 return $ret;
00116         }
DBQueryJoined::get_join_type (  ) 

Returns type of join.

Returns:
int

Definition at line 78 of file dbquery.joined.cls.php.

00078                                         {
00079                 return $this->join_type;
00080         }
DBQueryJoined::get_relation_type (  ) 

Returns type of relation, one of DBRelation's constant.

Definition at line 150 of file dbquery.joined.cls.php.

00150                                             {
00151                 $types = array();
00152                 $relations = $this->get_relations();
00153                 foreach($relations as $relation) {
00154                         /* @var $relation DBRelation */
00155                         $types[$relation->get_type()] = $relation->get_type();  
00156                 }
00157                 return count($types) ? max($types) : DBRelation::MANY_TO_MANY;
00158         }
DBQueryJoined::get_relations (  )  [protected]

Definition at line 140 of file dbquery.joined.cls.php.

00140                                            {
00141                 if (!is_array($this->relations)) {
00142                         $this->relations = $this->get_table()->get_matching_relations($this->parent_query->get_table());
00143                 }
00144                 return $this->relations;
00145         }
DBQueryJoined::set_join_type ( join_type  ) 

Sets join type.

Parameters:
int  $join_type One of constants DBQueryJoined::INNER, DBJoinedQuery::LEFT etc

Definition at line 69 of file dbquery.joined.cls.php.

00069                                                   {
00070                 $this->join_type = $join_type;
00071         }

Member Data Documentation

DBQueryJoined::$join_conditions [protected]

Definition at line 47 of file dbquery.joined.cls.php.

DBQueryJoined::$join_type [protected]

Definition at line 33 of file dbquery.joined.cls.php.

DBQueryJoined::$parent_query [protected]

Definition at line 40 of file dbquery.joined.cls.php.

DBQueryJoined::$relations = false [protected]

Definition at line 54 of file dbquery.joined.cls.php.

Policy to detect join condition fields.

Definition at line 26 of file dbquery.joined.cls.php.

INNER JOIN.

Definition at line 14 of file dbquery.joined.cls.php.

LEFT JOIN.

Definition at line 18 of file dbquery.joined.cls.php.

RIGHT JOIN.

Definition at line 22 of file dbquery.joined.cls.php.


The documentation for this class was generated from the following file: