Project

General

Profile

Download (2.92 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
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 = null, $theme = NULL, $themeArguments = array()){
62

    
63
      if(!$object){
64
      	return false;
65
      }
66

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

    
107
}
(3-3/4)