summaryrefslogtreecommitdiffstats
path: root/codebase/db_phpyii.php
diff options
context:
space:
mode:
authorEgor <egor.26.93@gmail.com>2015-06-15 22:08:43 +0300
committerEgor <egor.26.93@gmail.com>2015-06-15 22:08:43 +0300
commit21af0503ad129c8cd83ec355638e7aa029c42af6 (patch)
treef37966ce737ad7d49a162fb7dd46089f4aa4961d /codebase/db_phpyii.php
parent4b45cf326019de4604bd01fb098a2b43c940a789 (diff)
downloadconnector-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_phpyii.php')
-rw-r--r--codebase/db_phpyii.php30
1 files changed, 22 insertions, 8 deletions
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");
}