I’m doing a "sort menu" kind of thing which allow the user to move their documents up/down in the tree.
NewsManager function "Move to top" alter the menuindex value to now(). Pretty primitive in my opionion!
My code looks like this
if ($menuid == $resource[$x]['id'] && $menuvalue != "") {
if ($sort == "up") {
$sortid = $menuvalue -1;
}
if ($sort == "down" ) {
$sortid = $menuvalue +1;
}
$flds = array(
'menuindex' => $sortid,
);
$modx->db->update($flds, $tbl, "id = $menuid");
$modx->sendRedirect($modx->makeUrl($postid));
}
As you can see this function just adds or reduces the menuindex value, not taking anything else into consideration. That’s pretty primitive too, as nothing would happen if two links have the same value and so on.. A possible solution were to not allow duplicate menuindex values or something. But I don’t know enough of PHP do that..
Anyone up for a challenge?