1
0

Modified module to use weight field in DB to order the modules instead of id requires commit d3a161ca1b

This commit is contained in:
hukoeth 2010-08-10 15:20:38 +02:00 committed by Bharat Mediratta
parent e94df5cdd0
commit edb4f6c6f4
2 changed files with 4 additions and 29 deletions

View File

@ -54,44 +54,19 @@ class Admin_Moduleorder_Controller extends Admin_Controller {
}
ksort($modulelist);
//Get the highest used index
$highestindex = 0;
foreach ($modulelist as $row) {
$currentry = explode(":", $row);
if ($currentry[1] > $highestindex) {
$highestindex = $currentry[1];
}
}
$highestindex++; //Have a safety margin just in case
//To avoid conflicts on the index we now rewrite all indices of all modules
foreach ($modulelist as $row) {
$highestindex++;
$currentry = explode("=", $row);
$currentry = explode(":", $currentry[1]);
db::build()
->update("modules")
->set("id", $highestindex)
->where("name", "=", $currentry[0])
->execute();
}
//Now we are ready to write the correct id values
$highestindex = 0;
$current_weight = 0;
foreach ($modulelist as $row) {
$highestindex++;
$current_weight++;
$currentry = explode("=", $row);
$currentry = explode(":", $currentry[1]);
db::build()
->update("modules")
->set("id", $highestindex)
->set("weight", $current_weight)
->where("name", "=", $currentry[0])
->execute();
}
//As last step we optimize the table
db::query("OPTIMIZE TABLE `modules`")
->execute();
message::success(t("Your settings have been saved."));
url::redirect("admin/moduleorder");
print $this->_get_view();

View File

@ -24,7 +24,7 @@ class module_manager_Core {
private static function _get_modules() {
$modules = array();
foreach (db::build()->select("*")->from("modules")->order_by("id")->execute() as $row) {
foreach (db::build()->select("*")->from("modules")->order_by("weight")->execute() as $row) {
$modules["{$row->name}:$row->id"] = $row->name;
}
return $modules;