1212if you plan to use it for Oracle - use Oracle connection type instead
1313**/
1414class 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 }
0 commit comments