From 5f566df68e943fb5360fadc445ce21fe4dcf7efc Mon Sep 17 00:00:00 2001 From: maximXbs Date: Mon, 29 Feb 2016 21:25:52 +0300 Subject: [PATCH 1/2] fixes for incorrect rendering and handling actions like insert/update/delete for Gantt connector --- codebase/Dhtmlx/Connector/Data/DataItem.php | 10 +++++-- .../DataStorage/PHPLaravelDBDataWrapper.php | 28 +++++++++++++++---- codebase/Dhtmlx/Connector/GanttConnector.php | 6 ++-- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/codebase/Dhtmlx/Connector/Data/DataItem.php b/codebase/Dhtmlx/Connector/Data/DataItem.php index 09ba8a0..8f317f2 100644 --- a/codebase/Dhtmlx/Connector/Data/DataItem.php +++ b/codebase/Dhtmlx/Connector/Data/DataItem.php @@ -59,10 +59,14 @@ public function set_value($name,$value){ id of element */ public function get_id(){ + $return = false; $id = $this->config->id["name"]; - if (array_key_exists($id,$this->data)) - return $this->data[$id]; - return false; + if ((is_array($this->data) && array_key_exists($id,$this->data)) || + (is_object($this->data) && property_exists($this->data,'attributes') && isset($this->data[$id])) + ){ + $return = $this->data[$id]; + } + return $return; } /*! change id of element diff --git a/codebase/Dhtmlx/Connector/DataStorage/PHPLaravelDBDataWrapper.php b/codebase/Dhtmlx/Connector/DataStorage/PHPLaravelDBDataWrapper.php index b99fd0f..cee476b 100755 --- a/codebase/Dhtmlx/Connector/DataStorage/PHPLaravelDBDataWrapper.php +++ b/codebase/Dhtmlx/Connector/DataStorage/PHPLaravelDBDataWrapper.php @@ -35,8 +35,14 @@ protected function getErrorMessage() { } public function insert($data, $source) { - $className = get_class($source->get_source()); - $obj = new $className(); + $obj = null; + if(method_exists($source->get_source(), 'getModel')){ + $obj = $source->get_source()->getModel()->newInstance(); + } else { + $className = get_class($source->get_source()); + $obj = new $className(); + } + $this->fill_model($obj, $data)->save(); $fieldPrimaryKey = $this->config->id["db_name"]; @@ -44,14 +50,24 @@ public function insert($data, $source) { } public function delete($data, $source) { - $className = get_class($source->get_source()); - $className::destroy($data->get_id()); + if(method_exists($source->get_source(), 'getModel')){ + $source->get_source()->getModel()->find($data->get_id())->delete(); + } else { + $className = get_class($source->get_source()); + $className::destroy($data->get_id()); + } $data->success(); } public function update($data, $source) { - $className = get_class($source->get_source()); - $obj = $className::find($data->get_id()); + $obj = null; + if(method_exists($source->get_source(), 'getModel')){ + $obj = $source->get_source()->getModel()->find($data->get_id()); + } else { + $className = get_class($source->get_source()); + $obj = $className::find($data->get_id()); + } + $this->fill_model($obj, $data)->save(); $data->success(); } diff --git a/codebase/Dhtmlx/Connector/GanttConnector.php b/codebase/Dhtmlx/Connector/GanttConnector.php index e581386..8df7762 100755 --- a/codebase/Dhtmlx/Connector/GanttConnector.php +++ b/codebase/Dhtmlx/Connector/GanttConnector.php @@ -96,11 +96,9 @@ function order_set_parent($action){ function delete_related_links($action){ if (isset($this->options["links"])){ $links = $this->options["links"]; - $value = $this->sql->escape($action->get_new_id()); + $value = $action->get_new_id(); $table = $links->get_request()->get_source(); - - $this->sql->query("DELETE FROM $table WHERE source = '$value'"); - $this->sql->query("DELETE FROM $table WHERE target = '$value'"); + $table->where('source', '=', $value)->orWhere('target', '=', $value)->delete(); } } From de4bd7901ed6cac86a01ab1fe12b5b9b6f40247a Mon Sep 17 00:00:00 2001 From: maximXbs Date: Tue, 1 Mar 2016 13:36:17 +0300 Subject: [PATCH 2/2] some changes for the GanttConnector --- codebase/Dhtmlx/Connector/GanttConnector.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/codebase/Dhtmlx/Connector/GanttConnector.php b/codebase/Dhtmlx/Connector/GanttConnector.php index 8df7762..a2ceae8 100755 --- a/codebase/Dhtmlx/Connector/GanttConnector.php +++ b/codebase/Dhtmlx/Connector/GanttConnector.php @@ -96,9 +96,14 @@ function order_set_parent($action){ function delete_related_links($action){ if (isset($this->options["links"])){ $links = $this->options["links"]; - $value = $action->get_new_id(); + $value = $this->sql->escape($action->get_new_id()); $table = $links->get_request()->get_source(); - $table->where('source', '=', $value)->orWhere('target', '=', $value)->delete(); + if(method_exists($table, 'getModel') && method_exists($table->getModel(), 'getTable')){ + $table->where('source', '=', $value)->orWhere('target', '=', $value)->delete(); + } else { + $this->sql->query("DELETE FROM $table WHERE source = $value"); + $this->sql->query("DELETE FROM $table WHERE target = $value"); + } } }