summaryrefslogtreecommitdiffstats
path: root/codebase
diff options
context:
space:
mode:
authorStanislav-Wolski <stanislau.wolski@gmail.com>2012-05-23 16:01:17 +0300
committerStanislav-Wolski <stanislau.wolski@gmail.com>2012-05-23 16:01:17 +0300
commit20dee97f248150fdeec70dc0d8314bb1677f5eb3 (patch)
tree97422cd6d0e049ccb7c19356b9d2d74f3c7fd1de /codebase
parentfc6240c00fb8acba8700749ebb2b2e40dd85fc41 (diff)
downloadconnector-php-20dee97f248150fdeec70dc0d8314bb1677f5eb3.zip
connector-php-20dee97f248150fdeec70dc0d8314bb1677f5eb3.tar.gz
connector-php-20dee97f248150fdeec70dc0d8314bb1677f5eb3.tar.bz2
[add] support for php-yii, better looging
Diffstat (limited to 'codebase')
-rw-r--r--codebase/dataprocessor.php2
-rw-r--r--codebase/db_phpyii.php88
2 files changed, 90 insertions, 0 deletions
diff --git a/codebase/dataprocessor.php b/codebase/dataprocessor.php
index 80af207..74852e2 100644
--- a/codebase/dataprocessor.php
+++ b/codebase/dataprocessor.php
@@ -98,6 +98,7 @@ class DataProcessor{
}
} catch(Exception $e){
+ LogMaster::log($e);
$failed=true;
}
@@ -169,6 +170,7 @@ class DataProcessor{
}
} catch (Exception $e){
+ LogMaster::log($e);
$action->set_status("error");
if ($action)
$this->connector->event->trigger("onDBError", $action, $e);
diff --git a/codebase/db_phpyii.php b/codebase/db_phpyii.php
new file mode 100644
index 0000000..41066ee
--- /dev/null
+++ b/codebase/db_phpyii.php
@@ -0,0 +1,88 @@
+<?php
+/*
+ @author dhtmlx.com
+ @license GPL, see license.txt
+*/
+
+require_once("db_common.php");
+
+class PHPYiiDBDataWrapper extends ArrayDBDataWrapper{
+ public function select($sql){
+ $res = $this->connection->findAll();
+ if (sizeof($res)){
+ $name = get_class($this->connection);
+ $temp = array();
+ foreach ($res as $obj)
+ $temp[]=&$obj->getAttributes();
+ }
+ return new ArrayQueryWrapper($temp);
+ }
+
+ protected function getErrorMessage(){
+ $errors = $this->connection->invalidFields();
+ $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);
+ $obj = new $name();
+
+ $this->fill_model_and_save($obj, $data);
+ }
+ public function delete($data,$source){
+ $obj = $this->connection->findByPk($data->get_id());
+ if ($obj->delete()){
+ $data->success();
+ $data->set_new_id($obj->getPrimaryKey());
+ } else {
+ $data->set_response_attribute("details", $this->errors_to_string($obj->getErrors()));
+ $data->invalid();
+ }
+ }
+ public function update($data,$source){
+ $obj = $this->connection->findByPk($data->get_id());
+ $this->fill_model_and_save($obj, $data);
+ }
+
+ protected function fill_model_and_save($obj, $data){
+ $values = $data->get_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();
+ $data->set_new_id($obj->getPrimaryKey());
+ } else {
+ $data->set_response_attribute("details", $this->errors_to_string($obj->getErrors()));
+ $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");
+ }
+}
+
+?> \ No newline at end of file