|
|
|
@ -276,6 +276,41 @@ class Changeset |
|
|
|
|
return $cachedColumns = $newOrder; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param string $id |
|
|
|
|
* @return Column |
|
|
|
|
*/ |
|
|
|
|
public function fetchColumn(string $id) |
|
|
|
|
{ |
|
|
|
|
if ($this->isNewColumn($id)) { |
|
|
|
|
$c = new Column($this->newColumns[$id]); |
|
|
|
|
$c->markAsNew(); |
|
|
|
|
return $c; |
|
|
|
|
} else { |
|
|
|
|
$columns = collect($this->revision->columns)->keyBy('id'); |
|
|
|
|
return new Column($columns[$id]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param string $id |
|
|
|
|
* @return Column |
|
|
|
|
*/ |
|
|
|
|
public function fetchAndTransformColumn(string $id) |
|
|
|
|
{ |
|
|
|
|
$column = $this->fetchColumn($id); |
|
|
|
|
|
|
|
|
|
if (isset($this->columnUpdates[$column->id])) { |
|
|
|
|
$column->modifyByChangeset($this->columnUpdates[$column->id]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (in_array($column->id, $this->removedColumns)) { |
|
|
|
|
$column->markForRemoval(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $column; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function rowRemove(int $id) |
|
|
|
|
{ |
|
|
|
|
if ($this->isNewRow($id)) { |
|
|
|
@ -296,6 +331,11 @@ class Changeset |
|
|
|
|
return isset($this->newRows[$id]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function isNewColumn(string $id) |
|
|
|
|
{ |
|
|
|
|
return isset($this->newColumns[$id]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function fetchAndTransformRow(int $id) |
|
|
|
|
{ |
|
|
|
|
$r = $this->fetchRow($id); |
|
|
|
@ -337,6 +377,7 @@ class Changeset |
|
|
|
|
* if all differences were undone. |
|
|
|
|
* |
|
|
|
|
* @param array|object $newVals - values of the new row |
|
|
|
|
* @return object - updated column |
|
|
|
|
*/ |
|
|
|
|
public function rowUpdate($newVals) |
|
|
|
|
{ |
|
|
|
@ -373,6 +414,56 @@ class Changeset |
|
|
|
|
unset($this->rowUpdates[$_id]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $this->fetchAndTransformRow($_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param $newVals |
|
|
|
|
* @return Column |
|
|
|
|
*/ |
|
|
|
|
public function columnUpdate($newVals) |
|
|
|
|
{ |
|
|
|
|
$id = $newVals->id; |
|
|
|
|
$col = $this->fetchColumn($id); |
|
|
|
|
|
|
|
|
|
$updateObj = []; |
|
|
|
|
foreach ($newVals as $field => $value) { |
|
|
|
|
if (starts_with($field, '_')) continue; // internals |
|
|
|
|
|
|
|
|
|
if ($value !== $col->$field) { |
|
|
|
|
$updateObj[$field] = $value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($this->isNewColumn($id)) { |
|
|
|
|
$this->newColumns[$id] = array_merge($this->newColumns[$id], $updateObj); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
if (!empty($updateObj)) { |
|
|
|
|
$this->columnUpdates[$id] = $updateObj; |
|
|
|
|
} else { |
|
|
|
|
// remove possible old update record for this row, if nothing changes now |
|
|
|
|
unset($this->columnUpdates[$id]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $this->fetchAndTransformColumn($id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function columnRemove(string $id) |
|
|
|
|
{ |
|
|
|
|
if ($this->isNewColumn($id)) { |
|
|
|
|
unset($this->newColumns[$id]); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$this->removedColumns[] = $id; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function columnRestore(string $id) |
|
|
|
|
{ |
|
|
|
|
$this->removedColumns = array_diff($this->removedColumns, [$id]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -464,4 +555,22 @@ class Changeset |
|
|
|
|
|
|
|
|
|
$this->newRows = array_merge($this->newRows, $rows->all()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function addBlankCol() |
|
|
|
|
{ |
|
|
|
|
$cid = (new ColumnNumerator(1))->next(); |
|
|
|
|
|
|
|
|
|
$allCols = $this->fetchAndTransformColumns(); |
|
|
|
|
$num = count($allCols) + 1; |
|
|
|
|
|
|
|
|
|
$col = [ |
|
|
|
|
'name' => "col_{$num}", |
|
|
|
|
'type' => "string", |
|
|
|
|
'title' => "Column {$num}", |
|
|
|
|
'id' => $cid, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$this->newColumns[$cid] = $col; |
|
|
|
|
return $col; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|