datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
datatable.directory/app/Models/Row.php

55 lines
1.3 KiB

6 years ago
<?php
namespace App\Models;
/**
* Row in a data table
*
* @property int $id
6 years ago
* @property string $data - JSONB, always containing _grid
6 years ago
*/
class Row extends BaseModel
6 years ago
{
protected $casts = [
'data' => 'object',
];
6 years ago
protected $guarded = [];
public $timestamps = false;
6 years ago
public function getGridAttribute() {
return $this->data->_grid;
}
public function setGridAttribute($value) {
$this->data->_grid = $value;
}
/**
* Allocate a single Global Row ID, application-unique.
*
* GRIDs are used to uniquely identify existing or proposed new rows,
* and are preserved after row modifications, to ensure change proposals have
* a clear target.
*
* @return int
*/
public static function allocateGRID()
{
return \DB::selectOne("SELECT nextval('global_row_id_seq') AS grid;")->grid;
}
/**
* Allocate a block of Global Row IDs, application-unique.
*
* @see Row::allocateGRID()
*
* @return int[] first and last
*/
public static function allocateGRIDs($count)
{
$last = \DB::selectOne("SELECT multi_nextval('global_row_id_seq', ?) AS last_grid;", [$count])->last_grid;
return [$last - $count + 1, $last];
}
6 years ago
}