mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
Added save in onItemMoved
This commit is contained in:
parent
e9b4dea6c5
commit
589000fb6c
@ -144,7 +144,8 @@ function createVisualConsole(
|
|||||||
var id = e.item.props.id;
|
var id = e.item.props.id;
|
||||||
var data = {
|
var data = {
|
||||||
x: e.newPosition.x,
|
x: e.newPosition.x,
|
||||||
y: e.newPosition.y
|
y: e.newPosition.y,
|
||||||
|
type: e.item.props.type
|
||||||
};
|
};
|
||||||
var taskId = "visual-console-item-move-" + id;
|
var taskId = "visual-console-item-move-" + id;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ use Models\VisualConsole\Container as VisualConsole;
|
|||||||
$visualConsoleId = (int) get_parameter('visualConsoleId');
|
$visualConsoleId = (int) get_parameter('visualConsoleId');
|
||||||
$getVisualConsole = (bool) get_parameter('getVisualConsole');
|
$getVisualConsole = (bool) get_parameter('getVisualConsole');
|
||||||
$getVisualConsoleItems = (bool) get_parameter('getVisualConsoleItems');
|
$getVisualConsoleItems = (bool) get_parameter('getVisualConsoleItems');
|
||||||
|
$updateVisualConsoleItem = (bool) get_parameter('updateVisualConsoleItem');
|
||||||
|
|
||||||
// Check groups can access user.
|
// Check groups can access user.
|
||||||
$aclUserGroups = [];
|
$aclUserGroups = [];
|
||||||
@ -44,6 +45,21 @@ if ($getVisualConsole === true) {
|
|||||||
} else if ($getVisualConsoleItems === true) {
|
} else if ($getVisualConsoleItems === true) {
|
||||||
$vcItems = VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups);
|
$vcItems = VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups);
|
||||||
echo '['.implode($vcItems, ',').']';
|
echo '['.implode($vcItems, ',').']';
|
||||||
|
} else if ($updateVisualConsoleItem === true) {
|
||||||
|
$visualConsoleId = (integer) get_parameter('visualConsoleId');
|
||||||
|
$visualConsoleItemId = (integer) get_parameter('visualConsoleItemId');
|
||||||
|
$data = get_parameter('data');
|
||||||
|
|
||||||
|
$class = VisualConsole::getItemClass($data['type']);
|
||||||
|
|
||||||
|
$item_data = [];
|
||||||
|
$item_data['id'] = $visualConsoleItemId;
|
||||||
|
$item_data['id_layout'] = $visualConsoleId;
|
||||||
|
$item_data['type'] = $data['type'];
|
||||||
|
|
||||||
|
$item = $class::fromDB($item_data);
|
||||||
|
|
||||||
|
$item->save($item->toArray(), $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
@ -68,7 +68,7 @@ abstract class Model
|
|||||||
*
|
*
|
||||||
* @abstract
|
* @abstract
|
||||||
*/
|
*/
|
||||||
abstract public function save(array $data=[]): bool;
|
abstract public function save(array $data=[], array $newdata=[]);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +93,7 @@ abstract class Model
|
|||||||
*
|
*
|
||||||
* @return self Instance of the model.
|
* @return self Instance of the model.
|
||||||
*/
|
*/
|
||||||
public static function fromArray(array $data)
|
public static function fromArray(array $data): self
|
||||||
{
|
{
|
||||||
// The reserved word static refers to the invoked class at runtime.
|
// The reserved word static refers to the invoked class at runtime.
|
||||||
return new static($data);
|
return new static($data);
|
||||||
|
@ -117,7 +117,7 @@ final class Container extends Model
|
|||||||
*
|
*
|
||||||
* @overrides Model::save.
|
* @overrides Model::save.
|
||||||
*/
|
*/
|
||||||
public function save(array $data=[]): bool
|
public function save(array $data=[], array $newdata=[]): bool
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -396,7 +396,6 @@ final class Container extends Model
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
array_push($items, $class::fromDB($data));
|
array_push($items, $class::fromDB($data));
|
||||||
hd($class::save($data), true);
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// TODO: Log this?
|
// TODO: Log this?
|
||||||
}
|
}
|
||||||
|
@ -1627,24 +1627,33 @@ class Item extends CachedModel
|
|||||||
*
|
*
|
||||||
* @overrides Model::save.
|
* @overrides Model::save.
|
||||||
*/
|
*/
|
||||||
public function save(array $data=[]): bool
|
public function save(array $data=[], array $newdata=[])
|
||||||
{
|
{
|
||||||
$save = static::encode($data);
|
$save = self::encode($data);
|
||||||
|
$newSave = self::encode($newdata);
|
||||||
|
|
||||||
|
$save = \array_merge($save, $newSave);
|
||||||
|
|
||||||
|
if (!empty($save)) {
|
||||||
if (empty($save['id'])) {
|
if (empty($save['id'])) {
|
||||||
// Insert.
|
// Insert.
|
||||||
$result = \db_process_sql_insert('tlayout_data', $save);
|
$result = \db_process_sql_insert('tlayout_data', $save);
|
||||||
// static = static::fromDB(['id' => $result]);
|
|
||||||
} else {
|
} else {
|
||||||
// Update.
|
// Update.
|
||||||
$result = \db_process_sql_update('tlayout_data', $save, ['id' => $save['id']]);
|
$result = \db_process_sql_update('tlayout_data', $save, ['id' => $save['id']]);
|
||||||
// static = static::fromDB(['id' => $save['id']]);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the model.
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
if (empty($save['id'])) {
|
||||||
|
$item = static::fromDB(['id' => $result]);
|
||||||
|
} else {
|
||||||
|
$item = static::fromDB(['id' => $save['id']]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ final class Line extends Model
|
|||||||
*
|
*
|
||||||
* @overrides Model::save.
|
* @overrides Model::save.
|
||||||
*/
|
*/
|
||||||
public function save(array $data=[]): bool
|
public function save(array $data=[], array $newdata=[]): bool
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user