Project

General

Profile

Download (2.92 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 wich 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 begining 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

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

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

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

    
61
  /**
62
   * @todo document this function.
63
   */
64
  public static function setFootnoteListKey($key) {
65
    self::$footnoteListKey = $key;
66
  }
67

    
68
  /**
69
   * Reset the FootnoteListKey to the default value = 'PAGE_GLOBAL'
70
   */
71
  public static function clearFootnoteListKey() {
72
    self::$footnoteListKey = self::$footnoteListKeyDefault;
73
  }
74

    
75
  /**
76
   * @todo document this function.
77
   */
78
  public static function pushToRenderStack($pathelement) {
79
    array_push(self::$renderStack, $pathelement);
80
  }
81

    
82
  /**
83
   * @todo document this function.
84
   */
85
  public static function popFromRenderStack() {
86
    return array_pop(self::$renderStack);
87
  }
88

    
89
  /**
90
   * @todo document this function.
91
   */
92
  public static function sizeof() {
93
    return sizeof(self::$renderStack);
94
  }
95

    
96
  /**
97
   * @todo document this function.
98
   */
99
  public static function getRenderPath() {
100
    return join('.', array_reverse(self::$renderStack));
101
  }
102

    
103
  /**
104
   * @todo document this function.
105
   */
106
  public static function getHtmlElementID($cdmBase) {
107
    return 'id="' . RenderHints::getRenderPath() . '(' . $cdmBase->class . ':' . $cdmBase->uuid . ')"';
108
  }
109

    
110
  /**
111
   * Stop users from cloning.
112
   */
113
  public function __clone() {
114
    trigger_error('Cloning instances of the singleton class RenderHints is prohibited', E_USER_ERROR);
115
  }
116
}
(8-8/8)