Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

Rev 36 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36 Rev 80
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
2
 
2
 
Line 3... Line 3...
3
class macroElement implements iMacroElement{
3
class macroElement implements iMacroElement{
-
 
4
    
4
    
5
    protected $identifiantblockdedonnees;
5
    protected $identifiantblockdedonnees;
6
    protected $identifiant_parent;
-
 
7
    protected $connexion;
-
 
8
    protected $contexteRef;
6
    protected $connexion;
9
    protected $contexteRefTmp;
7
    protected $contexteRef;
10
    protected $contexteSQL;
8
    protected $blockdedonneesParent;
11
    protected $blockdedonneesParent;
Line 9... Line 12...
9
    protected $collectionblockdedonnees;
12
    protected $collectionblockdedonnees;
10
    protected $idRes;
13
    protected $idRes;
11
    
14
    
12
    function __construct($une_connexion, $un_block_données_parent, $identifiant)
15
    function __construct($une_connexion, $un_block_donnees_parent, $chemin_macro_element)
-
 
16
    {
-
 
17
        $this->connexion = $une_connexion;
13
    {
18
        $this->blockdedonneesParent = $un_block_donnees_parent;
-
 
19
        $tab_etape_chemin = array_reverse(explode('>', $chemin_macro_element));
-
 
20
        $identifiant = $tab_etape_chemin[0];
-
 
21
        $this->identifiantblockdedonnees = $identifiant;
-
 
22
        if (count($tab_etape_chemin) > 1) {
-
 
23
            $this->identifiant_parent = $tab_etape_chemin[1];
14
        $this->connexion = $une_connexion;
24
            $this->contexteRef = $this->attribuerContexteRef($this->blockdedonneesParent);
-
 
25
        } else {
15
        $this->blockdedonneesParent = $un_block_donn;
26
            $this->identifiant_parent = NULL;
16
        $this->identifiantblockdedonnees = $identifiant;
27
            $this->contexteRef = $this->blockdedonneesParent->recupererDonnees();
-
 
28
        }
-
 
29
    }
-
 
30
    
-
 
31
    function attribuerContexteRef($un_block_donnees)
-
 
32
    {
-
 
33
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
-
 
34
        for($i = 0; $i < count($collection_block_fils); $i++) {
-
 
35
            $collection = $collection_block_fils[$i];
-
 
36
            if ($collection->recupererIdentifiant() == $this->identifiant_parent) {
-
 
37
                return $collection->recupererBlocksDeDonnees();
-
 
38
            } else if (is_object($un_block_donnees->recupererCollectionBlockFils())) {
-
 
39
                return $this->attribuerContexteRef($un_block_donnees->recupererCollectionBlockFils());
-
 
40
            }
-
 
41
        }
-
 
42
    }
-
 
43
    
-
 
44
    function attribuerCollectionBlockFils($un_block_donnees, $id)
-
 
45
    {
-
 
46
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
-
 
47
        for($i = 0; $i < count($collection_block_fils); $i++) {
-
 
48
            $collection = $collection_block_fils[$i];
-
 
49
            if ($collection->recupererIdentifiant() == $this->identifiant_parent) {
-
 
50
                $blocks_de_donnees = $collection->recupererBlocksDeDonnees();
-
 
51
                foreach ($blocks_de_donnees as $cle => $val) {
-
 
52
                    if ($cle == $id) {
-
 
53
                        return $blocks_de_donnees[$cle]->ajouterCollectionBlockFils($this->collectionblockdedonnees);
-
 
54
                    }
-
 
55
                }
-
 
56
            } else if (is_object($this->blockdedonneesParent->recupererCollectionBlockFils())) {
-
 
57
                return $this->attribuerCollectionBlockFils($un_block_donnees->recupererCollectionBlockFils());
-
 
58
            }
17
        $this->contexteRef = $this->blockdedonneesParent->recupererDonnees();
59
        }
18
    }
60
    }
-
 
61
    
19
    
62
    function construire()
20
    function construire() 
63
    {
21
    {
64
        if (is_null($this->identifiant_parent)) {
22
        $sql = $this->getSQL();
65
            $sql = $this->getSQL();
23
        if(!is_null($sql)) {
66
            if(!is_null($sql)) {
-
 
67
                $this->openCursor($sql);
-
 
68
                while ($this->fetch());
-
 
69
                $this->closeCursor();
-
 
70
            }
-
 
71
        } else {
-
 
72
            $this->contexteRefTmp = $this->contexteRef;
-
 
73
            for($i = 0; $i < count($this->contexteRefTmp); $i++) {
-
 
74
                $this->contexteRef = $this->contexteRefTmp[$i]->recupererDonnees();
-
 
75
                $sql = $this->getSQL();
-
 
76
                if(!is_null($sql)) {
-
 
77
                    $this->openCursor($sql, $i);
-
 
78
                    while ($this->fetch());
-
 
79
                    $this->closeCursor();
24
            $this->openCursor($sql);
80
                }
-
 
81
            }
25
            while ($this->fetch());
82
            //$this->contexteRef = $this->contexteRefTmp;
Line 26... Line 83...
26
            $this->closeCursor();
83
        }
27
        }
84
        //echo '<pre>'.print_r($this->contexteRef, true).'</pre>';
28
    }
85
    }
Line 39... Line 96...
39
    function contruireParRecursivite()
96
    function contruireParRecursivite()
40
    {
97
    {
Line 41... Line 98...
41
        
98
        
Line 42... Line 99...
42
    }
99
    }
43
    
100
    
44
    function openCursor($sql)
101
    function openCursor($sql, $id = null)
45
    {
102
    {
46
        $res = mysql_query($sql, $this->connexion);
103
        $res = mysql_query($sql, $this->connexion);
47
        if (!$res) echo mysql_errno().': '.mysql_error()."\n";
104
        if (!$res) echo mysql_errno().': '.mysql_error()."\n";
-
 
105
        $this->idRes = $res;
48
        $this->idRes = $res;
106
        $this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees);
-
 
107
        if (is_null($this->identifiant_parent)) {
-
 
108
            $this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees);
-
 
109
        } else {
49
        $this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees);
110
            $this->attribuerCollectionBlockFils($this->blockdedonneesParent, $id);
Line 50... Line 111...
50
        $this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees);
111
        }
51
    }
112
    }
52
    
113