summaryrefslogtreecommitdiffstats
path: root/codebase/grid_config.php
diff options
context:
space:
mode:
authorDmitry <dmitry@dhtmlx.com>2011-12-19 16:51:01 +0200
committerDmitry <dmitry@dhtmlx.com>2011-12-19 16:51:01 +0200
commit8ea0fdb184ee3baaa44eea2768b202155e1f312f (patch)
treefba56e23ea890bc9d28b4c6f5183b4e803ca003d /codebase/grid_config.php
parent0e246885222003478703ca127eaf04f71899c148 (diff)
downloadconnector-php-8ea0fdb184ee3baaa44eea2768b202155e1f312f.zip
connector-php-8ea0fdb184ee3baaa44eea2768b202155e1f312f.tar.gz
connector-php-8ea0fdb184ee3baaa44eea2768b202155e1f312f.tar.bz2
-add set_convert_mode for GridConfiguration
Diffstat (limited to 'codebase/grid_config.php')
-rw-r--r--codebase/grid_config.php169
1 files changed, 148 insertions, 21 deletions
diff --git a/codebase/grid_config.php b/codebase/grid_config.php
index 5bb99c5..e25fa9f 100644
--- a/codebase/grid_config.php
+++ b/codebase/grid_config.php
@@ -24,6 +24,8 @@ class GridConfiguration{
protected $headerHidden = false;
protected $headerFormat = false;
+ protected $convert_mode = false;
+
function __construct($headers = false){
if ($headers === false || $headers === true )
$this->headerNames = $headers;
@@ -246,13 +248,101 @@ class GridConfiguration{
$_GET["dhx_colls"] = implode(",",$temp);
}
+
+ /*! gets header as array
+ */
+ private function getHeaderArray() {
+ $head = Array();
+ $head[0] = $this->headerNames;
+ $head = $this->getAttaches($head, $this->headerAttaches);
+ return $head;
+ }
+
+
+ /*! get footer as array
+ */
+ private function getFooterArray() {
+ $foot = Array();
+ $foot = $this->getAttaches($foot, $this->footerAttaches);
+ return $foot;
+ }
+
+
+ /*! gets array of data with attaches
+ */
+ private function getAttaches($to, $from) {
+ for ($i = 0; $i < count($from); $i++) {
+ $line = $from[$i]['values'];
+ $to[] = $line;
+ }
+ return $to;
+ }
+
+
+ /*! calculates rowspan array according #cspan markers
+ */
+ private function processCspan($data) {
+ $rspan = Array();
+ for ($i = 0; $i < count($data); $i++) {
+ $last = 0;
+ $rspan[$i] = Array();
+ for ($j = 0; $j < count($data[$i]); $j++) {
+ $rspan[$i][$j] = 0;
+ if ($data[$i][$j] === '#cspan') {
+ $rspan[$i][$last]++;
+ } else {
+ $last = $j;
+ }
+ }
+ }
+ return $rspan;
+ }
+
+
+ /*! calculates colspan array according #rspan markers
+ */
+ private function processRspan($data) {
+ $last = Array();
+ $cspan = Array();
+ for ($i = 0; $i < count($data); $i++) {
+ $cspan[$i] = Array();
+ for ($j = 0; $j < count($data[$i]); $j++) {
+ $cspan[$i][$j] = 0;
+ if (!isset($last[$j])) $last[$j] = 0;
+ if ($data[$i][$j] === '#rspan') {
+ $cspan[$last[$j]][$j]++;
+ } else {
+ $last[$j] = $i;
+ }
+ }
+ }
+ return $cspan;
+ }
+
+
+ /*! sets mode of output format: usual mode or convert mode.
+ * @param mode
+ * true - convert mode, false - otherwise
+ */
+ public function set_convert_mode($mode) {
+ $this->convert_mode = $mode;
+ }
+
+
/*! adds header configuration in output XML
*/
public function attachHeaderToXML($conn, $out) {
if (!$conn->is_first_call()) return; //render head only for first call
-
+ $head = $this->getHeaderArray();
+ $foot = $this->getFooterArray();
+ $rspan = $this->processRspan($head);
+ $cspan = $this->processCspan($head);
+
$str = '<head>';
+
+ if ($this->convert_mode) $str .= "<columns>";
+
for ($i = 0; $i < count($this->headerNames); $i++) {
$str .= '<column';
$str .= ' type="'. $this->headerTypes[$i].'"';
@@ -264,33 +354,70 @@ class GridConfiguration{
$str .= $this->headerColors[$i] ? ' color="'.$this->headerColors[$i].'"' : '';
$str .= $this->headerHidden[$i] ? ' hidden="'.$this->headerHidden[$i].'"' : '';
$str .= $this->headerFormat[$i] ? ' format="'.$this->headerFormat[$i].'"' : '';
+ echo $rspan[0][$i]."<br>";
+ $str .= $cspan[0][$i] ? ' colspan="'.($cspan[0][$i] + 1).'"' : '';
+ $str .= $rspan[0][$i] ? ' rowspan="'.($rspan[0][$i] + 1).'"' : '';
$str .= '>'.$this->headerNames[$i].'</column>';
}
- $str .= '<settings><colwidth>'.$this->headerWidthsUnits.'</colwidth></settings>';
- if ((count($this->headerAttaches) > 0)||(count($this->footerAttaches) > 0)) {
- $str .= '<afterInit>';
- }
- for ($i = 0; $i < count($this->headerAttaches); $i++) {
- $str .= '<call command="attachHeader">';
- $str .= '<param>'.implode(",",$this->headerAttaches[$i]['values']).'</param>';
- if ($this->headerAttaches[$i]['styles'] != null) {
- $str .= '<param>'.implode(",",$this->headerAttaches[$i]['styles']).'</param>';
+
+ if (!$this->convert_mode) {
+ $str .= '<settings><colwidth>'.$this->headerWidthsUnits.'</colwidth></settings>';
+ if ((count($this->headerAttaches) > 0)||(count($this->footerAttaches) > 0)) {
+ $str .= '<afterInit>';
}
- $str .= '</call>';
- }
- for ($i = 0; $i < count($this->footerAttaches); $i++) {
- $str .= '<call command="attachFooter">';
- $str .= '<param>'.implode(",",$this->footerAttaches[$i]['values']).'</param>';
- if ($this->footerAttaches[$i]['styles'] != null) {
- $str .= '<param>'.implode(",",$this->footerAttaches[$i]['styles']).'</param>';
+ for ($i = 0; $i < count($this->headerAttaches); $i++) {
+ $str .= '<call command="attachHeader">';
+ $str .= '<param>'.implode(",",$this->headerAttaches[$i]['values']).'</param>';
+ if ($this->headerAttaches[$i]['styles'] != null) {
+ $str .= '<param>'.implode(",",$this->headerAttaches[$i]['styles']).'</param>';
+ }
+ $str .= '</call>';
+ }
+ for ($i = 0; $i < count($this->footerAttaches); $i++) {
+ $str .= '<call command="attachFooter">';
+ $str .= '<param>'.implode(",",$this->footerAttaches[$i]['values']).'</param>';
+ if ($this->footerAttaches[$i]['styles'] != null) {
+ $str .= '<param>'.implode(",",$this->footerAttaches[$i]['styles']).'</param>';
+ }
+ $str .= '</call>';
+ }
+ if ((count($this->headerAttaches) > 0)||(count($this->footerAttaches) > 0)) {
+ $str .= '</afterInit>';
+ }
+ } else {
+ $str .= "</columns>";
+ for ($i = 1; $i < count($head); $i++) {
+ $str .= "<columns>";
+ for ($j = 0; $j < count($head[$i]); $j++) {
+ $str .= '<column';
+ echo $rspan[$i][$j]."<br>";
+ $str .= $cspan[$i][$j] ? ' colspan="'.($cspan[$i][$j] + 1).'"' : '';
+ $str .= $rspan[$i][$j] ? ' rowspan="'.($rspan[$i][$j] + 1).'"' : '';
+ $str .= '>'.$head[$i][$j].'</column>';
+ }
+ $str .= "</columns>\n";
}
- $str .= '</call>';
- }
- if ((count($this->headerAttaches) > 0)||(count($this->footerAttaches) > 0)) {
- $str .= '</afterInit>';
}
$str .= '</head>';
+
+ if ($this->convert_mode && count($foot) > 0) {
+ $rspan = $this->processRspan($foot);
+ $cspan = $this->processCspan($foot);
+ $str .= "<foot>";
+ for ($i = 0; $i < count($foot); $i++) {
+ $str .= "<columns>";
+ for ($j = 0; $j < count($foot[$i]); $j++) {
+ $str .= '<column';
+ $str .= $cspan[$i][$j] ? ' colspan="'.($cspan[$i][$j] + 1).'"' : '';
+ $str .= $rspan[$i][$j] ? ' rowspan="'.($rspan[$i][$j] + 1).'"' : '';
+ $str .= '>'.$foot[$i][$j].'</column>';
+ }
+ $str .= "</columns>\n";
+ }
+ $str .= "</foot>";
+ }
+
$out->add($str);
}
}