1+ <?php
2+ namespace Dhtmlx \Connector \DataStorage ;
3+ use Dhtmlx \Connector \DataProcessor \DataProcessor ;
4+ use \Exception ;
5+
6+ class PHPLaravelDBDataWrapper extends ArrayDBDataWrapper {
7+
8+ public function select ($ source ) {
9+ $ className = $ source ->get_source ();
10+ return new ArrayQueryWrapper ($ className ::all ()->toArray ());
11+ }
12+
13+ protected function getErrorMessage () {
14+ $ errors = $ this ->connection ->getErrors ();
15+ $ text = array ();
16+ foreach ($ errors as $ key => $ value )
17+ $ text [] = $ key ." - " .$ value [0 ];
18+
19+ return implode ("\n" , $ text );
20+ }
21+
22+ public function insert ($ data , $ source ) {
23+ $ className = $ source ->get_source ();
24+ $ obj = $ className ::create ();
25+ $ this ->fill_model_data ($ obj , $ data )->save ();
26+
27+ $ fieldPrimaryKey = $ this ->config ->id ["db_name " ];
28+ $ data ->success ($ obj ->$ fieldPrimaryKey );
29+ }
30+
31+ public function delete ($ data , $ source ) {
32+ $ className = $ source ->get_source ();
33+ $ className ::destroy ($ data ->get_id ());
34+ $ data ->success ();
35+ }
36+
37+ public function update ($ data , $ source ) {
38+ $ className = $ source ->get_source ();
39+ $ obj = $ className ::find ($ data ->get_id ());
40+ $ this ->fill_model_data ($ obj , $ data )->save ();
41+ $ data ->success ();
42+ }
43+
44+ private function fill_model_data ($ obj , $ data ) {
45+ $ dataArray = $ data ->get_data ();
46+ unset($ dataArray [DataProcessor::$ action_param ]);
47+ unset($ dataArray [$ this ->config ->id ["db_name " ]]);
48+
49+ foreach ($ dataArray as $ key => $ value )
50+ $ obj ->$ key = $ value ;
51+
52+ return $ obj ;
53+ }
54+
55+ protected function errors_to_string ($ errors ) {
56+ $ text = array ();
57+ foreach ($ errors as $ value )
58+ $ text [] = implode ("\n" , $ value );
59+
60+ return implode ("\n" ,$ text );
61+ }
62+
63+ public function escape ($ str ) {
64+ throw new Exception ("Not implemented " );
65+ }
66+
67+ public function query ($ str ) {
68+ throw new Exception ("Not implemented " );
69+ }
70+
71+ public function get_new_id () {
72+ throw new Exception ("Not implemented " );
73+ }
74+
75+ }
0 commit comments