Projet

Général

Profil

Paste
Télécharger (2,95 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panelizer / plugins / views / panelizer_handler_filter_panelizer_status.inc @ 13755f8d

1
<?php
2
/**
3
 * Filter by node type
4
 */
5
class panelizer_handler_filter_panelizer_status extends views_handler_filter_in_operator {
6
  function get_value_options() {
7
    if (!isset($this->value_options)) {
8
      $this->value_title = t('Panelizer defaults');
9
      $entity_info = entity_get_info($this->definition['entity_type']);
10

    
11
      // The normal get_panelizer_default_objects() requires a bundle type
12
      // but in a filter all we know for sure is the entity type. This
13
      // is going to make a bit of an awkward list, unfortunately.
14
      $conditions = array(
15
        'panelizer_type' => $this->definition['entity_type'],
16
      );
17

    
18
      ctools_include('export');
19
      $defaults = ctools_export_load_object('panelizer_defaults', 'conditions', $conditions);
20

    
21
      foreach ($defaults as $name => $default) {
22
        if (empty($default->title)) {
23
          $default->title = t('Default');
24
        }
25
        $options[$name] = t('@bundle: @title', array('@bundle' => $entity_info['bundles'][$default->panelizer_key]['label'], '@title' => $default->title));
26
      }
27
      natcasesort($options);
28
      $options = array(
29
        'not' => t('Not panelized'),
30
        'custom' => t('Customized'),
31
      ) + $options;
32

    
33
      $this->value_options = $options;
34
    }
35
  }
36

    
37
  function op_simple() {
38
    if (empty($this->value)) {
39
      return;
40
    }
41
    $this->ensure_my_table();
42

    
43
    $or = db_or();
44
    $values = $this->value;
45

    
46
    // @todo -- see if we need to use in_array() when a select is used.
47
    if (in_array('not', $values)) {
48
      if ($this->operator == 'in') {
49
        $or->condition(
50
          db_and()
51
            ->condition("$this->table_alias.$this->real_field", NULL)
52
            ->condition("$this->table_alias.did", 0)
53
        );
54
      }
55
      else {
56
        $or->condition(
57
          db_or()
58
            ->isNotNull("$this->table_alias.$this->real_field")
59
            ->condition(db_and()
60
              ->isNull("$this->table_alias.$this->real_field")
61
              ->condition("$this->table_alias.did", 0, '!=')
62
            )
63
        );
64
      }
65
      unset($values['not']);
66
    }
67

    
68
    if (in_array('custom', $values)) {
69
      if ($this->operator == 'in') {
70
        $or->condition(
71
          db_and()
72
            ->condition("$this->table_alias.$this->real_field", NULL)
73
            ->condition("$this->table_alias.did", 0, '!=')
74
        );
75
      }
76
      else {
77
        $or->condition(
78
          db_or()
79
            ->isNotNull("$this->table_alias.$this->real_field")
80
            ->condition(db_and()
81
              ->isNull("$this->table_alias.$this->real_field")
82
              ->condition("$this->table_alias.did", 0, '=')
83
            )
84
        );
85
      }
86
      unset($values['custom']);
87
    }
88

    
89
    if ($values) {
90
      $or->condition("$this->table_alias.$this->real_field", array_values($values), $this->operator);
91
    }
92

    
93
    // We use array_values() because the checkboxes keep keys and that can cause
94
    // array addition problems.
95
    $this->query->add_where($this->options['group'], $or);
96
  }
97

    
98
}