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
|
39
|
* @param $separator
|
40
|
* @return the rendered footnotelist
|
41
|
*/
|
42
|
public static function renderFootnoteList($footnoteListKey, $separator = ', '){
|
43
|
$out = '';
|
44
|
if(array_key_exists($footnoteListKey, self::$fnstore)){
|
45
|
foreach(self::$fnstore[$footnoteListKey] as $fn){
|
46
|
$out .= $fn->doRender() . $separator;
|
47
|
}
|
48
|
$out = substr($out, 0, strlen($out)-strlen($separator));
|
49
|
}
|
50
|
return $out;
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
*
|
55
|
* @param $footnoteListKey
|
56
|
* @param $object
|
57
|
* @param $theme
|
58
|
* @param $themeArguments
|
59
|
* @return unknown_type
|
60
|
*/
|
61
|
public static function addNewFootnote($footnoteListKey, $object, $theme = NULL, $themeArguments = array()){
|
62
|
|
63
|
if(!array_key_exists($footnoteListKey, self::$fnstore)){
|
64
|
self::$fnstore[$footnoteListKey] = array();
|
65
|
}
|
66
|
|
67
|
$fnKey = NULL;
|
68
|
if( !($fnKey = self::footnoteExists($footnoteListKey, $object)) ){
|
69
|
$fnKey = self::$nextFootnoteKey++;
|
70
|
$fn = new Footnote($fnKey, $object, $theme, $themeArguments);
|
71
|
self::$fnstore[$footnoteListKey][$fnKey] = $fn;
|
72
|
|
73
|
}
|
74
|
|
75
|
return $fnKey;
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
*
|
80
|
* @param $footnoteListKey
|
81
|
* @param $object
|
82
|
* @return unknown_type
|
83
|
*/
|
84
|
private static function footnoteExists($footnoteListKey, $object){
|
85
|
foreach(self::$fnstore[$footnoteListKey] as $key=>$fn){
|
86
|
/**
|
87
|
* When using the comparison operator (==), object variables are compared in a simple manner, namely:
|
88
|
* Two object instances are equal if they have the same attributes and values, and are instances of the same class.
|
89
|
*/
|
90
|
if($object == $fn->object){
|
91
|
return $key;
|
92
|
}
|
93
|
}
|
94
|
return FALSE;
|
95
|
}
|
96
|
|
97
|
// stop users from cloning
|
98
|
public function __clone() {
|
99
|
|
100
|
trigger_error('Cloning instances of the singleton class FootNoteManager is prohibited', E_USER_ERROR);
|
101
|
}
|
102
|
|
103
|
}
|