Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

Rev 44 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42 fred 1
<?php
2
 
3
class blockdedonnees {
39 jpm 4
 
42 fred 5
    protected $identifiant;
6
    protected $donnees;
7
    protected $collectionBlocksfils;
8
    protected $erreur;
9
 
10
    function __construct($identifiant)
11
    {
12
        $this->identifiant = $identifiant;
13
        $this->donnees = array();
14
        $this->collectionBlocksfils = array();
15
    }
16
 
17
    function affecterIdentifiant($identifiant)
18
    {
19
        $this->identifiant = $identifiant;
20
    }
44 jpm 21
 
22
    function recupererIdentifiant()
23
    {
24
        return $this->identifiant;
25
    }
42 fred 26
 
27
    function affecterDonnees($donnees)
28
    {
29
        $this->donnees = $donnees;
30
    }
31
 
32
    function recupererDonnees()
33
    {
34
        return $this->donnees;
35
    }
36
 
37
    function ajouterDonnee($clef, $valeur)
38
    {
39
        $this->donnees["$clef"] = $valeur;
40
    }
41
 
42
    function recupererDonnee($clef)
43
    {
44
        return $this->donnees["$clef"];
45
    }
46
 
47
    function recupererErreur()
48
    {
49
        return $this->erreur;
50
    }
51
 
52
    function recupererBlockFils()
53
    {
54
        return $this->blocksfils;
55
    }
56
 
57
    function ajouterCollectionBlockFils($collection_block)
58
    {
59
        array_push($this->collectionBlocksfils, $collection_block);
60
    }
61
 
39 jpm 62
    function recupererCollectionBlockFils()
63
    {
64
        return $this->collectionBlocksfils;
65
    }
42 fred 66
 
44 jpm 67
    function afficherPattern($chemin, $nom_fonction)
68
    {
69
        $retour = '';
70
        if($chemin == $this->recupererIdentifiant()) {
71
            $retour .= call_user_func($nom_fonction, $this->recupererDonnees());
72
        } else {
73
            $etape_chemin = explode('>', $chemin);
74
            if($this->identifiant == $etape_chemin[0]) {
75
                $collection_block_fils = $this->recupererCollectionBlockFils();
76
                for($i = 0; $i < count($collection_block_fils); $i++) {
77
                    $collection = $collection_block_fils[$i];
78
                    if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
79
                        array_shift($etape_chemin);
80
                        $retour .= $collection->afficherPattern(implode('>', $etape_chemin), $nom_fonction);
81
                    }
82
                }
83
            }
84
        }
85
        return $retour;
86
    }
42 fred 87
 
72 jpm 88
    function attribuerContexte($chemin, $cle_contexte, $cle_donnee)
89
    {
90
        if ($chemin == $this->recupererIdentifiant()) {
91
            $donnees = $this->recupererDonnees();
92
            return $donnees;
93
        } else {
94
            $etape_chemin = explode('>', $chemin);
95
            if($this->identifiant == $etape_chemin[0]) {
96
                $collection_block_fils = $this->recupererCollectionBlockFils();
97
                for($i = 0; $i < count($collection_block_fils); $i++) {
98
                    $collection = $collection_block_fils[$i];
99
                    if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
100
                        array_shift($etape_chemin);
101
                        $donnees = null;
102
                        $donnees = $collection->attribuerContexte(implode('>', $etape_chemin), $cle_contexte, $cle_donnee);
103
                        if (isset($donnees)) {
104
                            $i = count($collection_block_fils);
105
                        }
106
                    }
107
                }
108
            }
109
        }
110
        $this->ajouterDonnee($cle_contexte, $donnees[$cle_donnee]);
111
        return null;
112
    }
113
 
42 fred 114
    function afficher()
115
    {
116
        echo '<ol>';
117
        foreach ($this->donnees as $key => $value) {
118
            echo '<li>'.$key.' : '.$value;
119
        }
120
        echo '</ol>';
121
        for ($i = 0; $i < count($this->collectionBlocksfils); $i++) {
122
            $collection = $this->collectionBlocksfils[$i];
123
            echo '<ol>';
124
            $collection->afficher();
125
            echo '</ol>';
126
        }
127
    }
128
}
27 jpm 129
?>