summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgor <egor.26.93@gmail.com>2015-06-15 18:07:26 +0300
committerEgor <egor.26.93@gmail.com>2015-06-15 18:07:26 +0300
commitee431bfd4ea730ba5b096183427b16c4bf0ec5cb (patch)
treee85511848d55de7e682aba864591790fc22fb524
parenta934bef8432cd33e50305fe70db761ff3b9b7486 (diff)
downloadconnector-php-ee431bfd4ea730ba5b096183427b16c4bf0ec5cb.zip
connector-php-ee431bfd4ea730ba5b096183427b16c4bf0ec5cb.tar.gz
connector-php-ee431bfd4ea730ba5b096183427b16c4bf0ec5cb.tar.bz2
Added connector for Laravel 5.1 framework.
-rwxr-xr-xcodebase/Dhtmlx/Connector/DataStorage/PHPLaravelDBDataWrapper.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/codebase/Dhtmlx/Connector/DataStorage/PHPLaravelDBDataWrapper.php b/codebase/Dhtmlx/Connector/DataStorage/PHPLaravelDBDataWrapper.php
new file mode 100755
index 0000000..54f371f
--- /dev/null
+++ b/codebase/Dhtmlx/Connector/DataStorage/PHPLaravelDBDataWrapper.php
@@ -0,0 +1,75 @@
+<?php
+namespace Dhtmlx\Connector\DataStorage;
+use Dhtmlx\Connector\DataProcessor\DataProcessor;
+use \Exception;
+
+class PHPLaravelDBDataWrapper extends ArrayDBDataWrapper {
+
+ public function select($source) {
+ $className = $source->get_source();
+ return new ArrayQueryWrapper($className::all()->toArray());
+ }
+
+ protected function getErrorMessage() {
+ $errors = $this->connection->getErrors();
+ $text = array();
+ foreach($errors as $key => $value)
+ $text[] = $key." - ".$value[0];
+
+ return implode("\n", $text);
+ }
+
+ public function insert($data, $source) {
+ $className = $source->get_source();
+ $obj = $className::create();
+ $this->fill_model_data($obj, $data)->save();
+
+ $fieldPrimaryKey = $this->config->id["db_name"];
+ $data->success($obj->$fieldPrimaryKey);
+ }
+
+ public function delete($data, $source) {
+ $className = $source->get_source();
+ $className::destroy($data->get_id());
+ $data->success();
+ }
+
+ public function update($data, $source) {
+ $className = $source->get_source();
+ $obj = $className::find($data->get_id());
+ $this->fill_model_data($obj, $data)->save();
+ $data->success();
+ }
+
+ private function fill_model_data($obj, $data) {
+ $dataArray = $data->get_data();
+ unset($dataArray[DataProcessor::$action_param]);
+ unset($dataArray[$this->config->id["db_name"]]);
+
+ foreach($dataArray as $key => $value)
+ $obj->$key = $value;
+
+ return $obj;
+ }
+
+ protected function errors_to_string($errors) {
+ $text = array();
+ foreach($errors as $value)
+ $text[] = implode("\n", $value);
+
+ return implode("\n",$text);
+ }
+
+ public function escape($str) {
+ throw new Exception("Not implemented");
+ }
+
+ public function query($str) {
+ throw new Exception("Not implemented");
+ }
+
+ public function get_new_id() {
+ throw new Exception("Not implemented");
+ }
+
+} \ No newline at end of file