• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/field/views_handler_relationship_entity_reverse.inc

Go to the documentation of this file.
00001 <?php
00012 class views_handler_relationship_entity_reverse extends views_handler_relationship  {
00013   function init(&$view, &$options) {
00014     parent::init($view, $options);
00015 
00016     $this->field_info = field_info_field($this->definition['field_name']);
00017   }
00018 
00022   function query() {
00023     $this->ensure_my_table();
00024     // First, relate our base table to the current base table to the
00025     // field, using the base table's id field to the field's column.
00026     $views_data = views_fetch_data($this->table);
00027     $left_field = $views_data['table']['base']['field'];
00028 
00029     $first = array(
00030       'left_table' => $this->table_alias,
00031       'left_field' => $left_field,
00032       'table' => $this->definition['field table'],
00033       'field' => $this->definition['field field'],
00034     );
00035     if (!empty($this->options['required'])) {
00036       $first['type'] = 'INNER';
00037     }
00038 
00039     if (!empty($this->definition['join_extra'])) {
00040       $first['extra'] = $this->definition['join_extra'];
00041     }
00042 
00043     if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
00044       $first_join = new $this->definition['join_handler'];
00045     }
00046     else {
00047       $first_join = new views_join();
00048     }
00049     $first_join->definition = $first;
00050     $first_join->construct();
00051     $first_join->adjusted = TRUE;
00052 
00053     $this->first_alias = $this->query->add_table($this->definition['field table'], $this->relationship, $first_join);
00054 
00055     // Second, relate the field table to the entity specified using
00056     // the entity id on the field table and the entity's id field.
00057     $second = array(
00058       'left_table' => $this->first_alias,
00059       'left_field' => 'entity_id',
00060       'table' => $this->definition['base'],
00061       'field' => $this->definition['base field'],
00062     );
00063 
00064     if (!empty($this->options['required'])) {
00065       $second['type'] = 'INNER';
00066     }
00067 
00068     if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
00069       $second_join = new $this->definition['join_handler'];
00070     }
00071     else {
00072       $second_join = new views_join();
00073     }
00074     $second_join->definition = $second;
00075     $second_join->construct();
00076     $second_join->adjusted = TRUE;
00077 
00078     // use a short alias for this:
00079     $alias = $this->definition['field_name'] . '_' . $this->table;
00080 
00081     $this->alias = $this->query->add_relationship($alias, $second_join, $this->definition['base'], $this->relationship);
00082   }
00083 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1