implement GRIDs

This commit is contained in:
2018-08-01 22:19:30 +02:00
parent 8988df93fd
commit 755c65a42d
12 changed files with 203 additions and 37 deletions
+36 -1
View File
@@ -6,7 +6,7 @@ namespace App\Models;
* Row in a data table
*
* @property int $id
* @property string $data - JSONB
* @property string $data - JSONB, always containing _grid
*/
class Row extends BaseModel
{
@@ -16,4 +16,39 @@ class Row extends BaseModel
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];
}
}
+5 -1
View File
@@ -62,7 +62,7 @@ class User extends BaseModel implements
* @var array
*/
protected $fillable = [
'name', 'title', 'email', 'password', 'bio', 'website'
'name', 'title', 'email', 'password', 'bio', 'website', 'confirmed'
];
/**
@@ -183,6 +183,10 @@ class User extends BaseModel implements
}
else {
$u = static::where('email', $ident)->first();
if (!$u) {
$u = static::where('name', $ident)->first();
}
}
if (!$u) throw new NotExistException("No user found matching \"$ident\"");