From fbd8c4c6f48dcdca9c0d76fca46de09cb2525c0f Mon Sep 17 00:00:00 2001 From: Jean-Marc Coic Date: Sun, 6 Feb 2005 10:49:08 +0000 Subject: [PATCH] Now handle sub-categories git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-448 --- include/exalead/exalead.class.php | 5 ++++ include/exalead/exalead.parser.inc.php | 51 ++++++++++++++++++++++++---------- include/exalead/exalead.smarty.inc.php | 44 +++++++++++++++++------------ 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/include/exalead/exalead.class.php b/include/exalead/exalead.class.php index 18290de..e1f6a43 100644 --- a/include/exalead/exalead.class.php +++ b/include/exalead/exalead.class.php @@ -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 = ""; diff --git a/include/exalead/exalead.parser.inc.php b/include/exalead/exalead.parser.inc.php index 66e90cf..4c30131 100644 --- a/include/exalead/exalead.parser.inc.php +++ b/include/exalead/exalead.parser.inc.php @@ -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(){ } diff --git a/include/exalead/exalead.smarty.inc.php b/include/exalead/exalead.smarty.inc.php index 85bc8ae..e750eae 100644 --- a/include/exalead/exalead.smarty.inc.php +++ b/include/exalead/exalead.smarty.inc.php @@ -142,7 +142,7 @@ function _display_3_columns($title, $count, $refine, $exclude, $categorie){ href=\"?_C=".$refine."&_f=xml2\" title=\"$title\" >$extract$count - &_f=xml2\" + [-] "; @@ -177,6 +177,30 @@ function _display_2_columns($title, $reset, $excluded, $categorie){ "; } +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 = ""; - 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 .= "
$groupe
"; return $result; } -- 2.1.4