Now handle sub-categories
authorJean-Marc Coic <jean-marc.coic@m4x.org>
Sun, 6 Feb 2005 10:49:08 +0000 (10:49 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:28:04 +0000 (23:28 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-448

include/exalead/exalead.class.php
include/exalead/exalead.parser.inc.php
include/exalead/exalead.smarty.inc.php

index 18290de..e1f6a43 100644 (file)
@@ -124,9 +124,14 @@ class ExaleadCategory{
   var $cref = "";
   var $gid = "";
   var $gcount = "";
+  var $categories = array();
 
   function ExaleadCategory(){}
 
+  function addCategory($category){
+    $this->categories[] = $category;
+  }
+
   function clear(){
    $this->name = "";
    $this->display = "";
index 66e90cf..4c30131 100644 (file)
@@ -15,7 +15,7 @@ class Exalead{
   var $data;
 
   var $currentGroup;
-  var $currentCategory;
+  var $currentCategories = array();
   var $currentSpelling;
   var $currentHit;
   var $currentHitField;
@@ -37,7 +37,7 @@ class Exalead{
   function Exalead($base_cgi = ''){
      $this->data = new ExaleadData();
      $this->currentGroup = new ExaleadGroup();
-     $this->currentCategory = new ExaleadCategory();
+     $this->currentCategories = array();
      $this->currentSpelling = new ExaleadSpelling();
      $this->currentHit = new ExaleadHit();
      $this->currentHitField = new ExaleadHitField();
@@ -112,7 +112,9 @@ class Exalead{
       }
       fclose($fp);
     }*/
+    //echo $xml_response;exit;
     $this->parse($xml_response);
+    //var_dump($this);
   }
 
   //pour recuperer tous les résultats d'une base indexée
@@ -252,17 +254,26 @@ class Exalead{
   }
 
   function startCategory(&$attrs){
-     $this->currentCategory->name = utf8_decode($attrs['NAME']);
-     $this->currentCategory->display = utf8_decode($attrs['DISPLAY']);
-     $this->currentCategory->count = $attrs['COUNT'];
-     $this->currentCategory->automatic = $attrs['AUTOMATIC'];
-     if(isset($attrs['REFINEHREF'])) $this->currentCategory->refine_href = convert_url($attrs['REFINEHREF']);
+     $currentCategory = new ExaleadCategory();
+     $currentCategory->name = utf8_decode($attrs['NAME']);
+     $currentCategory->display = utf8_decode($attrs['DISPLAY']);
+     $currentCategory->count = $attrs['COUNT'];
+     $currentCategory->automatic = $attrs['AUTOMATIC'];
+     $currentCategory->cref = $attrs['CREF'];
+     if(isset($attrs['REFINEHREF'])) $currentCategory->refine_href = convert_url($attrs['REFINEHREF']);
      //if(isset($attrs['REFINEHREF'])) $this->currentCategory->refine_href = $attrs['REFINEHREF'];
-     if(isset($attrs['EXCLUDEHREF'])) $this->currentCategory->exclude_href = $attrs['EXCLUDEHREF'];
-     if(isset($attrs['RESETHREF'])) $this->currentCategory->reset_href = $attrs['RESETHREF'];
-     $this->currentCategory->cref = $attrs['CREF'];
-     $this->currentCategory->gid = $attrs['GID'];
-     $this->currentCategory->gcount = $attrs['GCOUNT'];
+     if(isset($attrs['EXCLUDEHREF'])){
+       $currentCategory->exclude_href = $attrs['EXCLUDEHREF'];
+     }
+     else{
+       $currentCategory->exclude_href = '_c=-'.$currentCategory->cref;
+     }
+     if(isset($attrs['RESETHREF'])){
+       $currentCategory->reset_href = $attrs['RESETHREF'];
+     }
+     $currentCategory->gid = $attrs['GID'];
+     $currentCategory->gcount = $attrs['GCOUNT'];
+     $this->currentCategories[] = $currentCategory;
   }
 
   function startSearch(&$attrs){}
@@ -378,8 +389,20 @@ class Exalead{
      $this->currentGroup->clear();
   }
   function endCategory(){
-     $this->currentGroup->addCategory($this->currentCategory);
-     $this->currentCategory->clear();
+     //the parent element is a Group element ?
+     if(count($this->currentCategories) == 1){
+       $this->currentGroup->addCategory(array_pop($this->currentCategories));
+     }
+     else{
+       //var_dump($this->currentCategories);
+       $category = array_pop($this->currentCategories);
+       //reset($this->currentCategories);
+       end($this->currentCategories);
+       //var_dump($this->currentCategories);
+       $parentCategory = &$this->currentCategories[key($this->currentCategories)];
+       //var_dump($parentCategory);
+       $parentCategory->addCategory($category);
+     }
   }
   function endSearch(){
   }
index 85bc8ae..e750eae 100644 (file)
@@ -142,7 +142,7 @@ function _display_3_columns($title, $count, $refine, $exclude, $categorie){
                               href=\"?_C=".$refine."&amp;_f=xml2\"
                               title=\"$title\"
                            >$extract</a></td><td width=\"10%\">$count</td><td width=\"10%\">
-                           <a href=\"?_C=".$exclude."?>&amp;_f=xml2\"
+                           <a href=\"?_C=".$exclude."&amp;_f=xml2\"
                                title=\"$title_exclude\">[-]</a></td>
                        </tr>";
 
@@ -177,6 +177,30 @@ function _display_2_columns($title, $reset, $excluded, $categorie){
             </tr>";
 }
 
+function _display_resume_groupe_category(&$group, $context, $padding = ''){
+     $result = '';
+      foreach($group->categories as $categorie){
+        $title = (empty($categorie->display)?$categorie->name:$categorie->display);
+        $count = (empty($categorie->count)?'':' ('.$categorie->count.')');
+        $refine = $context.'/'.$categorie->refine_href;
+       $exclude = $context.'/'.$categorie->exclude_href;
+       $reset = $context.'/'.$categorie->reset_href;
+       
+        if($categorie->display != ''){
+         if($categorie->is_normal()){
+            $result .= _display_3_columns($padding.$title, $count, $refine, $exclude, true);
+         }
+         else{
+            $result .= _display_2_columns($padding.$title, $reset, $categorie->is_excluded(), true);
+         }
+       }
+       if(count($categorie->categories) > 0){
+          $result .= _display_resume_groupe_category($categorie, $context, $padding.'-');
+       }
+      }
+      return $result;
+}
+
 /**
 * This function is used to resume database content for given group (template argument 'groupe')
 */
@@ -194,24 +218,8 @@ function _display_resume_groupe($params, &$smarty){
   $groupe = $params['groupe'];
   foreach($exalead_data->groups as $group){
     if($group->title == $groupe){
-      $array = & $group->categories;
       $result = "<table class=\"exa_resume\"><th colspan=\"3\" class=\"titre\">$groupe</th>";
-      foreach($array as $categorie){
-        $title = (empty($categorie->display)?$categorie->name:$categorie->display);
-        $count = (empty($categorie->count)?'':' ('.$categorie->count.')');
-        $refine = $exalead_data->query->context.'/'.$categorie->refine_href;
-       $exclude = $exalead_data->query->context.'/'.$categorie->exclude_href;
-       $reset = $exalead_data->query->context.'/'.$categorie->reset_href;
-       
-        if($categorie->display != ''){
-         if($categorie->is_normal()){
-            $result .= _display_3_columns($title, $count, $refine, $exclude, true);
-         }
-         else{
-            $result .= _display_2_columns($title, $reset, $categorie->is_excluded(), true);
-         }
-       }
-      }
+      $result .= _display_resume_groupe_category($group, $exalead_data->query->context);
       $result .= "</table>";
       return $result;
     }