Rev 106 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpclass 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 recupererDonneesRecursivement($tab_chemin, $aso_retour = array()){if ($tab_chemin[0] == $this->recupererIdentifiant()) {return $aso_retour[$this->recupererIdentifiant()] = $this->donnees;$collection_block_fils = $this->recupererCollectionBlockFils();for($i = 0; $i < count($collection_block_fils); $i++) {$collection = $collection_block_fils[$i];if ($collection->recupererIdentifiant() == $tab_chemin[1]) {$blocks = $collection->recupererBlocksDeDonnees();for($j = 0; $j < count($blocks); $j++) {$block = $blocks[$j];$block->recupererDonneesRecursivement(array_shift($tab_chemin), $aso_retour);}}}}return $aso_retour;}function recupererDonneesRecursivementSsChemin($un_block){$aso_donnees = array();$aso_donnees = $un_block->recupererDonnees();$collection_block_fils = $un_block->recupererCollectionBlockFils();for($i = 0; $i < count($collection_block_fils); $i++) {$une_collection = $collection_block_fils[$i];$blocks_de_donnees = $une_collection->recupererBlocksDeDonnees();for ($i = 0; $i < count($blocks_de_donnees); $i++) {$block = $blocks_de_donnees[$i];$aso_donnees[$block->recupererIdentifiant()] = $this->recupererDonneesRecursivementSsChemin($block);}}return $aso_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 afficherPatternRecursivement($nom_fonction, $aso_parametres = array()){$retour = '';$aso_donnees = $this->recupererDonneesRecursivementSsChemin($this);return call_user_func($nom_fonction, $aso_donnees, $aso_parametres);}function afficherPattern($chemin, $nom_fonction, $aso_parametres = array(), $recuperer_ascendance = FALSE, &$aso_donnees = array()){$retour = '';if ($recuperer_ascendance == TRUE) {$aso_donnees[$this->recupererIdentifiant()] = $this->recupererDonnees();}if ($chemin == $this->recupererIdentifiant() && $recuperer_ascendance == TRUE) {$retour .= call_user_func($nom_fonction, $aso_donnees, $aso_parametres);} else if ($chemin == $this->recupererIdentifiant()) {$retour .= call_user_func($nom_fonction, $this->recupererDonnees(), $aso_parametres);} else {$tab_etape_chemin = explode('>', $chemin);if($this->recupererIdentifiant() == $tab_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() == $tab_etape_chemin[1]) {array_shift($tab_etape_chemin);if ($recuperer_ascendance == TRUE) {$retour .= $collection->afficherPattern(implode('>', $tab_etape_chemin), $nom_fonction, $aso_parametres, $recuperer_ascendance, $aso_donnees);} else {$retour .= $collection->afficherPattern(implode('>', $tab_etape_chemin), $nom_fonction, $aso_parametres);}}}}}return $retour;}function attribuerContexteSql($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->attribuerContexteSql(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 attribuerContexteValeur($chemin, $cle_contexte, $valeur = null){if ($chemin == $this->recupererIdentifiant()) {$this->ajouterDonnee($cle_contexte, $valeur);return null;} 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->attribuerContexteValeur(implode('>', $etape_chemin), $cle_contexte, $valeur);if (isset($donnees)) {$i = count($collection_block_fils);}}}}}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>';}}}?>