stub of the row editor
This commit is contained in:
+84
-12
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Tables;
|
||||
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use JsonSerializable;
|
||||
use MightyPork\Exceptions\NotApplicableException;
|
||||
use MightyPork\Utils\Utils;
|
||||
@@ -15,8 +14,20 @@ use MightyPork\Utils\Utils;
|
||||
* @property-read string $type
|
||||
* @property-read string $name
|
||||
* @property-read string $title
|
||||
* @property-read bool $isNew
|
||||
* @property-read bool $toRemove
|
||||
*
|
||||
* @property-read bool $id_modified
|
||||
* @property-read bool $type_modified
|
||||
* @property-read bool $name_modified
|
||||
* @property-read bool $title_modified
|
||||
*
|
||||
* @property-read string $id_orig
|
||||
* @property-read string $type_orig
|
||||
* @property-read string $name_orig
|
||||
* @property-read string $title_orig
|
||||
*/
|
||||
class Column implements JsonSerializable
|
||||
class Column implements JsonSerializable, Arrayable
|
||||
{
|
||||
const colTypes = [
|
||||
'int', 'bool', 'float', 'string'
|
||||
@@ -27,6 +38,76 @@ class Column implements JsonSerializable
|
||||
private $name;
|
||||
private $title;
|
||||
|
||||
/** @var bool - column is marked to be deleted by a changeset */
|
||||
private $toRemove = false;
|
||||
|
||||
/** @var bool - column is new in this changeset */
|
||||
private $isNew = false;
|
||||
|
||||
/** @var array - original attrib values if edited in a changeset */
|
||||
private $orig_attribs = [];
|
||||
/** @var array - list of attrib names that are modified by a changeset */
|
||||
private $modified_attribs = [];
|
||||
|
||||
/**
|
||||
* Mark for removal (used in editing GUI)
|
||||
*/
|
||||
public function markForRemoval()
|
||||
{
|
||||
$this->toRemove = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this column as new
|
||||
*/
|
||||
public function markAsNew()
|
||||
{
|
||||
$this->isNew = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify by a changeset
|
||||
*
|
||||
* @param array $columnObject
|
||||
*/
|
||||
public function modifyByChangeset(array $columnObject)
|
||||
{
|
||||
foreach ((array)$columnObject as $key => $value) {
|
||||
if ($value != $this->$key) {
|
||||
$this->modified_attribs[] = $key;
|
||||
$this->orig_attribs[] = $this->$key;
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
if (property_exists($this, $name)) {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
if (ends_with($name, '_modified')) {
|
||||
$basename = str_replace('_modified', '', $name);
|
||||
if (property_exists($this, $basename)) {
|
||||
return in_array($basename, $this->modified_attribs);
|
||||
}
|
||||
}
|
||||
|
||||
if (ends_with($name, '_orig')) {
|
||||
$basename = str_replace('_orig', '', $name);
|
||||
if (property_exists($this, $basename)) {
|
||||
return $this->orig_attribs[$basename];
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotApplicableException("No such column property: $name");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $columns
|
||||
* @return Column[]
|
||||
*/
|
||||
public static function columnsFromJson($columns)
|
||||
{
|
||||
if (is_string($columns)) {
|
||||
@@ -73,15 +154,6 @@ class Column implements JsonSerializable
|
||||
$this->title = $b->title ?: $b->name;
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
if (property_exists($this, $name)) {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
throw new NotApplicableException("No such column property: $name");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array with keys {name, title, type}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user