diff options
author | Egor <egor.26.93@gmail.com> | 2015-06-15 22:08:43 +0300 |
---|---|---|
committer | Egor <egor.26.93@gmail.com> | 2015-06-15 22:08:43 +0300 |
commit | 21af0503ad129c8cd83ec355638e7aa029c42af6 (patch) | |
tree | f37966ce737ad7d49a162fb7dd46089f4aa4961d /codebase | |
parent | 4b45cf326019de4604bd01fb098a2b43c940a789 (diff) | |
download | connector-php-21af0503ad129c8cd83ec355638e7aa029c42af6.zip connector-php-21af0503ad129c8cd83ec355638e7aa029c42af6.tar.gz connector-php-21af0503ad129c8cd83ec355638e7aa029c42af6.tar.bz2 |
Updated connectors for phpcake 3 and yii2.
Diffstat (limited to 'codebase')
-rw-r--r-- | codebase/db_phpcake.php | 52 | ||||
-rwxr-xr-x | codebase/db_phplaravel.php | 75 | ||||
-rw-r--r-- | codebase/db_phpyii.php | 30 |
3 files changed, 55 insertions, 102 deletions
diff --git a/codebase/db_phpcake.php b/codebase/db_phpcake.php index 99eb723..92b5134 100644 --- a/codebase/db_phpcake.php +++ b/codebase/db_phpcake.php @@ -12,16 +12,21 @@ require_once("db_common.php"); if you plan to use it for Oracle - use Oracle connection type instead **/ class PHPCakeDBDataWrapper extends ArrayDBDataWrapper { - public function select($sql) { - if(is_array($this->connection)) //result of findAll - $query = $this->connection; - else - $query = $this->connection->find("all"); - $temp = array(); - foreach($query as $row) - $temp[] = $row->toArray(); - return new ArrayQueryWrapper($temp); -} + + public function select($source) { + $sourceData = $source->get_source(); + if(is_array($sourceData)) //result of find + $query = $sourceData; + else + $query = $sourceData->find("all"); + + $temp = array(); + foreach($query as $row) + $temp[] = $row->toArray(); + + return new ArrayQueryWrapper($temp); + } + protected function getErrorMessage() { $errors = $this->connection->invalidFields(); $text = array(); @@ -30,40 +35,49 @@ class PHPCakeDBDataWrapper extends ArrayDBDataWrapper { } return implode("\n", $text); } + public function insert($data, $source) { - $table = TableRegistry::get($source->get_source()); - $obj = $table->newEntity(); + $sourceData = $source->get_source(); + $obj = $sourceData->newEntity(); $obj = $this->fillModel($obj, $data); - $savedResult = $this->connection->save($obj); + $savedResult = $source->get_source()->save($obj); $data->success($savedResult->get($this->config->id["db_name"])); } + public function delete($data, $source) { - $table = TableRegistry::get($source->get_source()); - $obj = $table->get($data->get_id()); - $this->connection->delete($obj); + $sourceData = $source->get_source(); + $obj = $sourceData->get($data->get_id()); + $source->get_source()->delete($obj); } + public function update($data, $source) { - $table = TableRegistry::get($source->get_source()); - $obj = $table->get($data->get_id()); + $sourceData = $source->get_source(); + $obj = $sourceData->get($data->get_id()); $obj = $this->fillModel($obj, $data); - $table->save($obj); + $sourceData->save($obj); } + private function fillModel($obj, $data) { //Map data to model object. for($i = 0; $i < count($this->config->text); $i++) { $step=$this->config->text[$i]; $obj->set($step["name"], $data->get_value($step["name"])); } + if($relation = $this->config->relation_id["db_name"]) $obj->set($relation, $data->get_value($relation)); + return $obj; } + 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"); } diff --git a/codebase/db_phplaravel.php b/codebase/db_phplaravel.php deleted file mode 100755 index 54f371f..0000000 --- a/codebase/db_phplaravel.php +++ /dev/null @@ -1,75 +0,0 @@ -<?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 diff --git a/codebase/db_phpyii.php b/codebase/db_phpyii.php index 80b44c3..1d8d5d1 100644 --- a/codebase/db_phpyii.php +++ b/codebase/db_phpyii.php @@ -7,12 +7,14 @@ require_once("db_common.php"); class PHPYiiDBDataWrapper extends ArrayDBDataWrapper { - - public function select($sql) { - if(is_array($this->connection)) //result of findAll - $res = $this->connection; + + public function select($source) { + $sourceData = $source->get_source(); + if(is_array($sourceData)) //result of find + $res = $sourceData; else - $res = $this->connection->find()->all(); + $res = $sourceData->find()->all(); + $temp = array(); if(sizeof($res)) { foreach($res as $obj) @@ -20,20 +22,23 @@ class PHPYiiDBDataWrapper extends ArrayDBDataWrapper { } return new ArrayQueryWrapper($temp); } + 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) { - $name = get_class($this->connection); + $name = get_class($source->get_source()); $obj = new $name(); $this->fill_model_and_save($obj, $data); } + public function delete($data, $source) { - $obj = $this->connection->findOne($data->get_id()); + $obj = $source->get_source()->findOne($data->get_id()); if($obj->delete()) { $data->success(); $data->set_new_id($obj->getPrimaryKey()); @@ -43,18 +48,22 @@ class PHPYiiDBDataWrapper extends ArrayDBDataWrapper { $data->invalid(); } } + public function update($data, $source) { - $obj = $this->connection->findOne($data->get_id()); + $obj = $source->get_source()->findOne($data->get_id()); $this->fill_model_and_save($obj, $data); } + protected function fill_model_and_save($obj, $data) { //Map data to model object. for($i=0; $i < sizeof($this->config->text); $i++) { $step=$this->config->text[$i]; $obj->setAttribute($step["name"], $data->get_value($step["name"])); } + if($relation = $this->config->relation_id["db_name"]) $obj->setAttribute($relation, $data->get_value($relation)); + //Save model. if($obj->save()) { $data->success(); @@ -65,18 +74,23 @@ class PHPYiiDBDataWrapper extends ArrayDBDataWrapper { $data->invalid(); } } + 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"); } |