Code

Added experimental sorting for rendered cells. Preparing for cached entries.
[gosa.git] / gosa-core / include / class_listing.inc
index cf2366ecec565f3d069b601d2367d514ac9b7e29..e2bdb9a44a2d7e608db8d888dbf9cc66f59bea41 100644 (file)
@@ -140,6 +140,9 @@ class listing {
     }
     $this->categories= array();
     if (isset($this->xmlData['definition']['objectType'])) {
+      if(isset($this->xmlData['definition']['objectType']['label'])) {
+        $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
+      }
       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
         $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index];
         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
@@ -290,23 +293,35 @@ class listing {
     }
 
     // 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.="<tr class='rowxp".($alt&1)."'>";
+    foreach ($this->entry as $row => $entry) {
+      $trow ="<tr class='rowxp".($alt&1)."'>";
 
       // Render multi select if needed
       if ($this->multiSelect) {
-        $result.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>";
+        $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>";
       }
 
       foreach ($this->xmlData['table']['column'] as $index => $config) {
-        $result.="<td ".$this->colprops[$index]." class='list0'>".$this->renderCell($config['value'], $entry, $row)."</td>";
+        $renderedCell= $this->renderCell($config['value'], $entry, $row);
+        $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>";
+
+        // Save rendered column
+        $this->entry[$row]["_sort$index"]= $renderedCell;
       }
-      $result.="</tr>";
+      $trow.="</tr>";
+
+      // Save rendered entry
+      $this->entry[$row]['_rendered']= $trow;
 
       $alt++;
     }
 
+    // Complete list by sorting entries for _sort$index and appending them to the output
+    $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
+    foreach ($entryIterator as $row => $entry){
+      $result.= $entry['_rendered'];
+    }
+
     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
     $emptyListStyle= (count($this->entries) + $deps == 0)?"border:0;":"";
     if ((count($this->entries) + $deps) < 22) {
@@ -511,6 +526,10 @@ class listing {
     // Watch out for filters and prepare to execute them
     $data= $this->processElementFilter($data, $config, $row);
 
+    // Replace all non replaced %{...} instances because they
+    // are non resolved attributes or filters
+    $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
+
     return $data;
   }
 
@@ -897,7 +916,7 @@ class listing {
     $actions= &$this->xmlData['actionmenu']['action'];
     $result= "<input type='hidden' name='act' id='actionmenu' value=''>".
              "<ul class='level1' id='root'><li><a href='#'>Aktionen&nbsp;<img ".
-             "border=0 src='images/lists/sort-down.png'></a>";
+             "border=0 class='center' src='images/lists/sort-down.png'></a>";
 
     // Build ul/li list
     $result.= $this->recurseActions($actions);
@@ -922,7 +941,7 @@ class listing {
       // Fill image if set
       $img= "";
       if (isset($action['image'])){
-        $img= "<img border=0 src='".$action['image']."'>&nbsp;";
+        $img= "<img border='0' class='center' src='".$action['image']."'>&nbsp;";
       }
 
       if ($action['type'] == "separator"){
@@ -983,7 +1002,7 @@ class listing {
       // Every ACL has to pass
       foreach ($acls as $acl) {
         $module= $this->module;
-        $acllist= array();
+        $aclList= array();
 
         // Split for category and plugins if needed
         // match for "[rw]" style entries
@@ -1273,9 +1292,9 @@ class listing {
     // If there is a daemon registered, draw the menu entries
     if(class_available("DaemonEvent")){
       $events= DaemonEvent::get_event_types_by_category($this->categories);
-      if(count($events['BY_CLASS'])){
+      if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
         foreach($events['BY_CLASS'] as $name => $event){
-          $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$name\";mainform.submit();'><img src='".$event['MenuImage']."' alt='' border='0' class='center'>&nbsp;".$event['s_Menu_Name']."</a></li>";
+          $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";mainform.submit();'>".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."</a></li>";
           $separator= "";
         }
       }