~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to modules/views/includes/base.inc

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: base.inc,v 1.2 2008/06/06 19:29:03 merlinofchaos Exp $
 
3
/**
 
4
 * @file
 
5
 *
 
6
 * Provides the basic object definitions used by plugins and handlers.
 
7
 */
 
8
 
 
9
/**
 
10
 * Basic definition for many views objects
 
11
 */
 
12
class views_object {
 
13
  /**
 
14
   * Except for displays, options for the object will be held here.
 
15
   */
 
16
  var $options = array();
 
17
  /**
 
18
   * Information about options for all kinds of purposes will be held here.
 
19
   * @code
 
20
   * 'option_name' => array(
 
21
   *  - 'default' => default value,
 
22
   *  - 'translatable' => TRUE/FALSE (wrap in t() on export if true),
 
23
   *  - 'contains' => array of items this contains, with its own defaults, etc.
 
24
   *      If contains is set, the default will be ignored and assumed to
 
25
   *      be array()
 
26
   *
 
27
   *  ),
 
28
   *  @endcode
 
29
   * Each option may have any of the following functions:
 
30
   *  - export_option_OPTIONNAME -- Special export handling if necessary.
 
31
   *  - translate_option_OPTIONNAME -- Special handling for translating data
 
32
   *    within the option, if necessary.
 
33
   */
 
34
  function option_definition() { return array(); }
 
35
 
 
36
  /**
 
37
   * Views handlers use a special construct function so that we can more
 
38
   * easily construct them with variable arguments.
 
39
   */
 
40
  function construct() { $this->set_default_options(); }
 
41
 
 
42
  /**
 
43
   * Set default options on this object. Called by the constructor in a
 
44
   * complex chain to deal with backward compatibility.
 
45
   */
 
46
  function options() { }
 
47
 
 
48
  /**
 
49
   * Set default options.
 
50
   * For backward compatibility, it sends the options array; this is a
 
51
   * feature that will likely disappear at some point.
 
52
   */
 
53
  function set_default_options() {
 
54
    $this->_set_option_defaults($this->options, $this->option_definition());
 
55
 
 
56
    // Retained for complex defaults plus backward compatibility.
 
57
    $this->options($this->options);
 
58
  }
 
59
 
 
60
  function _set_option_defaults(&$storage, $options, $level = 0) {
 
61
    foreach ($options as $option => $definition) {
 
62
      if (isset($definition['contains']) && is_array($definition['contains'])) {
 
63
        $storage[$option] = array();
 
64
        $this->_set_option_defaults($storage[$option], $definition['contains'], $level++);
 
65
      }
 
66
      elseif (!empty($definition['translatable']) && !empty($definition['default'])) {
 
67
        $storage[$option] = t($definition['default']);
 
68
      }
 
69
      else {
 
70
        $storage[$option] = isset($definition['default']) ? $definition['default'] : NULL;
 
71
      }
 
72
    }
 
73
  }
 
74
 
 
75
  /**
 
76
   * Unpack options over our existing defaults, drilling down into arrays
 
77
   * so that defaults don't get totally blown away.
 
78
   */
 
79
  function unpack_options(&$storage, $options, $definition = NULL) {
 
80
    if (!is_array($options)) {
 
81
      return;
 
82
    }
 
83
 
 
84
    if (!isset($definition)) {
 
85
      $definition = $this->option_definition();
 
86
    }
 
87
 
 
88
    foreach ($options as $key => $value) {
 
89
      if (is_array($value)) {
 
90
        if (!isset($storage[$key]) || !is_array($storage[$key])) {
 
91
          $storage[$key] = array();
 
92
        }
 
93
 
 
94
        $this->unpack_options($storage[$key], $value, isset($definition[$key]) ? $definition[$key] : array());
 
95
      }
 
96
      else if (!empty($definition[$key]['translatable']) && !empty($value)) {
 
97
        $storage[$key] = t($value);
 
98
      }
 
99
      else {
 
100
        $storage[$key] = $value;
 
101
      }
 
102
    }
 
103
  }
 
104
 
 
105
  /**
 
106
   * Let the handler know what its full definition is.
 
107
   */
 
108
  function set_definition($definition) {
 
109
    $this->definition = $definition;
 
110
    if (isset($definition['field'])) {
 
111
      $this->real_field = $definition['field'];
 
112
    }
 
113
  }
 
114
 
 
115
  function destroy() {
 
116
    if (isset($this->view)) {
 
117
      unset($this->view);
 
118
    }
 
119
 
 
120
    if (isset($this->display)) {
 
121
      unset($this->display);
 
122
    }
 
123
 
 
124
    if (isset($this->query)) {
 
125
      unset($this->query);
 
126
    }
 
127
  }
 
128
}