Project

General

Profile

Download (5.47 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Singleton class to provide render hints.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15

    
16
/**
17
 * A Singleton class which holds and manages information on the render path in the
18
 * page element hierarchy and also stored the current FootnoteListKey.
19
 *
20
 * RenderPath:
21
 * The render path is manages as a stack.
22
 * Usually you will push a new element to this stack at the beginning of a theme
23
 * method: RenderHints::pushToRenderStack('mypageElement');
24
 * After the output is generated you again pop the current path element from the stack:
25
 * RenderHints::popFromRenderStack()
26
 * The current render path can be retrieved by @see getRenderPath().
27
 *
28
 * FootnoteListKey
29
 *
30
 */
31
class RenderHints {
32
  private static $renderStack = array();
33
  private static $footnoteListKey = '';
34
  private static $footnoteListKeyDefault = 'PAGE_GLOBAL';
35
  private static $annotationsAndSourceConfig = ANNOTATIONS_AND_SOURCE_CONFIG_DEFAULT;
36

    
37
  /**
38
   * Private constructor.
39
   */
40
  private function __construct() {}
41

    
42
  /**
43
   * @return string
44
   *   The FootnoteListKey as set or the default FootnoteListKey ('PAGE_GLOBAL')
45
   */
46
  public static function getFootnoteListKey() {
47
    if(self::$footnoteListKey){
48
      return self::$footnoteListKey;
49
    } else {
50
      return self::$footnoteListKeyDefault;
51
    }
52
  }
53

    
54
  /**
55
   * @return bool
56
   *   true if the FootnoteListKey is unset or reset (== $footnoteListKeyDefault)
57
   */
58
  public static function isUnsetFootnoteListKey() {
59
    return self::$footnoteListKey === self::$footnoteListKeyDefault;
60
  }
61

    
62
  /**
63
   * Set the new FootnoteList key.
64
   * The key which is replaced by the new value is returned.
65
   *
66
   * @param $key
67
   *  The new FootnoteListKey to set
68
   * @return string
69
   *  The last FootnoteListKey or NULL
70
   */
71
  public static function setFootnoteListKey($key) {
72
    $lastFnListKey = self::$footnoteListKey;
73
    self::$footnoteListKey = $key;
74
    return $lastFnListKey;
75
  }
76

    
77
  /**
78
   * Reset the FootnoteListKey to the default value = 'PAGE_GLOBAL'
79
   * An existing key which is cleared will be returned returned.
80
   * @return string
81
   *  The last FootnoteListKey or NULL
82
   */
83
  public static function clearFootnoteListKey() {
84
    $lastFnListKey = self::$footnoteListKey;
85
    self::$footnoteListKey = self::$footnoteListKeyDefault;
86
    return $lastFnListKey;
87
  }
88

    
89
  /**
90
   * Put the $pathelement onto the stack render hint
91
   * path elements to add a new named hierarchy level
92
   * in which the following render actions are taking
93
   * place.
94
   *
95
   * @param string $pathelement
96
   *    The element to put onto the stack of render elements.
97
   */
98
  public static function pushToRenderStack($pathelement) {
99
    array_push(self::$renderStack, $pathelement);
100
  }
101

    
102
  /**
103
   * Removes and returns the last element from the
104
   * render stack.
105
   *
106
   * @return string
107
   *      The element which has just been removed from the render stack.
108
   */
109
  public static function popFromRenderStack() {
110
    return array_pop(self::$renderStack);
111
  }
112

    
113
  /**
114
   * @return array
115
   */
116
  public static function getAnnotationsAndSourceConfig() {
117
    return self::$annotationsAndSourceConfig;
118
  }
119

    
120
  /**
121
   * Set the configuration for handling annotations and sources in the
122
   * current section of the page.
123
   *
124
   * This configuration is being used in handle_annotations_and_sources():
125
   *
126
   * @param array $annotationsAndSourceConfig
127
   *    The associative configuration array with the keys and boolean values:
128
   *      - 'sources_as_content' => TRUE|FALSE,
129
   *      - 'link_to_name_used_in_source' => TRUE|FALSE,
130
   *      - 'link_to_reference' => TRUE|FALSE,
131
   *      - 'add_footnote_keys' => TRUE|FALSE,
132
   *      - 'bibliography_aware' => TRUE|FALSE
133
   * @return array
134
   * the configuration array which has been set before.
135
   */
136
  public static function setAnnotationsAndSourceConfig($annotationsAndSourceConfig) {
137
    $lastConfig = self::$annotationsAndSourceConfig;
138
    self::$annotationsAndSourceConfig = $annotationsAndSourceConfig;
139
    return $lastConfig;
140
  }
141

    
142
  /**
143
   * Provides access to the size of the render stack.
144
   *
145
   * @return int
146
   *   The size of the render stack.
147
   */
148
  public static function renderStackSize() {
149
    return sizeof(self::$renderStack);
150
  }
151

    
152
  /**
153
   * Composes and returns the render path from the
154
   * elements on the stack.
155
   * The render path elements will be concatenated with the
156
   * dot '.' character.
157
   *
158
   * @return string
159
   *   The current render path.
160
   */
161
  public static function getRenderPath() {
162
    return join('.', array_reverse(self::$renderStack));
163
  }
164

    
165
  /**
166
   * Function to produce html id attribute values consistently for
167
   * the current render path and the passed cdm entity.
168
   *
169
   * @param $cdmBase
170
   *   The cdm entity.
171
   *
172
   * @return string
173
   *  The value for the DOM element id attribute composed from the current
174
   * render path and cdm entity class and uuid.
175
   *
176
   * @see html_class_attribute_ref()
177
   *
178
   * TODO: check, only used in theme_cdm_polytomousKey_linkedStyle_subgraph()
179
   *
180
   */
181
  public static function getHtmlElementID($cdmBase) {
182
    return 'id="' . RenderHints::getRenderPath() . '(' . $cdmBase->class . ':' . $cdmBase->uuid . ')"';
183
  }
184

    
185
  /**
186
   * Stop users from cloning.
187
   */
188
  public function __clone() {
189
    trigger_error('Cloning instances of the singleton class RenderHints is prohibited', E_USER_ERROR);
190
  }
191
}
(14-14/14)