summaryrefslogtreecommitdiffstats
path: root/codebase/connector/keygrid_connector.php
blob: 3942ac23078da4c2d6cd13d938851567844ae5c6 (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
<?php
/*
	@author dhtmlx.com
	@license GPL, see license.txt
*/
require_once("grid_connector.php");
class KeyGridConnector extends GridConnector{
	public function __construct($res,$type=false,$item_type=false,$data_type=false){
		if (!$item_type) $item_type="GridDataItem";
		if (!$data_type) $data_type="KeyGridDataProcessor";
		parent::__construct($res,$type,$item_type,$data_type);
		
		$this->event->attach("beforeProcessing",array($this,"before_check_key"));	
		$this->event->attach("afterProcessing",array($this,"after_check_key"));	
	}

	public function before_check_key($action){
		if ($action->get_value($this->config->id["name"])=="")
			$action->error();
	}
	public function after_check_key($action){
		if ($action->get_status()=="inserted" || $action->get_status()=="updated"){
			$action->success($action->get_value($this->config->id["name"]));
			$action->set_status("inserted");
		}
	}
};

class KeyGridDataProcessor extends DataProcessor{
	
	/*! convert incoming data name to valid db name
		converts c0..cN to valid field names
		@param data 
			data name from incoming request
		@return 
			related db_name
	*/
	function name_data($data){
		if ($data == "gr_id") return "__dummy__id__"; //ignore ID
		$parts=explode("c",$data);
		if ($parts[0]=="" && intval($parts[1])==$parts[1])
			return $this->config->text[intval($parts[1])]["name"];
		return $data;
	}
}

	
?>