Project

General

Profile

Download (3.26 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id$
3

    
4
/**
5
* Copyright (C) 2007 EDIT
6
* European Distributed Institute of Taxonomy 
7
* http://www.e-taxonomy.eu
8
* 
9
* The contents of this file are subject to the Mozilla Public License Version 1.1
10
* See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
11
*/
12

    
13
class FootnoteManager
14
{
15
  
16
    
17
    private static $fnstore = array();
18
    
19
    private static $nextFootnoteKey = 1;
20
    
21
    // private constructor
22
    private function __construct() {
23
      
24
    }
25

    
26
 
27
    /**
28
     * @param $footnoteListKey a string as key to the list of footnotes
29
     * @return an array of footnotes objects
30
     *  
31
     */
32
    public static function getFootnoteList($footnoteListKey){
33
      return array_key_exists($footnoteListKey, self::$fnstore) ? self::$fnstore[$footnoteListKey] : NULL;
34
    }
35
    
36
    /**
37
     * 
38
     * @param $footnoteListKey a string as key to the list of footnotes
39
     * @return
40
     */
41
    public static function removeFootnoteList($footnoteListKey){
42
      if(array_key_exists($footnoteListKey, self::$fnstore)) {
43
	      unset(self::$fnstore[$footnoteListKey]);
44
      }
45
    }
46
    
47
    /**
48
     * 
49
     * @param $footnoteListKey
50
     * @param $separator
51
     * @return the rendered footnotelist
52
     */
53
    public static function renderFootnoteList($footnoteListKey, $separator = ', '){
54
      $out = '';
55
      if(array_key_exists($footnoteListKey, self::$fnstore)){
56
        foreach(self::$fnstore[$footnoteListKey] as $fn){
57
          $out .= $fn->doRender() . $separator;
58
        }
59
        $out = substr($out, 0, strlen($out)-strlen($separator));
60
      }
61
      return $out;
62
    }
63
    
64
    /**
65
     * 
66
     * @param $footnoteListKey
67
     * @param $object
68
     * @param $theme
69
     * @param $themeArguments
70
     * @return unknown_type
71
     */
72
    public static function addNewFootnote($footnoteListKey, $object = null, $theme = NULL, $themeArguments = array()){
73

    
74
      if(!$object){
75
      	return false;
76
      }
77
      if(!array_key_exists($footnoteListKey, self::$fnstore)){
78
          self::$fnstore[$footnoteListKey] = array();
79
      }
80
      
81
      $fnKey = NULL;
82
      if( !($fnKey = self::footnoteExists($footnoteListKey, $object)) ){
83
        $fnKey = self::$nextFootnoteKey++;
84
        $fn = new Footnote($fnKey, $object, $theme, $themeArguments);
85
        self::$fnstore[$footnoteListKey][$fnKey] = $fn;
86
        
87
      }
88
      
89
      return new FootnoteKey($fnKey, $footnoteListKey);
90
    }
91
    
92
    /**
93
     * 
94
     * @param $footnoteListKey
95
     * @param $object
96
     * @return unknown_type
97
     */
98
    private static function footnoteExists($footnoteListKey, $object){
99
      foreach(self::$fnstore[$footnoteListKey] as $key=>$fn){
100
        /**
101
         * When using the comparison operator (==), object variables are compared in a simple manner, namely: 
102
         * Two object instances are equal if they have the same attributes and values, and are instances of the same class. 
103
         */
104
        if($object == $fn->object){
105
          return $key;
106
        }
107
      }
108
      return FALSE;
109
    }
110
    
111
    // stop users from cloning
112
    public function __clone() {
113
      
114
        trigger_error('Cloning instances of the singleton class FootNoteManager is prohibited', E_USER_ERROR);
115
    }
116

    
117
}
(3-3/4)