Skip to content

Commit 21af050

Browse files
Updated connectors for phpcake 3 and yii2.
1 parent 4b45cf3 commit 21af050

File tree

3 files changed

+55
-102
lines changed

3 files changed

+55
-102
lines changed

codebase/db_phpcake.php

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@
1212
if you plan to use it for Oracle - use Oracle connection type instead
1313
**/
1414
class PHPCakeDBDataWrapper extends ArrayDBDataWrapper {
15-
public function select($sql) {
16-
if(is_array($this->connection)) //result of findAll
17-
$query = $this->connection;
18-
else
19-
$query = $this->connection->find("all");
20-
$temp = array();
21-
foreach($query as $row)
22-
$temp[] = $row->toArray();
23-
return new ArrayQueryWrapper($temp);
24-
}
15+
16+
public function select($source) {
17+
$sourceData = $source->get_source();
18+
if(is_array($sourceData)) //result of find
19+
$query = $sourceData;
20+
else
21+
$query = $sourceData->find("all");
22+
23+
$temp = array();
24+
foreach($query as $row)
25+
$temp[] = $row->toArray();
26+
27+
return new ArrayQueryWrapper($temp);
28+
}
29+
2530
protected function getErrorMessage() {
2631
$errors = $this->connection->invalidFields();
2732
$text = array();
@@ -30,40 +35,49 @@ protected function getErrorMessage() {
3035
}
3136
return implode("\n", $text);
3237
}
38+
3339
public function insert($data, $source) {
34-
$table = TableRegistry::get($source->get_source());
35-
$obj = $table->newEntity();
40+
$sourceData = $source->get_source();
41+
$obj = $sourceData->newEntity();
3642
$obj = $this->fillModel($obj, $data);
37-
$savedResult = $this->connection->save($obj);
43+
$savedResult = $source->get_source()->save($obj);
3844
$data->success($savedResult->get($this->config->id["db_name"]));
3945
}
46+
4047
public function delete($data, $source) {
41-
$table = TableRegistry::get($source->get_source());
42-
$obj = $table->get($data->get_id());
43-
$this->connection->delete($obj);
48+
$sourceData = $source->get_source();
49+
$obj = $sourceData->get($data->get_id());
50+
$source->get_source()->delete($obj);
4451
}
52+
4553
public function update($data, $source) {
46-
$table = TableRegistry::get($source->get_source());
47-
$obj = $table->get($data->get_id());
54+
$sourceData = $source->get_source();
55+
$obj = $sourceData->get($data->get_id());
4856
$obj = $this->fillModel($obj, $data);
49-
$table->save($obj);
57+
$sourceData->save($obj);
5058
}
59+
5160
private function fillModel($obj, $data) {
5261
//Map data to model object.
5362
for($i = 0; $i < count($this->config->text); $i++) {
5463
$step=$this->config->text[$i];
5564
$obj->set($step["name"], $data->get_value($step["name"]));
5665
}
66+
5767
if($relation = $this->config->relation_id["db_name"])
5868
$obj->set($relation, $data->get_value($relation));
69+
5970
return $obj;
6071
}
72+
6173
public function escape($str){
6274
throw new Exception("Not implemented");
6375
}
76+
6477
public function query($str){
6578
throw new Exception("Not implemented");
6679
}
80+
6781
public function get_new_id(){
6882
throw new Exception("Not implemented");
6983
}

codebase/db_phplaravel.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

codebase/db_phpyii.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,38 @@
77
require_once("db_common.php");
88

99
class PHPYiiDBDataWrapper extends ArrayDBDataWrapper {
10-
11-
public function select($sql) {
12-
if(is_array($this->connection)) //result of findAll
13-
$res = $this->connection;
10+
11+
public function select($source) {
12+
$sourceData = $source->get_source();
13+
if(is_array($sourceData)) //result of find
14+
$res = $sourceData;
1415
else
15-
$res = $this->connection->find()->all();
16+
$res = $sourceData->find()->all();
17+
1618
$temp = array();
1719
if(sizeof($res)) {
1820
foreach($res as $obj)
1921
$temp[] = $obj->getAttributes();
2022
}
2123
return new ArrayQueryWrapper($temp);
2224
}
25+
2326
protected function getErrorMessage() {
2427
$errors = $this->connection->getErrors();
2528
$text = array();
2629
foreach($errors as $key => $value)
2730
$text[] = $key." - ".$value[0];
31+
2832
return implode("\n", $text);
2933
}
3034
public function insert($data, $source) {
31-
$name = get_class($this->connection);
35+
$name = get_class($source->get_source());
3236
$obj = new $name();
3337
$this->fill_model_and_save($obj, $data);
3438
}
39+
3540
public function delete($data, $source) {
36-
$obj = $this->connection->findOne($data->get_id());
41+
$obj = $source->get_source()->findOne($data->get_id());
3742
if($obj->delete()) {
3843
$data->success();
3944
$data->set_new_id($obj->getPrimaryKey());
@@ -43,18 +48,22 @@ public function delete($data, $source) {
4348
$data->invalid();
4449
}
4550
}
51+
4652
public function update($data, $source) {
47-
$obj = $this->connection->findOne($data->get_id());
53+
$obj = $source->get_source()->findOne($data->get_id());
4854
$this->fill_model_and_save($obj, $data);
4955
}
56+
5057
protected function fill_model_and_save($obj, $data) {
5158
//Map data to model object.
5259
for($i=0; $i < sizeof($this->config->text); $i++) {
5360
$step=$this->config->text[$i];
5461
$obj->setAttribute($step["name"], $data->get_value($step["name"]));
5562
}
63+
5664
if($relation = $this->config->relation_id["db_name"])
5765
$obj->setAttribute($relation, $data->get_value($relation));
66+
5867
//Save model.
5968
if($obj->save()) {
6069
$data->success();
@@ -65,18 +74,23 @@ protected function fill_model_and_save($obj, $data) {
6574
$data->invalid();
6675
}
6776
}
77+
6878
protected function errors_to_string($errors) {
6979
$text = array();
7080
foreach($errors as $value)
7181
$text[] = implode("\n", $value);
82+
7283
return implode("\n",$text);
7384
}
85+
7486
public function escape($str) {
7587
throw new Exception("Not implemented");
7688
}
89+
7790
public function query($str) {
7891
throw new Exception("Not implemented");
7992
}
93+
8094
public function get_new_id() {
8195
throw new Exception("Not implemented");
8296
}

0 commit comments

Comments
 (0)