tmgmt_node_handler_filter_missing_translation.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @file
  4. * Definition of tmgmt_node_handler_filter_missing_translation.
  5. */
  6. /**
  7. * Filter by language.
  8. *
  9. * @ingroup views_filter_handlers
  10. */
  11. class tmgmt_node_handler_filter_missing_translation extends views_handler_filter {
  12. /**
  13. * The target status to use for the query.
  14. *
  15. * @var string
  16. */
  17. protected $target_status = 'untranslated_or_outdated';
  18. /**
  19. * {@inheritdoc}
  20. */
  21. function query() {
  22. $this->ensure_my_table();
  23. // Don't do anything if no language was selected.
  24. if (!$this->value) {
  25. return;
  26. }
  27. $join = new views_join();
  28. $join->definition['left_table'] = $this->table_alias;
  29. $join->definition['left_field'] = $this->real_field;
  30. $join->definition['table'] = 'node';
  31. $join->definition['field'] = 'tnid';
  32. $join->definition['type'] = 'LEFT';
  33. $join->construct();
  34. $join->extra = array(array(
  35. 'field' => 'language',
  36. 'value' => $this->value,
  37. ));
  38. $table_alias = $this->query->add_table('node', $this->relationship, $join);
  39. $this->query->add_where_expression($this->options['group'], "{$this->table_alias}.language != :language", array(':language' => $this->value));
  40. if ($this->target_status == 'untranslated_or_outdated') {
  41. $this->query->add_where_expression($this->options['group'], "($table_alias.nid IS NULL OR {$this->table_alias}.translate = 1)");
  42. }
  43. elseif ($this->target_status == 'outdated') {
  44. $this->query->add_where_expression($this->options['group'], "{$this->table_alias}.translate = 1");
  45. }
  46. elseif ($this->target_status == 'untranslated') {
  47. $this->query->add_where_expression($this->options['group'], "$table_alias.nid IS NULL");
  48. }
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. function value_form(&$form, &$form_state) {
  54. $options = array();
  55. foreach (language_list() as $langcode => $language) {
  56. $options[$langcode] = $language->name;
  57. }
  58. $identifier = $this->options['expose']['identifier'];
  59. $form['value'][$identifier] = array(
  60. '#type' => 'select',
  61. '#options' => $options,
  62. '#empty_option' => t('Any'),
  63. '#id' => 'tmgmt_node_missing_target_language',
  64. '#element_validate' => array('tmgmt_node_views_exposed_target_language_validate'),
  65. );
  66. // Attach css to style the target_status element inline.
  67. $form['#attached']['css'][] = drupal_get_path('module', 'tmgmt_node_ui') . '/tmgmt_node_ui.source_overview.css';
  68. $form['value']['target_status'] = array(
  69. '#type' => 'select',
  70. '#title' => t('Target status'),
  71. '#options' => array(
  72. 'untranslated_or_outdated' => t('Untranslated or outdated'),
  73. 'untranslated' => t('Untranslated'),
  74. 'outdated' => t('Outdated'),
  75. ),
  76. '#states' => array(
  77. 'invisible' => array(
  78. ':input[id="tmgmt_node_missing_target_language"]' => array('value' => ''),
  79. ),
  80. ),
  81. );
  82. }
  83. /**
  84. * {@inheritdoc}
  85. */
  86. function accept_exposed_input($input) {
  87. $return = parent::accept_exposed_input($input);
  88. if ($return && isset($input['target_status'])) {
  89. $this->target_status = $input['target_status'];
  90. }
  91. return $return;
  92. }
  93. }