summaryrefslogtreecommitdiffstats
path: root/codebase/db_phpcake.php
blob: 99eb723525944380e09c951e77b784e32f4c9478 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?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 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");
    }
}

?>