mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
FIX Type hint SS_List instead of DataList and use filter() over where()
This allows people to use this component with ArrayList instances if they want to. Protected methods are generally not considered part of our API, which is why I am proposing this change as a patch.
This commit is contained in:
parent
6e922fcec0
commit
3e50eb224a
@ -664,12 +664,12 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
$this->extend('onAfterReorderItems', $list, $values, $sortedIDs);
|
$this->extend('onAfterReorderItems', $list, $values, $sortedIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function populateSortValues(DataList $list)
|
protected function populateSortValues(SS_List $list)
|
||||||
{
|
{
|
||||||
$list = clone $list;
|
$list = clone $list;
|
||||||
$field = $this->getSortField();
|
$field = $this->getSortField();
|
||||||
$table = $this->getSortTable($list);
|
$table = $this->getSortTable($list);
|
||||||
$clause = sprintf('"%s"."%s" = 0', $table, $this->getSortField());
|
$clause = [sprintf('"%s"."%s"', $table, $this->getSortField()) => 0];
|
||||||
$now = DBDatetime::now()->Rfc2822();
|
$now = DBDatetime::now()->Rfc2822();
|
||||||
$additionalSQL = '';
|
$additionalSQL = '';
|
||||||
$baseTable = DataObject::getSchema()->baseDataTable($list->dataClass());
|
$baseTable = DataObject::getSchema()->baseDataTable($list->dataClass());
|
||||||
@ -679,7 +679,14 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
$additionalSQL = ", \"LastEdited\" = '$now'";
|
$additionalSQL = ", \"LastEdited\" = '$now'";
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($list->where($clause)->column('ID') as $id) {
|
// B/C support for DataList
|
||||||
|
if ($list instanceof DataList) {
|
||||||
|
$filteredList = $list->where($clause);
|
||||||
|
} else {
|
||||||
|
$filteredList = $list->filter($clause);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($filteredList->column('ID') as $id) {
|
||||||
$max = DB::query(sprintf('SELECT MAX("%s") + 1 FROM "%s"', $field, $table));
|
$max = DB::query(sprintf('SELECT MAX("%s") + 1 FROM "%s"', $field, $table));
|
||||||
$max = $max->value();
|
$max = $max->value();
|
||||||
|
|
||||||
@ -710,12 +717,12 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
* e.g. SortOrder = 5 AND RelatedThing.ID = 3
|
* e.g. SortOrder = 5 AND RelatedThing.ID = 3
|
||||||
* e.g. SortOrder IN(5, 8, 10) AND RelatedThing.ID = 3
|
* e.g. SortOrder IN(5, 8, 10) AND RelatedThing.ID = 3
|
||||||
*
|
*
|
||||||
* @param DataList $list
|
* @param SS_List $list
|
||||||
* @param int|string|array $ids a single number, or array of numbers
|
* @param int|string|array $ids a single number, or array of numbers
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getSortTableClauseForIds(DataList $list, $ids)
|
protected function getSortTableClauseForIds(SS_List $list, $ids)
|
||||||
{
|
{
|
||||||
if (is_array($ids)) {
|
if (is_array($ids)) {
|
||||||
$value = 'IN (' . implode(', ', array_map('intval', $ids)) . ')';
|
$value = 'IN (' . implode(', ', array_map('intval', $ids)) . ')';
|
||||||
|
Loading…
Reference in New Issue
Block a user