summaryrefslogtreecommitdiffstats
path: root/codebase
diff options
context:
space:
mode:
Diffstat (limited to 'codebase')
-rw-r--r--codebase/db_phpcake.php125
-rw-r--r--codebase/db_phpcake2.php85
-rw-r--r--codebase/db_phpyii.php154
-rw-r--r--codebase/db_phpyii1.php91
4 files changed, 306 insertions, 149 deletions
diff --git a/codebase/db_phpcake.php b/codebase/db_phpcake.php
index 4df0289..99eb723 100644
--- a/codebase/db_phpcake.php
+++ b/codebase/db_phpcake.php
@@ -11,75 +11,62 @@ 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){
- $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");
- }
+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);
+}
+ 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) {
+ $table = TableRegistry::get($source->get_source());
+ $obj = $table->newEntity();
+ $obj = $this->fillModel($obj, $data);
+ $savedResult = $this->connection->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);
+ }
+ public function update($data, $source) {
+ $table = TableRegistry::get($source->get_source());
+ $obj = $table->get($data->get_id());
+ $obj = $this->fillModel($obj, $data);
+ $table->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");
+ }
}
?> \ No newline at end of file
diff --git a/codebase/db_phpcake2.php b/codebase/db_phpcake2.php
new file mode 100644
index 0000000..76a941d
--- /dev/null
+++ b/codebase/db_phpcake2.php
@@ -0,0 +1,85 @@
+<?php
+/*
+ @author dhtmlx.com
+ @license GPL, see license.txt
+*/
+require_once("db_common.php");
+
+//DataProcessor::$action_param ="dhx_editor_status";
+
+/*! Implementation of DataWrapper for PDO
+
+if you plan to use it for Oracle - use Oracle connection type instead
+**/
+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
diff --git a/codebase/db_phpyii.php b/codebase/db_phpyii.php
index 616d7f3..80b44c3 100644
--- a/codebase/db_phpyii.php
+++ b/codebase/db_phpyii.php
@@ -6,86 +6,80 @@
require_once("db_common.php");
-class PHPYiiDBDataWrapper extends ArrayDBDataWrapper{
- public function select($sql){
- if (is_array($this->connection)) //result of findAll
- $res = $this->connection;
- else
- $res = $this->connection->findAll();
-
- $temp = array();
- if (sizeof($res)){
- 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");
- }
+class PHPYiiDBDataWrapper extends ArrayDBDataWrapper {
+
+ public function select($sql) {
+ if(is_array($this->connection)) //result of findAll
+ $res = $this->connection;
+ else
+ $res = $this->connection->find()->all();
+ $temp = array();
+ if(sizeof($res)) {
+ foreach($res as $obj)
+ $temp[] = $obj->getAttributes();
+ }
+ 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);
+ $obj = new $name();
+ $this->fill_model_and_save($obj, $data);
+ }
+ public function delete($data, $source) {
+ $obj = $this->connection->findOne($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->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();
+ $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
diff --git a/codebase/db_phpyii1.php b/codebase/db_phpyii1.php
new file mode 100644
index 0000000..616d7f3
--- /dev/null
+++ b/codebase/db_phpyii1.php
@@ -0,0 +1,91 @@
+<?php
+/*
+ @author dhtmlx.com
+ @license GPL, see license.txt
+*/
+
+require_once("db_common.php");
+
+class PHPYiiDBDataWrapper extends ArrayDBDataWrapper{
+ public function select($sql){
+ if (is_array($this->connection)) //result of findAll
+ $res = $this->connection;
+ else
+ $res = $this->connection->findAll();
+
+ $temp = array();
+ if (sizeof($res)){
+ 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