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

54 lines
1.3 KiB

<?php
namespace App\Models;
/**
* Row in a data table
*
* @property int $id
* @property string $data - JSONB, always containing _grid
*/
class Row extends BaseModel
{
protected $casts = [
'data' => 'object',
];
protected $guarded = [];
public $timestamps = false;
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];
}
}