Row edit and delete card working

This commit is contained in:
2018-08-05 17:07:34 +02:00
parent bb8bc459dc
commit a4103e7084
15 changed files with 393 additions and 209 deletions
+12 -17
View File
@@ -10,13 +10,6 @@ use MightyPork\Utils\Utils;
/**
* Helper class representing one column in a data table.
*
* @property-read string $id
* @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
@@ -33,16 +26,18 @@ class Column implements JsonSerializable, Arrayable
'int', 'bool', 'float', 'string'
];
private $id;
private $type;
private $name;
private $title;
// marked public to make keyBy() work
public $id;
public $type;
public $name;
public $title;
/** @var bool - column is marked to be deleted by a changeset */
private $toRemove = false;
public $toRemove = false;
/** @var bool - column is new in this changeset */
private $isNew = false;
public $isNew = false;
/** @var array - original attrib values if edited in a changeset */
private $orig_attribs = [];
@@ -83,10 +78,6 @@ class Column implements JsonSerializable, Arrayable
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)) {
@@ -177,20 +168,24 @@ class Column implements JsonSerializable, Arrayable
{
switch ($this->type) {
case 'int':
if (is_null($value)) return 0;
if (is_int($value)) return $value;
if (is_float($value)) return round($value);
if (is_numeric($value)) return intval($value);
throw new NotApplicableException("Could not convert value \"$value\" to int!");
case 'float':
if (is_null($value)) return 0;
if (is_int($value) || is_float($value)) return (float)$value;
if (is_numeric($value)) return floatval($value);
throw new NotApplicableException("Could not convert value \"$value\" to float!");
case 'bool':
if (is_null($value)) return false;
return Utils::parseBool($value);
case 'string':
if (is_null($value)) return "";
return "$value";
default: