Hallo Frank,
Erst einmal: ich habe den Eindruck, dass Dich bisher keiner wirklich verstanden hat, (vor allem in dem Sinn, wie weit Du schon in Gedanken warst) obwohl die Fragestellung _sehr_ deutlich war. Seltsam.
wie kann ich es nun im adminbereich realisieren artikel up/down zu stellen.
man müsst ja die id des artikels und aller anderen artikel auch ändern. hat das schon mal jemand gemacht und kann mir hier weiterhelfen.
Also: Ich habe das mit einem sehr simplen, jedoch komplett ineffizienten Algorithmus gelöst. Es gibt mit _Sicherheit_ effizientere Algorithmen »da draußen«. Aber der folgende funktioniert, und ich hatte nicht viel Zeit, daher hab' ich mich damit begnügt. (Über etwas effizienteres würde ich selbst mich sehr freuen :-))
»Angehäng« habe ich eine Funktion, die das neu sortieren durchführt. Sie erwartet 3 Paramter: 1. Die ID des Menüeintrages, der umsortiert werden soll. (ich hab's bei mir für das Menü verwendet, aber Du kannst es ruhig für Deine Artikel verwenden, musst es nur anpassen ;-)) 2. Die ID des Menüeintrages, der als »Referenzpunkt« dienen soll. 3. Soll der Menüeintrag _vor_ (3. Parameter <= 0) oder _nach_ (3. Paramter > 0) dem »Referenzeintrag« einsortiert werden.
Ich verwende desweiteren PEAR::DB um auf die Datenbank zuzugreifen, und executeMultiple führt nichts anderes als lauter Anfragen auf einmal aus. Ich empfehle zum Verständnis http://pear.php.net/manual/en/core.db.tut_execute.php.
Ich hoffe, der Code hilft Dir weiter, wenn Du etwas nicht verstehst, frag' nach. (Ich habe nur keine Lust, eine ellenlange Erklärung zu schreiben, wenn Du auf Anhieb aus dem Code kapierst, was ich meine, wenn Du ihn aber nicht sofort kapierst, dann bin ich gerne bereit, das nachzuholen (das gilt auch für jeden anderen Mitleser))
Christian
_____________________________________________________________________
// resort menu list - put a menu in front or behind of another
// where > 0 => after, where <= 0 => before
// returns: DB_OK if successful, false if one of the entries doesn't exist or the parent is not identical
// or DB_Error object
function resort ($to_put, $reference, $where) {
// import database connection
global $db_conn;
// import configuration
global $global_config;
// see if first entry exists
$tp_res = Menu::getInfo ($to_put);
// oops - something went really wrong...
if (DB::isError($tp_res)) {
return $tp_res;
}
// if the entry doesn't exist, return false
if ($tp_res === null) {
return false;
}
// see if second entry exists
$r_res = Menu::getInfo ($reference);
// oops - something went really wrong...
if (DB::isError($r_res)) {
return $r_res;
}
// if the entry doesn't exist, return false
if ($r_res === null) {
return false;
}
// if parents are not equal, return false
if ($r_res['parentid'] != $tp_res['parentid']) {
return false;
}
// get list
$list = Menu::getEntries ($r_res['parentid']);
// now if there's an error, return it
if (DB::isError($list)) {
return $list;
}
// if the list contains less than two entries, somethings really weired
if (count($list) < 2) {
return false;
}
// init arrays for sorting
$new_arr = array ();
// init counter
$ctr = 0;
// go through the list and set new range
foreach ($list as $entry) {
// if the entry is the entry to put, ignore it
if ($entry['menuid'] == $to_put) {
continue;
}
// if the entry is the reference
if ($entry['menuid'] == $reference && $where <= 0) {
// add to array
$new_arr[] = array ($ctr, $to_put);
// increment counter
$ctr++;
}
// add item to array
$new_arr[] = array ($ctr, $entry['menuid']);
// increment counter
$ctr++;
// if the entry is the reference
if ($entry['menuid'] == $reference && $where > 0) {
// add to array
$new_arr[] = array ($ctr, $to_put);
// increment counter
$ctr++;
}
}
// now build up update sentence
$update = 'UPDATE ' . $global_config['database']['table_prefix'] . '_menu';
$update .= ' SET sortid = ? WHERE menuid = ?';
// prepare the statement
$sth = $db_conn->prepare ($update);
// run the query
$res = $db_conn->executeMultiple ($sth, $new_arr);
// return the result
return $res;
}
Ich bitte darum, dass ein Themenbereich (BARRIEREFREIHEIT) eingerichtet wird.