Source of file GridFieldWhereableOrderableRows.php
Size: 1,500 Bytes - Last Modified: 2021-12-24T06:50:54+00:00
/var/www/docs.ssmods.com/process/src/code/GridField/GridFieldWhereableOrderableRows.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | <?php /** * Allows a where clause when using orderable rows * Class GridFieldWhereableOrderableRows */ class GridFieldWhereableOrderableRows extends GridFieldOrderableRows { /** * @var string */ protected $maxWhereClause; /** * @param string $sortField * @param string $maxWhereClause */ public function __construct($sortField = 'Sort', $maxWhereClause = '') { $this->sortField = $sortField; $this->maxWhereClause = $maxWhereClause; } /** * @param DataList $list */ protected function populateSortValues(DataList $list) { $list = clone $list; $field = $this->getSortField(); $table = $this->getSortTable($list); $clause = sprintf('"%s"."%s" = 0', $table, $this->getSortField()); foreach ($list->where($clause)->column('ID') as $id) { if ($this->maxWhereClause) { $max = DB::query(sprintf('SELECT MAX("%s") + 1 FROM "%s" WHERE %s', $field, $table, $this->maxWhereClause)); } else { $max = DB::query(sprintf('SELECT MAX("%s") + 1 FROM "%s"', $field, $table)); } $max = $max->value(); DB::query( sprintf( 'UPDATE "%s" SET "%s" = %d WHERE %s', $table, $field, $max, $this->getSortTableClauseForIds($list, $id) ) ); } } } |