1 | <?php
|
---|
2 | require_once("grid_connector.php");
|
---|
3 |
|
---|
4 | /*! DataItem class for TreeGrid component
|
---|
5 | **/
|
---|
6 | class TreeGridDataItem extends GridDataItem{
|
---|
7 | private $kids=-1;//!< checked state
|
---|
8 |
|
---|
9 | function __construct($data,$config,$index){
|
---|
10 | parent::__construct($data,$config,$index);
|
---|
11 | $this->im0=false;
|
---|
12 | }
|
---|
13 | /*! return id of parent record
|
---|
14 |
|
---|
15 | @return
|
---|
16 | id of parent record
|
---|
17 | */
|
---|
18 | function get_parent_id(){
|
---|
19 | return $this->data[$this->config->relation_id["name"]];
|
---|
20 | }
|
---|
21 | /*! assign image to treegrid's item
|
---|
22 | longer description
|
---|
23 | @param img
|
---|
24 | relative path to the image
|
---|
25 | */
|
---|
26 | function set_image($img){
|
---|
27 | $this->set_cell_attribute($this->config->text[0]["name"],"image",$img);
|
---|
28 | }
|
---|
29 |
|
---|
30 | /*! return count of child items
|
---|
31 | -1 if there is no info about childs
|
---|
32 | @return
|
---|
33 | count of child items
|
---|
34 | */
|
---|
35 | function has_kids(){
|
---|
36 | return $this->kids;
|
---|
37 | }
|
---|
38 | /*! sets count of child items
|
---|
39 | @param value
|
---|
40 | count of child items
|
---|
41 | */
|
---|
42 | function set_kids($value){
|
---|
43 | $this->kids=$value;
|
---|
44 | if ($value)
|
---|
45 | $this->set_row_attribute("xmlkids",$value);
|
---|
46 | }
|
---|
47 | }
|
---|
48 | /*! Connector for dhtmlxTreeGrid
|
---|
49 | **/
|
---|
50 | class TreeGridConnector extends GridConnector{
|
---|
51 | private $id_swap = array();
|
---|
52 |
|
---|
53 | /*! constructor
|
---|
54 |
|
---|
55 | Here initilization of all Masters occurs, execution timer initialized
|
---|
56 | @param res
|
---|
57 | db connection resource
|
---|
58 | @param type
|
---|
59 | string , which hold type of database ( MySQL or Postgre ), optional, instead of short DB name, full name of DataWrapper-based class can be provided
|
---|
60 | @param item_type
|
---|
61 | name of class, which will be used for item rendering, optional, DataItem will be used by default
|
---|
62 | @param data_type
|
---|
63 | name of class which will be used for dataprocessor calls handling, optional, DataProcessor class will be used by default.
|
---|
64 | */
|
---|
65 | public function __construct($res,$type=false,$item_type=false,$data_type=false){
|
---|
66 | if (!$item_type) $item_type="TreeGridDataItem";
|
---|
67 | if (!$data_type) $data_type="TreeGridDataProcessor";
|
---|
68 | parent::__construct($res,$type,$item_type,$data_type);
|
---|
69 |
|
---|
70 | $this->event->attach("afterInsert",array($this,"parent_id_correction_a"));
|
---|
71 | $this->event->attach("beforeProcessing",array($this,"parent_id_correction_b"));
|
---|
72 | }
|
---|
73 |
|
---|
74 | /*! store info about ID changes during insert operation
|
---|
75 | @param dataAction
|
---|
76 | data action object during insert operation
|
---|
77 | */
|
---|
78 | public function parent_id_correction_a($dataAction){
|
---|
79 | $this->id_swap[$dataAction->get_id()]=$dataAction->get_new_id();
|
---|
80 | }
|
---|
81 | /*! update ID if it was affected by previous operation
|
---|
82 | @param dataAction
|
---|
83 | data action object, before any processing operation
|
---|
84 | */
|
---|
85 | public function parent_id_correction_b($dataAction){
|
---|
86 | $relation = $this->config->relation_id["db_name"];
|
---|
87 | $value = $dataAction->get_value($relation);
|
---|
88 |
|
---|
89 | if (array_key_exists($value,$this->id_swap))
|
---|
90 | $dataAction->set_value($relation,$this->id_swap[$value]);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /*! process treegrid specific options in incoming request
|
---|
94 | */
|
---|
95 | public function parse_request(){
|
---|
96 | parent::parse_request();
|
---|
97 |
|
---|
98 | if (isset($_GET["id"]))
|
---|
99 | $this->request->set_relation($_GET["id"]);
|
---|
100 | else
|
---|
101 | $this->request->set_relation("0");
|
---|
102 |
|
---|
103 | $this->request->set_limit(0,0); //netralize default reaction on dyn. loading mode
|
---|
104 | }
|
---|
105 |
|
---|
106 | /*! process treegrid specific options in incoming request
|
---|
107 | */
|
---|
108 | protected function render_set($res){
|
---|
109 | $output="";
|
---|
110 | $index=0;
|
---|
111 | while ($data=$this->sql->get_next($res)){
|
---|
112 | $data = new $this->names["item_class"]($data,$this->config,$index);
|
---|
113 | $this->event->trigger("beforeRender",$data);
|
---|
114 | //there is no info about child elements,
|
---|
115 | //if we are using dyn. loading - assume that it has,
|
---|
116 | //in normal mode juse exec sub-render routine
|
---|
117 | if ($data->has_kids()===-1 && $this->dload)
|
---|
118 | $data->set_kids(true);
|
---|
119 | $output.=$data->to_xml_start();
|
---|
120 | if ($data->has_kids()===-1 || ( $data->has_kids()==true && !$this->dload)){
|
---|
121 | $sub_request = new DataRequestConfig($this->request);
|
---|
122 | $sub_request->set_relation($data->get_id());
|
---|
123 | $output.=$this->render_set($this->sql->select($sub_request));
|
---|
124 | }
|
---|
125 | $output.=$data->to_xml_end();
|
---|
126 | $index++;
|
---|
127 | }
|
---|
128 | return $output;
|
---|
129 | }
|
---|
130 |
|
---|
131 | /*! renders self as xml, starting part
|
---|
132 | */
|
---|
133 | protected function xml_start(){
|
---|
134 | return "<rows parent='".$this->request->get_relation()."'>";
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | /*! DataProcessor class for Grid component
|
---|
139 | **/
|
---|
140 | class TreeGridDataProcessor extends GridDataProcessor{
|
---|
141 |
|
---|
142 | function __construct($connector,$config,$request){
|
---|
143 | parent::__construct($connector,$config,$request);
|
---|
144 | $request->set_relation(false);
|
---|
145 | }
|
---|
146 |
|
---|
147 | /*! convert incoming data name to valid db name
|
---|
148 | converts c0..cN to valid field names
|
---|
149 | @param data
|
---|
150 | data name from incoming request
|
---|
151 | @return
|
---|
152 | related db_name
|
---|
153 | */
|
---|
154 | function name_data($data){
|
---|
155 |
|
---|
156 | if ($data=="gr_pid")
|
---|
157 | return $this->config->relation_id["name"];
|
---|
158 | else return parent::name_data($data);
|
---|
159 | }
|
---|
160 | }
|
---|
161 | ?> |
---|