commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / views / modules / translation / views_handler_relationship_translation.inc
1 <?php
2
3 /**
4 * @file
5 * Definition of views_handler_relationship_translation.
6 */
7
8 /**
9 * Handles relationships for content translation sets and provides multiple
10 * options.
11 *
12 * @ingroup views_relationship_handlers
13 */
14 class views_handler_relationship_translation extends views_handler_relationship {
15 function option_definition() {
16 $options = parent::option_definition();
17 $options['language'] = array('default' => 'current');
18
19 return $options;
20 }
21
22 /**
23 * Add a translation selector.
24 */
25 function options_form(&$form, &$form_state) {
26 parent::options_form($form, $form_state);
27
28 $options = array(
29 'all' => t('All'),
30 'current' => t('Current language'),
31 'default' => t('Default language'),
32 );
33 $options = array_merge($options, locale_language_list());
34 $form['language'] = array(
35 '#type' => 'select',
36 '#options' => $options,
37 '#default_value' => $this->options['language'],
38 '#title' => t('Translation option'),
39 '#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.'),
40 );
41 }
42
43 /**
44 * Called to implement a relationship in a query.
45 */
46 function query() {
47 // Figure out what base table this relationship brings to the party.
48 $table_data = views_fetch_data($this->definition['base']);
49 $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
50
51 $this->ensure_my_table();
52
53 $def = $this->definition;
54 $def['table'] = $this->definition['base'];
55 $def['field'] = $base_field;
56 $def['left_table'] = $this->table_alias;
57 $def['left_field'] = $this->field;
58 if (!empty($this->options['required'])) {
59 $def['type'] = 'INNER';
60 }
61
62 $def['extra'] = array();
63 if ($this->options['language'] != 'all') {
64 switch ($this->options['language']) {
65 case 'current':
66 $def['extra'][] = array(
67 'field' => 'language',
68 'value' => '***CURRENT_LANGUAGE***',
69 );
70 break;
71 case 'default':
72 $def['extra'][] = array(
73 'field' => 'language',
74 'value' => '***DEFAULT_LANGUAGE***',
75 );
76 break;
77 // Other values will be the language codes.
78 default:
79 $def['extra'][] = array(
80 'field' => 'language',
81 'value' => $this->options['language'],
82 );
83 break;
84 }
85 }
86
87 if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
88 $join = new $def['join_handler'];
89 }
90 else {
91 $join = new views_join();
92 }
93
94 $join->definition = $def;
95 $join->construct();
96 $join->adjusted = TRUE;
97
98 // use a short alias for this:
99 $alias = $def['table'] . '_' . $this->table;
100
101 $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
102 }
103 }