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

modules/translation/views_handler_relationship_translation.inc

00001 <?php
00002 
00009 class views_handler_relationship_translation extends views_handler_relationship {
00010   function option_definition() {
00011     $options = parent::option_definition();
00012     $options['language'] = array('default' => 'current');
00013 
00014     return $options;
00015   }
00016 
00020   function options_form(&$form, &$form_state) {
00021     parent::options_form($form, $form_state);
00022 
00023     $options = array(
00024       'all' => t('All'),
00025       'current' => t('Current language'),
00026       'default' => t('Default language'),
00027     );
00028     $options = array_merge($options, locale_language_list());
00029     $form['language'] = array(
00030       '#type' => 'select',
00031       '#options' => $options,
00032       '#default_value' => $this->options['language'],
00033       '#title' => t('Translation option'),
00034       '#description' => t('The translation options allows you to select which translation or translations in a translation set join on. Select "Current language" or "Default language" to join on the translation in the current or default language respectively. Select a specific language to join on a translation in that language. If you select "All", each translation will create a new row, which may appear to cause duplicates.'),
00035     );
00036   }
00037 
00041   function query() {
00042     // Figure out what base table this relationship brings to the party.
00043     $table_data = views_fetch_data($this->definition['base']);
00044     $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
00045 
00046     $this->ensure_my_table();
00047 
00048     $def = $this->definition;
00049     $def['table'] = $this->definition['base'];
00050     $def['field'] = $base_field;
00051     $def['left_table'] = $this->table_alias;
00052     $def['left_field'] = $this->field;
00053     if (!empty($this->options['required'])) {
00054       $def['type'] = 'INNER';
00055     }
00056 
00057     $def['extra'] = array();
00058     if ($this->options['language'] != 'all') {
00059       switch ($this->options['language']) {
00060         case 'current':
00061           $def['extra'][] = array(
00062             'field' => 'language',
00063             'value' => '***CURRENT_LANGUAGE***',
00064           );
00065           break;
00066         case 'default':
00067           $def['extra'][] = array(
00068             'field' => 'language',
00069             'value' => '***DEFAULT_LANGUAGE***',
00070           );
00071           break;
00072         // Other values will be the language codes.
00073         default:
00074           $def['extra'][] = array(
00075             'field' => 'language',
00076             'value' => $this->options['language'],
00077           );
00078           break;
00079       }
00080     }
00081 
00082     if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
00083       $join = new $def['join_handler'];
00084     }
00085     else {
00086       $join = new views_join();
00087     }
00088 
00089     $join->definition = $def;
00090     $join->construct();
00091     $join->adjusted = TRUE;
00092 
00093     // use a short alias for this:
00094     $alias = $def['table'] . '_' . $this->table;
00095 
00096     $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
00097   }
00098 }

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