public function join($query, $from_alias, $to_alias, $type = 'LEFT') { $prefix = $from_alias . '__' . $to_alias . '__'; // Loop on target entities : foreach ($this->joins as $trg_entity_name => $data1) { // Get entity object and build alias : $trg_entity = Glue_Entity::get($trg_entity_name); $trg_alias = $trg_entity_name === $this->to ? $to_alias : $prefix . $trg_entity_name; // Loop on source entities : $conds = array(); foreach ($data1 as $src_entity_name => $data2) { // Get entity object and build alias : $src_entity = Glue_Entity::get($src_entity_name); $src_alias = $src_entity_name === $this->from ? $from_alias : $prefix . $src_entity_name; // Loop on source entity fields : foreach ($data2 as $trg_field => $src_field) { $conds[] = array($trg_field, '=', $src_entity->query_field_expr($src_alias, $src_field)); } } // Join target entity : $trg_entity->query_join($query, $trg_alias, $type); foreach ($conds as $cond) { list($field, $op, $expr) = $cond; $query->on($trg_entity->query_field_expr($trg_alias, $field), $op, $expr); } } }
public static function entity($entity_name) { return Glue_Entity::get($entity_name); }