blob: 54f371fb1fd9d349e3199a114f905c24cdc0af60 (
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
73
74
75
|
<?php
namespace Dhtmlx\Connector\DataStorage;
use Dhtmlx\Connector\DataProcessor\DataProcessor;
use \Exception;
class PHPLaravelDBDataWrapper extends ArrayDBDataWrapper {
public function select($source) {
$className = $source->get_source();
return new ArrayQueryWrapper($className::all()->toArray());
}
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) {
$className = $source->get_source();
$obj = $className::create();
$this->fill_model_data($obj, $data)->save();
$fieldPrimaryKey = $this->config->id["db_name"];
$data->success($obj->$fieldPrimaryKey);
}
public function delete($data, $source) {
$className = $source->get_source();
$className::destroy($data->get_id());
$data->success();
}
public function update($data, $source) {
$className = $source->get_source();
$obj = $className::find($data->get_id());
$this->fill_model_data($obj, $data)->save();
$data->success();
}
private function fill_model_data($obj, $data) {
$dataArray = $data->get_data();
unset($dataArray[DataProcessor::$action_param]);
unset($dataArray[$this->config->id["db_name"]]);
foreach($dataArray as $key => $value)
$obj->$key = $value;
return $obj;
}
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");
}
}
|