Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

Rev 44 | Blame | Last modification | View Log | RSS feed

<?php

class blockdedonnees {
    
    protected $identifiant;
    protected $donnees;
    protected $collectionBlocksfils;
    protected $erreur;
    
    function __construct($identifiant)
    {
        $this->identifiant = $identifiant;
        $this->donnees = array();
        $this->collectionBlocksfils = array();
    }
   
    function affecterIdentifiant($identifiant)
    {
        $this->identifiant = $identifiant;
    }
    
    function recupererIdentifiant()
    {
        return $this->identifiant;
    }
   
    function affecterDonnees($donnees)
    {
        $this->donnees = $donnees;
    }
    
    function recupererDonnees()
    {
        return $this->donnees;
    }
    
    function ajouterDonnee($clef, $valeur)
    {
        $this->donnees["$clef"] = $valeur;
    }
    
    function recupererDonnee($clef)
    {
        return $this->donnees["$clef"];
    }
    
    function recupererErreur()
    {
        return $this->erreur;
    }
    
    function recupererBlockFils()
    {
        return $this->blocksfils;
    }
    
    function ajouterCollectionBlockFils($collection_block)
    {
        array_push($this->collectionBlocksfils, $collection_block);
    }
    
    function recupererCollectionBlockFils()
    {
        return $this->collectionBlocksfils;
    }
    
    function afficherPattern($chemin, $nom_fonction)
    {
        $retour = '';
        if($chemin == $this->recupererIdentifiant()) {
            $retour .= call_user_func($nom_fonction, $this->recupererDonnees());
        } else {
            $etape_chemin = explode('>', $chemin);
            if($this->identifiant == $etape_chemin[0]) {
                $collection_block_fils = $this->recupererCollectionBlockFils();
                for($i = 0; $i < count($collection_block_fils); $i++) {
                    $collection = $collection_block_fils[$i];
                    if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
                        array_shift($etape_chemin);
                        $retour .= $collection->afficherPattern(implode('>', $etape_chemin), $nom_fonction);
                    }
                }
            }
        }
        return $retour;
    }
    
    function attribuerContexte($chemin, $cle_contexte, $cle_donnee)
    {
        if ($chemin == $this->recupererIdentifiant()) {
            $donnees = $this->recupererDonnees();
            return $donnees;
        } else {
            $etape_chemin = explode('>', $chemin);
            if($this->identifiant == $etape_chemin[0]) {
                $collection_block_fils = $this->recupererCollectionBlockFils();
                for($i = 0; $i < count($collection_block_fils); $i++) {
                    $collection = $collection_block_fils[$i];
                    if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
                        array_shift($etape_chemin);
                        $donnees = null;
                        $donnees = $collection->attribuerContexte(implode('>', $etape_chemin), $cle_contexte, $cle_donnee);
                        if (isset($donnees)) {
                            $i = count($collection_block_fils);
                        }
                    }
                }
            }
        }
        $this->ajouterDonnee($cle_contexte, $donnees[$cle_donnee]);
        return null;
    }
    
    function afficher()
    {
        echo '<ol>';
        foreach ($this->donnees as $key => $value) {
            echo '<li>'.$key.' : '.$value;
        }
        echo '</ol>';
        for ($i = 0; $i < count($this->collectionBlocksfils); $i++) {
            $collection = $this->collectionBlocksfils[$i];
            echo '<ol>';
            $collection->afficher();
            echo '</ol>';
        }
    }
}
?>