Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

Rev 72 | 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($bool_descendance = FALSE)
    {
        if ($bool_descendance == TRUE) {
            $aso_donnees = array();
            $aso_donnees[$this->recupererIdentifiant()] = $this->donnees;
            $collections_blocks_fils = $this->recupererCollectionBlockFils();
            if (is_array($collections_blocks_fils)) {
                for($i = 0; $i < count($collections_blocks_fils); $i++) {
                    $collection = $collections_blocks_fils[$i];
                    $blocks_de_donnees = $collection->recupererBlocksDeDonnees();
                    for($j = 0; $j < count($blocks_de_donnees); $j++) {
                        $block = $blocks_de_donnees[$j];
                        $donnees = $block->recupererDonnees();
                        $aso_donnees[$this->recupererIdentifiant()][$block->recupererIdentifiant()] = $donnees;
                    }
                }
            }
            return $aso_donnees;
        } else {
            return $this->donnees;
        }
    }
    
    function ajouterDonnee($clef, $valeur)
    {
        $this->donnees[$clef] = $valeur;
    }
    
    function recupererDonnee($clef)
    {
        return $this->donnees[$clef];
    }
    
    function recupererErreur()
    {
        return $this->erreur;
    }
    
    function ajouterCollectionBlockFils($collection_block)
    {
        array_push($this->collectionBlocksfils, $collection_block);
    }
    
    function recupererCollectionBlockFils()
    {
        return $this->collectionBlocksfils;
    }
    
    function afficherPattern($chemin, $nom_fonction, $recuperer_descendance = FALSE, $aso_parametres = array())
    {
        $retour = '';
        if($chemin == $this->recupererIdentifiant()) {
            $retour .= call_user_func($nom_fonction, $this->recupererDonnees($recuperer_descendance), $aso_parametres);
        } 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, $recuperer_descendance, $aso_parametres);
                    }
                }
            }
        }
        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>';
        }
    }
}
?>