Optimize exercice numbering

This commit is contained in:
nemunaire 2014-11-20 21:56:37 +01:00
parent e6acdbd68a
commit bbd82406f9

View File

@ -178,26 +178,28 @@ class Exercice
{ {
if ($this->require == "") if ($this->require == "")
$this->number = 1; $this->number = 1;
else
$db = new BDD();
$exo = $this->id;
$ret = 0;
$checked = array();
do
{ {
array_push($checked, $exo); $db = new BDD();
$db->escape($exo);
$res = $db->unique_query("SELECT `require` FROM exercices WHERE id = '".$exo."'");
$exo = $res['require'];
$ret++;
} while ($exo != "" && !in_array($exo, $checked));
$this->number = $ret; $exo = $this->id;
$ret = 0;
$db->deconnexion(); $checked = array();
do
{
array_push($checked, $exo);
$db->escape($exo);
$res = $db->unique_query("SELECT `require` FROM exercices WHERE id = '".$exo."'");
$exo = $res['require'];
$ret++;
} while ($exo != "" && !in_array($exo, $checked));
$this->number = $ret;
$db->deconnexion();
}
} }
function update($create=false) function update($create=false)