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/db_phpcake.php | |
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/db_phpcake.php')
-rw-r--r-- | codebase/db_phpcake.php | 52 |
1 files changed, 33 insertions, 19 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"); } |