Code

Added experimental sorting for rendered cells. Preparing for cached entries.
[gosa.git] / gosa-core / include / class_listing.inc
index c50453a8ee75fee3228fa7cb581af8febb00310b..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'])){
@@ -267,11 +270,18 @@ class listing {
         }
 
         // Render defined department columns, fill the rest with some stuff
+        $rest= $this->numColumns - 1;
         foreach ($this->xmlData['table']['department'] as $index => $config) {
-          $result.="<td ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
+          $colspan= 1;
+          if (isset($config['span'])){
+            $colspan= $config['span'];
+          }
+          $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
+          $rest-= $colspan;
         }
-        $last= count($this->xmlData['table']['department']) + 1;
-        $rest= $this->numColumns - $last;
+
+        // Fill remaining cols with nothing
+        $last= $this->numColumns - $rest;
         for ($i= 0; $i<$rest; $i++){
           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
         }
@@ -283,26 +293,38 @@ 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) + count($deps) == 0)?"border:0;":"";
-    if (count($this->entries) + count($deps) < 22) {
+    $emptyListStyle= (count($this->entries) + $deps == 0)?"border:0;":"";
+    if ((count($this->entries) + $deps) < 22) {
       $result.= "<tr>";
       for ($i= 0; $i<$this->numColumns; $i++) {
         if ($i == 0) {
@@ -366,6 +388,9 @@ class listing {
     global $config;
     $ui= get_userinfo();
 
+    // Reset object counter
+    $this->objectTypeCount= array();
+
     // Do not do anything if this is not our PID
     if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
       return;
@@ -501,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;
   }
 
@@ -887,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);
@@ -912,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"){
@@ -973,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
@@ -1263,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= "";
         }
       }