mirror of
https://github.com/UndefinedOffset/SortableGridField.git
synced 2024-10-22 17:05:38 +02:00
Merge branch 'append-to-top' of git://github.com/g4b0/SortableGridField into experimental
This commit is contained in:
commit
6ca5bf9a9d
5
_config/gridfieldsortablerows.yml
Normal file
5
_config/gridfieldsortablerows.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
Name: gridfieldsortablerows
|
||||||
|
---
|
||||||
|
GridFieldSortableRows:
|
||||||
|
append_to_top: true
|
@ -189,20 +189,48 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP
|
|||||||
DB::getConn()->transactionStart();
|
DB::getConn()->transactionStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$append_to_top = Config::inst()->get('GridFieldSortableRows', 'append_to_top');
|
||||||
|
|
||||||
foreach($list as $obj) {
|
foreach($list as $obj) {
|
||||||
if($many_many) {
|
if($many_many) {
|
||||||
DB::query('UPDATE "' . $table
|
if ($append_to_top) {
|
||||||
. '" SET "' . $sortColumn .'" = ' . ($max + $i)
|
// Upgrade all the records (including the last iserted from 0 to 1)
|
||||||
. ' WHERE "' . $componentField . '" = ' . $obj->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
|
DB::query('UPDATE "' . $table
|
||||||
}else {
|
. '" SET "' . $sortColumn . '" = "' . $sortColumn .'"+1'
|
||||||
DB::query('UPDATE "' . $table
|
. ' WHERE "' . $parentField . '" = ' . $owner->ID);
|
||||||
. '" SET "' . $sortColumn . '" = ' . ($max + $i)
|
} else {
|
||||||
. ' WHERE "ID" = '. $obj->ID);
|
// Append the last record to the bottom
|
||||||
|
DB::query('UPDATE "' . $table
|
||||||
DB::query('UPDATE "' . $baseDataClass
|
. '" SET "' . $sortColumn .'" = ' . ($max + $i)
|
||||||
. '" SET "LastEdited" = \'' . date('Y-m-d H:i:s') . '\''
|
. ' WHERE "' . $componentField . '" = ' . $obj->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
|
||||||
. ' WHERE "ID" = '. $obj->ID);
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($append_to_top) {
|
||||||
|
/*
|
||||||
|
* Append to top
|
||||||
|
*/
|
||||||
|
// Upgrade all the records (including the last iserted from 0 to 1)
|
||||||
|
DB::query('UPDATE "' . $table
|
||||||
|
. '" SET "' . $sortColumn . '" = "' . $sortColumn .'"+1'
|
||||||
|
. ' WHERE "' . $list->foreignKey . '" = '. $owner->ID);
|
||||||
|
// LastEdited
|
||||||
|
DB::query('UPDATE "' . $baseDataClass
|
||||||
|
. '" SET "LastEdited" = \'' . date('Y-m-d H:i:s') . '\''
|
||||||
|
. ' WHERE "' . $list->foreignKey . '" = '. $owner->ID);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Append to bottom
|
||||||
|
*/
|
||||||
|
// Append the last record to the bottom
|
||||||
|
DB::query('UPDATE "' . $table
|
||||||
|
. '" SET "' . $sortColumn . '" = ' . ($max + $i)
|
||||||
|
. ' WHERE "ID" = '. $obj->ID);
|
||||||
|
// LastEdited
|
||||||
|
DB::query('UPDATE "' . $baseDataClass
|
||||||
|
. '" SET "LastEdited" = \'' . date('Y-m-d H:i:s') . '\''
|
||||||
|
. ' WHERE "ID" = '. $obj->ID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
|
Loading…
Reference in New Issue
Block a user