summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry <dmitry@dhtmlx.com>2012-05-22 16:50:46 +0200
committerDmitry <dmitry@dhtmlx.com>2012-05-22 16:50:46 +0200
commitdff9912b9ee40fbac29c54b4cf67591e11b5e4cb (patch)
tree0129bc7f77c5098874ebffb6c6f52f381eda28b3
parent2f3109a94c96af3cbaa8973407d27d072d489248 (diff)
downloadconnector-php-dff9912b9ee40fbac29c54b4cf67591e11b5e4cb.zip
connector-php-dff9912b9ee40fbac29c54b4cf67591e11b5e4cb.tar.gz
connector-php-dff9912b9ee40fbac29c54b4cf67591e11b5e4cb.tar.bz2
implements correct extending for fill_collections
-rw-r--r--codebase/base_connector.php32
-rw-r--r--codebase/data_connector.php45
-rw-r--r--codebase/grid_connector.php2
-rw-r--r--codebase/scheduler_connector.php35
4 files changed, 58 insertions, 56 deletions
diff --git a/codebase/base_connector.php b/codebase/base_connector.php
index 48039a6..8890a68 100644
--- a/codebase/base_connector.php
+++ b/codebase/base_connector.php
@@ -278,6 +278,7 @@ class Connector {
private $id_seed=0; //!< default value, used to generate auto-IDs
protected $live_update = false; // actions table name for autoupdating
+ protected $options=array();//!< hash of OptionsConnector
/*! constructor
@@ -649,9 +650,38 @@ class Connector {
/*! renders self as xml, ending part
*/
protected function xml_end(){
- return "</data>";
+ $this->fill_collections();
+ return $this->extra_output."</data>";
+ }
+
+ protected function fill_collections(){
+ foreach ($this->options as $k=>$v) {
+ $name = $k;
+ $this->extra_output.="<coll_options for='{$name}'>";
+ if (!is_string($this->options[$name]))
+ $this->extra_output.=$this->options[$name]->render();
+ else
+ $this->extra_output.=$this->options[$name];
+ $this->extra_output.="</coll_options>";
+ }
}
+ /*! assign options collection to the column
+
+ @param name
+ name of the column
+ @param options
+ array or connector object
+ */
+ public function set_options($name,$options){
+ if (is_array($options)){
+ $str="";
+ foreach($options as $k => $v)
+ $str.="<item value='".$this->xmlentities($k)."' label='".$this->xmlentities($v)."' />";
+ $options=$str;
+ }
+ $this->options[$name]=$options;
+ }
public function insert($data) {
$action = new DataAction('inserted', false, $data);
diff --git a/codebase/data_connector.php b/codebase/data_connector.php
index 45660db..36cafa0 100644
--- a/codebase/data_connector.php
+++ b/codebase/data_connector.php
@@ -74,7 +74,7 @@ class CommonDataItem extends DataItem{
/*! Connector class for DataView
**/
class DataConnector extends Connector{
-
+
/*! constructor
Here initilization of all Masters occurs, execution timer initialized
@@ -122,9 +122,6 @@ class DataConnector extends Connector{
$this->editing = true;
}
} else {
- if (isset($_GET["dhx_colls"]))
- $this->fill_collections($_GET["dhx_colls"]);
-
if (isset($_GET['editing']) && isset($_POST['ids']))
$this->editing = true;
@@ -142,7 +139,8 @@ class DataConnector extends Connector{
foreach($this->sections as $k=>$v)
$start .= "<".$k.">".$v."</".$k.">\n";
return $start;
- }
+ }
+
};
class JSONDataConnector extends DataConnector{
@@ -171,21 +169,15 @@ class JSONDataConnector extends DataConnector{
$this->options[$name]=$options;
}
-
- protected function fill_collections($list){
- $names=explode(",",$list);
- $options=array();
- for ($i=0; $i < sizeof($names); $i++) {
- $name = $this->resolve_parameter($names[$i]);
- if (!array_key_exists($name,$this->options)){
- $this->options[$name] = new JSONDistinctOptionsConnector($this->get_connection(),$this->names["db_class"]);
- $c = new DataConfig($this->config);
- $r = new DataRequestConfig($this->request);
- $c->minimize($name);
-
- $this->options[$name]->render_connector($c,$r);
- }
-
+ /*! generates xml description for options collections
+
+ @param list
+ comma separated list of column names, for which options need to be generated
+ */
+ protected function fill_collections(){
+ $options = array();
+ foreach ($this->options as $k=>$v) {
+ $name = $k;
$option="\"{$name}\":[";
if (!is_string($this->options[$name]))
$option.=substr($this->options[$name]->render(),0,-2);
@@ -194,7 +186,7 @@ class JSONDataConnector extends DataConnector{
$option.="]";
$options[] = $option;
}
- $this->extra_output .= implode(",", $options);
+ $this->extra_output .= implode($this->data_separator, $options);
}
protected function resolve_parameter($name){
@@ -204,12 +196,17 @@ class JSONDataConnector extends DataConnector{
}
protected function output_as_xml($res){
- $start = "[\n";
- $end = substr($this->render_set($res),0,-2)."\n]";
+ $start = "";
+ $end = "{ \"data\":[\n".substr($this->render_set($res),0,-2)."\n]";
+
+ $collections = $this->fill_collections();
+ if (!empty($this->extra_output))
+ $end .= ', "collections": {'.$this->extra_output.'} }';
+
$is_sections = sizeof($this->sections) && $this->is_first_call();
if ($this->dload || $is_sections){
- $start = "{ \"data\":".$start.$end;
+ $start = $start.$end;
$end="";
if ($is_sections){
diff --git a/codebase/grid_connector.php b/codebase/grid_connector.php
index a54799e..a39e30c 100644
--- a/codebase/grid_connector.php
+++ b/codebase/grid_connector.php
@@ -132,7 +132,7 @@ class GridDataItem extends DataItem{
**/
class GridConnector extends Connector{
protected $extra_output="";//!< extra info which need to be sent to client side
- private $options=array();//!< hash of OptionsConnector
+ protected $options=array();//!< hash of OptionsConnector
/*! constructor
diff --git a/codebase/scheduler_connector.php b/codebase/scheduler_connector.php
index c70fc92..123d03b 100644
--- a/codebase/scheduler_connector.php
+++ b/codebase/scheduler_connector.php
@@ -51,31 +51,8 @@ class SchedulerConnector extends Connector{
}
$this->options[$name]=$options;
}
- /*! generates xml description for options collections
-
- @param list
- comma separated list of column names, for which options need to be generated
- */
- protected function fill_collections(){
- foreach ($this->options as $k=>$v) {
- $name = $k;
- $this->extra_output.="<coll_options for='{$name}'>";
- if (!is_string($this->options[$name]))
- $this->extra_output.=$this->options[$name]->render();
- else
- $this->extra_output.=$this->options[$name];
- $this->extra_output.="</coll_options>";
- }
- }
-
- /*! renders self as xml, ending part
- */
- protected function xml_end(){
- $this->fill_collections();
- return $this->extra_output."</data>";
- }
-
-
+
+
/*! constructor
Here initilization of all Masters occurs, execution timer initialized
@@ -176,13 +153,11 @@ class JSONSchedulerConnector extends SchedulerConnector {
protected function xml_end() {
$this->fill_collections();
- if (empty($this->extra_output))
- return ' }';
- else
- return ', "collections": {'.$this->extra_output.'} }';
+ $end = (!empty($this->extra_output)) ? ', "collections": {'.$this->extra_output.'}' : '';
+ $end .= '}';
+ return $end;
}
-
/*! assign options collection to the column
@param name