Skip to content
Snippets Groups Projects
Commit 7267afef authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #23805 : facets view helper refacto

parent d6999d9f
Branches
Tags
2 merge requests!1009Dev#23805 unleash the facets,!1007Dev#23805 unleash the facets
......@@ -21,14 +21,15 @@
class ZendAfi_View_Helper_Facettes extends ZendAfi_View_Helper_BaseHelper {
protected
$_criteres_recherche,
$_current_facettes,
$_criteres,
$_current,
$_preferences;
function facettes($facettes, $preferences, $criteres_recherche) {
if(!$facettes) return;
public function facettes($facets, $preferences, $criteres) {
if (!$facets)
return;
$this->_criteres_recherche = $criteres_recherche;
$this->_criteres = $criteres;
$this->_preferences = $preferences;
Class_ScriptLoader::getInstance()
......@@ -39,82 +40,112 @@ class ZendAfi_View_Helper_Facettes extends ZendAfi_View_Helper_BaseHelper {
.'anchor.parent().remove();'
.'})');
$url = array_merge($criteres_recherche->getUrlRetourListe(),
$url = array_merge($criteres->getUrlRetourListe(),
['controller' => 'recherche',
'action' => 'simple',
'page' => null]);
return
'<div class="facette">'
. $this->listeFacettesHTML("T" . $this->_preferences['facettes_codes'],
$facettes,
$url)
. '</div>';
return $this
->_tag('div',
$this->listeFacettesHTML('T' . $this->_preferences['facettes_codes'],
$facets,
$url),
['class' => 'facette']);
}
public function listeFacettesHTML($facettes_codes,$facettes,$url) {
$html='<ul>';
foreach($facettes as $type => $valeurs){
if($facettes_codes and strpos($facettes_codes,$type) === false) continue;
public function listeFacettesHTML($codes, $facets, $url) {
$html = '';
foreach($facets as $type => $values) {
if ($codes and false === strpos($codes, $type))
continue;
$html.='<li class="facette_titre"><b>'.$valeurs["titre"].'</b>';
$html.=$this->listeFacettesElementHTML($type, array_splice($valeurs, 1), $url);
$html.='</li>';
$html .= $this
->_tag('li',
$this->_tag('b', $values['titre'])
. $this->listeFacettesElementHTML($type, array_splice($values, 1), $url),
['class' => 'facette_titre']);
}
return $html.='</ul>';
return $this->_tag('ul', $html);
}
public function listeFacettesElementHTML($type,$valeurs,$url){
$facettes_nombre = $this->_preferences['facettes_nombre'];
$first_facets = array_splice($valeurs, 0, $facettes_nombre);
$following_facets = array_splice($valeurs, 0, $facettes_nombre);
public function listeFacettesElementHTML($type, $values, $url) {
$count = $this->_preferences['facettes_nombre'];
$html = '<ul style="list-style-image:url('.URL_IMG.'puce_facette.gif)">';
foreach($first_facets as $facette)
$html .= $this->renderLIFacette($url, $facette);
$first_facets = array_splice($values, 0, $count);
$following_facets = array_splice($values, 0, $count);
if ($following_facets) {
$html .= '<li class="msg"><a href="#">'.$this->view->_('Afficher plus de facettes...').'</a><ul id="'.$type.'_msg" style="display:none">';
$html = '';
foreach($first_facets as $facet)
$html .= $this->renderLIFacette($url, $facet);
foreach($following_facets as $facette)
$html .= $this->renderLIFacette($url, $facette);
if ($following_facets)
$html .= $this->_renderFollowingFacets($type, $following_facets);
$html .= '</ul></li>';
}
return $this->_tag('ul', $html,
['style' => 'list-style-image:url(' . URL_IMG . 'puce_facette.gif)']);
}
protected function _renderFollowingFacets($type, $facets) {
$html = '';
foreach($facets as $facet)
$html .= $this->renderLIFacette($url, $facet);
return $this
->_tag('li',
$this->_tag('a', $this->_('Afficher plus de facettes...'),
['href' => '#'])
. $this->_tag('ul', $html,
['id' => $type . '_msg',
'style' => 'display:none']),
['class' => 'msg']);
}
$html.='</ul>';
return $html;
public function renderLIFacette($url, $facet) {
$url['facette'] = $facet['id'];
return $this->renderLi($url, $facet);
}
protected function renderLi($url, $facet) {
return $this
->_tag('li',
$this->renderLabel($url, $facet)
. $this->renderCount($facet)
. $this->renderRemove($facet),
['class' => 'facette' . ($this->isActive($facet['id']) ? 'selected' : '')]);
}
public function renderLIFacette($url, $facette) {
$url['facette'] = $facette['id'];
return $this->renderLi($url, $facette);
protected function renderLabel($url, $facet) {
return $this->view->tagAnchor($this->view->url($url, null, true),
$facet['libelle'],
['class' => 'facette']);
}
protected function renderLi($url, $facette) {
return
'<li class="facette'.
$this->isFacetteActive($facette['id']).'">'.
$this->view->tagAnchor($this->view->url($url, null, true),
$facette["libelle"],
['class' => 'facette']).
'<span>('.$facette["nombre"].')</span>'.
$this->view->tagAnchor($this->view->url($this->_criteres_recherche->getUrlRemoveFacette(new Class_Notice_Facette($facette['id'])),null,true),
$this->view->_('Retirer ').$facette["libelle"],
['class' => 'remove_facette',
'style' => 'display:none']).
'</li>';
protected function renderCount($facet) {
return $this->_tag('span', '(' . $facet['nombre'] . ')');
}
protected function renderRemove($facet) {
$remove_url = $this->view->url($this->_criteres->getUrlRemoveFacette(new Class_Notice_Facette($facet['id'])),
null, true);
return $this->view->tagAnchor($remove_url,
$this->_('Retirer ') . $facet['libelle'],
['class' => 'remove_facette',
'style' => 'display:none']);
}
protected function isFacetteActive($facette_id) {
$this->_current_facettes = $this->_criteres_recherche->getFacettes();
return in_array($facette_id,$this->_current_facettes) ? ' selected' : '';
protected function isActive($id) {
return in_array($id, $this->_criteres->getFacettes());
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment