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