Modified module to use weight field in DB to order the modules instead of id requires commit d3a161ca1b
This commit is contained in:
parent
848e5805af
commit
fc22acf0b4
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Reference in New Issue
Block a user