From: cajus Date: Mon, 17 Aug 2009 12:41:41 +0000 (+0000) Subject: Added sorting to the list by adding an iterator X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a62bc7d3e69b59cb9abfae1bf5368721bcabf889;p=gosa.git Added sorting to the list by adding an iterator git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14075 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_filter.inc b/gosa-core/include/class_filter.inc index 108eb8ee0..1247ad781 100644 --- a/gosa-core/include/class_filter.inc +++ b/gosa-core/include/class_filter.inc @@ -409,12 +409,13 @@ class filter { $this->elementValues[$tag]= ""; } } - } - // Save scope if needed - if ($this->scopeMode == "auto") { - $this->scope= isset($_POST['SCOPE'])?"sub":"one"; + // Save scope if needed + if ($this->scopeMode == "auto") { + $this->scope= isset($_POST['SCOPE'])?"sub":"one"; + } } + } diff --git a/gosa-core/include/class_listing.inc b/gosa-core/include/class_listing.inc index f025a200c..2609b88b1 100644 --- a/gosa-core/include/class_listing.inc +++ b/gosa-core/include/class_listing.inc @@ -1,4 +1,24 @@ colprops= $this->parseLayout($this->xmlData['table']['layout']); // Prepare table headers + $this->renderHeader(); + + // Assign headline/module + $this->headline= _($this->xmlData['definition']['label']); + $this->module= $this->xmlData['definition']['module']; + + return true; + } + + + function renderHeader() + { $this->header= array(); + + // Initialize sort? + $sortInit= false; + if (!$this->sortDirection) { + $this->sortColumn= 0; + if (isset($this->xmlData['definition']['defaultSortColumn'])){ + $this->sortColumn= $this->xmlData['definition']['defaultSortColumn']; + } else { + $this->sortAttribute= ""; + } + $this->sortDirection= array(); + $sortInit= true; + } + if (isset($this->xmlData['table']['column'])){ foreach ($this->xmlData['table']['column'] as $index => $config) { + // Initialize everything to one direction + if ($sortInit) { + $this->sortDirection[$index]= false; + } + + $sorter= ""; + if ($index == $this->sortColumn && isset($config['sortAttribute']) && + isset($config['sortType'])) { + $this->sortAttribute= $config['sortAttribute']; + $this->sortType= $config['sortType']; + $sorter= " "; + } + $sortable= (isset($config['sortAttribute'])); + + $link= "href='?plug=".$_GET['plug']."&PID=$this->pid&act=SORT_$index'"; if (isset($config['label'])) { - $this->header[$index]= "colprops[$index].">"._($config['label']).""; + if ($sortable) { + $this->header[$index]= "colprops[$index].">"._($config['label'])."$sorter"; + } else { + $this->header[$index]= "colprops[$index].">"._($config['label']).""; + } } else { - $this->header[$index]= "colprops[$index]."> "; + if ($sortable) { + $this->header[$index]= "colprops[$index]."> $sorter"; + } else { + $this->header[$index]= "colprops[$index]."> "; + } } } } - - // Assign headline/module - $this->headline= _($this->xmlData['definition']['label']); - $this->module= $this->xmlData['definition']['module']; - - return true; } - function render() { -echo "sorting, department browsing, copypaste handler, snapshot handler, daemon handler
"; +echo "department browsing, copypaste handler, snapshot handler, daemon handler
"; // Initialize list $result= ""; @@ -144,8 +210,9 @@ echo "sorting, department browsing, copypaste handler, snapshot handler, daemon // Fill with department browser if configured this way ############### - // Fill with contents - foreach ($this->entries as $row => $entry){ + // Fill with contents, sort as configured + $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], $this->sortAttribute, $this->sortType); + foreach ($entryIterator as $row => $entry){ $result.=""; // Render multi select if needed @@ -253,6 +320,23 @@ echo "sorting, department browsing, copypaste handler, snapshot handler, daemon } } + // Filter GET with "act" attributes + if (isset($_GET['act'])) { + $key= validate($_GET['act']); + if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) { + // Switch to new column or invert search order? + $column= $match[1]; + if ($this->sortColumn != $column) { + $this->sortColumn= $column; + } else { + $this->sortDirection[$column]= !$this->sortDirection[$column]; + } + + // Allow header to update itself according to the new sort settings + $this->renderHeader(); + } + } + // Override base if we got signals from the navigation elements $action= ""; foreach ($_POST as $key => $value) { @@ -279,6 +363,10 @@ echo "sorting, department browsing, copypaste handler, snapshot handler, daemon $this->base= get_base_from_people($ui->dn); } + // Check sorting + if (isset($_GET['SORT'])) { + } + // Update filter and refresh entries $this->filter->setBase($this->base); $this->entries= $this->filter->query(); diff --git a/gosa-core/include/class_listingSortIterator.inc b/gosa-core/include/class_listingSortIterator.inc index ddaf5c243..e656d98a9 100644 --- a/gosa-core/include/class_listingSortIterator.inc +++ b/gosa-core/include/class_listingSortIterator.inc @@ -23,7 +23,7 @@ class listingSortIterator implements Iterator { private $data; - public function __construct($data, $attribute, $type= "string") { + public function __construct($data, $direction, $attribute, $type= "string") { global $_sortAttribute; global $_sortType; $_sortAttribute= $attribute; @@ -54,14 +54,23 @@ class listingSortIterator implements Iterator { case 'string': return strnatcmp($a, $b); + // Sort for string by default default: - die(sprintf(_("Cannot sort entries: method '%s' is unknown!"), $_sortType)); + return strnatcmp($a, $b); } } // Sort for attribute - usort($data, "attrSort"); - $this->data= $data; + if ($attribute != "") { + usort($data, "attrSort"); + } + + // Invert if direction is set + if ($direction) { + $this->data= array_reverse($data); + } else { + $this->data= $data; + } } function rewind() {