1
|
<?php
|
2
|
|
3
|
class FootnoteManager
|
4
|
{
|
5
|
|
6
|
|
7
|
private static $fnstore = array();
|
8
|
|
9
|
private static $nextFootnoteKey = 1;
|
10
|
|
11
|
// private constructor
|
12
|
private function __construct() {
|
13
|
|
14
|
}
|
15
|
|
16
|
|
17
|
/**
|
18
|
* @param $footnoteListKey a string as key to the list of footnotes
|
19
|
* @return an array of footnotes objects
|
20
|
*
|
21
|
*/
|
22
|
public static function getFootnoteList($footnoteListKey){
|
23
|
return array_key_exists($footnoteListKey, self::$fnstore) ? self::$fnstore[$footnoteListKey] : NULL;
|
24
|
}
|
25
|
|
26
|
/**
|
27
|
*
|
28
|
* @param $footnoteListKey
|
29
|
* @param $separator
|
30
|
* @return unknown_type
|
31
|
*/
|
32
|
public static function renderFootnoteList($footnoteListKey, $separator = ', '){
|
33
|
$out = '';
|
34
|
if(array_key_exists($footnoteListKey, self::$fnstore)){
|
35
|
foreach(self::$fnstore[$footnoteListKey] as $fn){
|
36
|
$out .= $fn->doRender() . $separator;
|
37
|
}
|
38
|
$out = substr($out, 0, strlen($out)-strlen($separator));
|
39
|
}
|
40
|
return $out;
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
*
|
45
|
* @param $footnoteListKey
|
46
|
* @param $object
|
47
|
* @param $theme
|
48
|
* @param $themeArguments
|
49
|
* @return unknown_type
|
50
|
*/
|
51
|
public static function addNewFootnote($footnoteListKey, $object, $theme = NULL, $themeArguments = array()){
|
52
|
|
53
|
if(!array_key_exists($footnoteListKey, self::$fnstore)){
|
54
|
self::$fnstore[$footnoteListKey] = array();
|
55
|
}
|
56
|
|
57
|
$fnKey = NULL;
|
58
|
if( !($fnKey = self::footnoteExists($footnoteListKey, $object)) ){
|
59
|
$fnKey = self::$nextFootnoteKey++;
|
60
|
$fn = new Footnote($fnKey, $object, $theme, $themeArguments);
|
61
|
self::$fnstore[$footnoteListKey][$fnKey] = $fn;
|
62
|
|
63
|
}
|
64
|
|
65
|
return $fnKey;
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
*
|
70
|
* @param $footnoteListKey
|
71
|
* @param $object
|
72
|
* @return unknown_type
|
73
|
*/
|
74
|
private static function footnoteExists($footnoteListKey, $object){
|
75
|
foreach(self::$fnstore[$footnoteListKey] as $key=>$fn){
|
76
|
/**
|
77
|
* When using the comparison operator (==), object variables are compared in a simple manner, namely:
|
78
|
* Two object instances are equal if they have the same attributes and values, and are instances of the same class.
|
79
|
*/
|
80
|
if($object == $fn->object){
|
81
|
return $key;
|
82
|
}
|
83
|
}
|
84
|
return FALSE;
|
85
|
}
|
86
|
|
87
|
// stop users from cloning
|
88
|
public function __clone() {
|
89
|
|
90
|
trigger_error('Cloning instances of the singleton class FootNoteManager is prohibited', E_USER_ERROR);
|
91
|
}
|
92
|
|
93
|
}
|