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..a2ceae8 100755 --- a/codebase/Dhtmlx/Connector/GanttConnector.php +++ b/codebase/Dhtmlx/Connector/GanttConnector.php @@ -98,9 +98,12 @@ function delete_related_links($action){ $links = $this->options["links"]; $value = $this->sql->escape($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'"); + 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"); + } } }