diff options
author | Egor <egor.26.93@gmail.com> | 2015-06-14 22:40:16 +0300 |
---|---|---|
committer | Egor <egor.26.93@gmail.com> | 2015-06-14 22:40:16 +0300 |
commit | a934bef8432cd33e50305fe70db761ff3b9b7486 (patch) | |
tree | 307fa3c0b41780232bb59c223cc2dce1b11cafac | |
parent | 9abd184a386a2594398df9f5cd7bd6d5b9c240fc (diff) | |
download | connector-php-a934bef8432cd33e50305fe70db761ff3b9b7486.zip connector-php-a934bef8432cd33e50305fe70db761ff3b9b7486.tar.gz connector-php-a934bef8432cd33e50305fe70db761ff3b9b7486.tar.bz2 |
Added connector for phpcake version 2.
-rwxr-xr-x | codebase/Dhtmlx/Connector/DataStorage/PHPCake2DBDataWrapper.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/codebase/Dhtmlx/Connector/DataStorage/PHPCake2DBDataWrapper.php b/codebase/Dhtmlx/Connector/DataStorage/PHPCake2DBDataWrapper.php new file mode 100755 index 0000000..7b31f77 --- /dev/null +++ b/codebase/Dhtmlx/Connector/DataStorage/PHPCake2DBDataWrapper.php @@ -0,0 +1,76 @@ +<?php
+namespace Dhtmlx\Connector\DataStorage;
+use \Exception;
+
+class PHPCake2DBDataWrapper extends ArrayDBDataWrapper {
+ public function select($sql){
+ $source = $sql->get_source();
+ if (is_array($source)) //result of find
+ $res = $source;
+ else
+ $res = $this->connection->find("all");
+
+ $temp = array();
+ if (sizeof($res)){
+ $name = get_class($this->connection);
+ for ($i=sizeof($res)-1; $i>=0; $i--)
+ $temp[]=&$res[$i][$name];
+ }
+ 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);
+ $save = array();
+ $temp_data = $data->get_data();
+ unset($temp_data[$this->config->id['db_name']]);
+ unset($temp_data["!nativeeditor_status"]);
+ $save[$name] = $temp_data;
+
+ if ($this->connection->save($save)){
+ $data->success($this->connection->getLastInsertID());
+ } else {
+ $data->set_response_attribute("details", $this->getErrorMessage());
+ $data->invalid();
+ }
+ }
+ public function delete($data,$source){
+ $id = $data->get_id();
+ $this->connection->delete($id);
+ $data->success();
+ }
+ public function update($data,$source){
+ $name = get_class($this->connection);
+ $save = array();
+ $save[$name] = &$data->get_data();
+
+ if ($this->connection->save($save)){
+ $data->success();
+ } else {
+ $data->set_response_attribute("details", $this->getErrorMessage());
+ $data->invalid();
+ }
+ }
+
+
+ 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 |