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

handlers/views_handler_field_entity.inc

00001 <?php
00013 class views_handler_field_entity extends views_handler_field {
00014 
00018   public $entity_type;
00019 
00023   public $entities;
00024 
00028   public $base_field;
00029 
00033   public function init(&$view, &$options) {
00034     parent::init($view, $options);
00035 
00036     // Initialize the entity-type used.
00037     $table_data = views_fetch_data($this->table);
00038     $this->entity_type = $table_data['table']['entity type'];
00039   }
00040 
00044   function query() {
00045     $this->table_alias = $base_table = $this->view->base_table;
00046     $this->base_field = $this->view->base_field;
00047 
00048     if (!empty($this->relationship)) {
00049       foreach ($this->view->relationship as $relationship) {
00050         if ($relationship->alias == $this->relationship) {
00051           $base_table = $relationship->definition['base'];
00052           $this->table_alias = $relationship->alias;
00053 
00054           $table_data = views_fetch_data($base_table);
00055           $this->base_field = empty($relationship->definition['base field']) ? $table_data['table']['base']['field'] : $relationship->definition['base field'];
00056         }
00057       }
00058     }
00059 
00060     // Add the field if the query back-end implements an add_field() method,
00061     // just like the default back-end.
00062     if (method_exists($this->query, 'add_field')) {
00063       $this->field_alias = $this->query->add_field($this->table_alias, $this->base_field, '');
00064     }
00065 
00066     $this->add_additional_fields();
00067   }
00068 
00072   function pre_render(&$values) {
00073     if (!empty($values)) {
00074       list($this->entity_type, $this->entities) = $this->query->get_result_entities($values, !empty($this->relationship) ? $this->relationship : NULL, $this->field_alias);
00075     }
00076   }
00077 
00081   function get_value($values, $field = NULL) {
00082     if (isset($this->entities[$this->view->row_index])) {
00083       $entity = $this->entities[$this->view->row_index];
00084       // Support to get a certain part of the entity.
00085       if (isset($field) && isset($entity->{$field})) {
00086         return $entity->{$field};
00087       }
00088       // Support to get a part of the values as the normal get_value.
00089       elseif (isset($field) && isset($values->{$this->aliases[$field]})) {
00090         return $values->{$this->aliases[$field]};
00091       }
00092       else {
00093         return $entity;
00094       }
00095     }
00096     return FALSE;
00097   }
00098 }

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