43,20 → 43,37 |
|
function attribuerCollectionBlockFils($un_block_donnees, $id) |
{ |
if ($un_block_donnees->recupererIdentifiant() == $id ) { |
return $un_block_donnees->ajouterCollectionBlockFils($this->collectionblockdedonnees); |
} else if (is_array($un_block_donnees->recupererCollectionBlockFils()) AND count($un_block_donnees->recupererCollectionBlockFils()) > 0) { |
$collection_block_fils = $un_block_donnees->recupererCollectionBlockFils(); |
for($i = 0; $i < count($collection_block_fils); $i++) { |
$blocks_de_donnees = $collection_block_fils[$i]->recupererBlocksDeDonnees(); |
for ($i = 0; $i < count($blocks_de_donnees); $i++) { |
$this->attribuerCollectionBlockFils($blocks_de_donnees[$i], $id); |
} |
} |
} |
} |
|
function recupererCollectionBlockFils($un_block_donnees, $id) |
{ |
$collection_block_fils = $un_block_donnees->recupererCollectionBlockFils(); |
for($i = 0; $i < count($collection_block_fils); $i++) { |
$collection = $collection_block_fils[$i]; |
if ($collection->recupererIdentifiant() == $this->identifiant_parent) { |
$blocks_de_donnees = $collection->recupererBlocksDeDonnees(); |
foreach ($blocks_de_donnees as $cle => $val) { |
if ($cle == $id) { |
return $blocks_de_donnees[$cle]->ajouterCollectionBlockFils($this->collectionblockdedonnees); |
$une_collection = $collection_block_fils[$i]; |
if ($une_collection->recupererIdentifiant() == $id ) { |
return $une_collection->recupererBlocksDeDonnees(); |
} else { |
$blocks_de_donnees = $une_collection->recupererBlocksDeDonnees(); |
for ($i = 0; $i < count($blocks_de_donnees); $i++) { |
$block = $blocks_de_donnees[$i]; |
if (is_array($block->recupererCollectionBlockFils()) AND count($block->recupererCollectionBlockFils()) > 0) { |
return $this->recupererCollectionBlockFils($block, $id); |
} |
} |
} else if (is_object($this->blockdedonneesParent->recupererCollectionBlockFils())) { |
return $this->attribuerCollectionBlockFils($un_block_donnees->recupererCollectionBlockFils()); |
} |
} |
return null; |
} |
|
function construire() |
63,25 → 80,12 |
{ |
if (is_null($this->identifiant_parent)) { |
$sql = $this->getSQL(); |
if(!is_null($sql)) { |
if (!is_null($sql)) { |
$this->openCursor($sql); |
while ($this->fetch()); |
$this->closeCursor(); |
} |
} else { |
$this->contexteRefTmp = $this->contexteRef; |
for($i = 0; $i < count($this->contexteRefTmp); $i++) { |
$this->contexteRef = $this->contexteRefTmp[$i]->recupererDonnees(); |
$sql = $this->getSQL(); |
if(!is_null($sql)) { |
$this->openCursor($sql, $i); |
while ($this->fetch()); |
$this->closeCursor(); |
} |
} |
//$this->contexteRef = $this->contexteRefTmp; |
} |
//echo '<pre>'.print_r($this->contexteRef, true).'</pre>'; |
} |
} |
|
function contruireParRecursivitePlate() |
93,40 → 97,79 |
construire(); |
} |
|
function contruireParRecursivite() |
{ |
|
function construireParRecursivite($niveau_max, $aso_contexte = null, $id = null) |
{ |
static $niveau_courant = 0; |
if ($niveau_courant > $niveau_max) { |
return null; |
} |
|
if (!is_null($aso_contexte)) { |
$this->contexteRef = $aso_contexte; |
} |
if (is_null($id)) { |
$id = $this->identifiantblockdedonnees; |
$this->identifiant_parent = $this->blockdedonneesParent->recupererIdentifiant(); |
} else { |
$this->identifiant_parent = $id; |
} |
|
$sql = $this->getSQL(); |
//echo '<pre>'.print_r($sql, true).'</pre>'; |
if (!is_null($sql)) { |
$this->openCursor($sql, $id); |
for ($i = 0; $this->fetch($id.'-'.$i); $i++); |
$this->closeCursor($this->identifiant_parent); |
|
$blocks_de_donnees = $this->recupererCollectionBlockFils($this->blockdedonneesParent, $id); |
if (count($blocks_de_donnees) > 0) { |
$niveau_courant++; |
} |
for ($i = 0; $i < count($blocks_de_donnees); $i++) { |
$block = $blocks_de_donnees[$i]; |
$this->construireParRecursivite($niveau_max, $block->recupererDonnees(), $block->recupererIdentifiant()); |
} |
} |
} |
|
function openCursor($sql, $id = null) |
{ |
$res = mysql_query($sql, $this->connexion); |
if (!$res) echo mysql_errno().': '.mysql_error()."\n"; |
$this->idRes = $res; |
$this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees); |
if (is_null($this->identifiant_parent)) { |
$this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees); |
$resultat = mysql_query($sql, $this->connexion); |
if (!$resultat) { |
echo 'Numéro erreur Mysql : '.mysql_errno().'<br />'."\n"; |
echo 'Erreur Mysql : '.mysql_error().'<br />'."\n"; |
echo 'Requête : '.'<pre>'.$sql.'</pre>'; |
} |
$this->idRes = $resultat; |
if (is_null($id)) { |
$this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees); |
} else { |
$this->attribuerCollectionBlockFils($this->blockdedonneesParent, $id); |
$this->collectionblockdedonnees = new collectionblockdedonnees($id); |
} |
} |
|
function fetch() |
function fetch($identifiant = null) |
{ |
$res = mysql_fetch_assoc($this->idRes); |
if (!$res) { |
|
} else { |
//$this->blockdedonnees = new blockdedonnees($this->identifiantblockdedonnees); |
//$this->blockdedonnees->affecterDonnees($res); |
$this->collectionblockdedonnees->ajouterDonnees($res); |
$resultat = mysql_fetch_assoc($this->idRes); |
if (!$resultat) { |
// Nous ne faisons rien car aucune donnée n'est collectée. |
} else { |
$this->collectionblockdedonnees->ajouterDonnees($resultat, $identifiant); |
} |
return $res; |
return $resultat; |
} |
|
function closeCursor() |
function closeCursor($id = null) |
{ |
mysql_free_result($this->idRes); |
mysql_free_result($this->idRes); |
// Nous ajoutons les données de la requêtes seulement si elle a ramenée des données |
if (count($this->collectionblockdedonnees->recupererBlocksDeDonnees()) > 0) { |
if (is_null($id)) { |
$this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees); |
} else { |
$this->attribuerCollectionBlockFils($this->blockdedonneesParent, $id); |
} |
} |
} |
} |
?> |