From d7070f5c8cd6da76104d2ccb8030f4af7eec8db3 Mon Sep 17 00:00:00 2001
From: pairprog <pairprog@afi-sa.fr>
Date: Fri, 28 Feb 2014 17:09:51 +0100
Subject: [PATCH] rename domainsbrowsing

---
 library/ZendAfi/View/Helper/DomainBrowser.php | 87 +++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 library/ZendAfi/View/Helper/DomainBrowser.php

diff --git a/library/ZendAfi/View/Helper/DomainBrowser.php b/library/ZendAfi/View/Helper/DomainBrowser.php
new file mode 100644
index 00000000000..6bdaa3767af
--- /dev/null
+++ b/library/ZendAfi/View/Helper/DomainBrowser.php
@@ -0,0 +1,87 @@
+<?php 
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * AFI-OPAC 2.0 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+
+class ZendAfi_View_Helper_DomainBrowser extends ZendAfi_View_Helper_BaseHelper {
+	public function domainBrowser($current_domain,$current_breadcrumb) {
+		if (null == $current_domain)
+			$current_domain = Class_Catalogue::getRoot();
+
+		return
+			$this->displayParentsDomains($current_breadcrumb).
+			'<ul>'.$this->displayDomain($current_domain,$current_breadcrumb).'</ul>'.
+			$this->displayChildrenDomains($current_domain->getChildren(),
+																		$this->constructBreadcrumb($current_domain,$current_breadcrumb));
+	}
+
+	protected function displayChildrenDomains($children_domains,$parents_domains) {
+		$html='';
+		foreach($children_domains as $child) {
+			$html.=$this->displayDomain($child,$parents_domains);
+		}
+		return '<div class="domains_children"><ul>'.$html.'</ul></div>';
+	}
+
+	protected function constructBreadcrumb($current_domain,$current_breadcrumb) {
+		return 
+			$current_breadcrumb
+			?	$current_breadcrumb.';'.$current_domain->getId()
+			: $current_domain->getId();
+	}
+
+	public function displayParentsDomains($breadcrumb) {
+		if (!$breadcrumb)
+			return '';
+		
+		$html="<div class='domains_breadcrumb'><ul>";
+		$parents_domains=Class_Catalogue::getDomainsForBreadcrumb($breadcrumb);
+		$new_breadcrumb='';
+		foreach($parents_domains as $domain) {
+			$html.=$this->displayDomain($domain,$new_breadcrumb);
+			$new_breadcrumb=$this->constructBreadcrumb($domain,$new_breadcrumb);
+		}
+		return $html."</ul></div>";
+	}
+
+	protected function displayDomain($domain,$breadcrumb) {
+		return '<li>'.
+			$this->view
+			->tagAnchor($this->getBrowsingDomainUrl($domain,$breadcrumb),
+									($url_img=$domain->getUrlImg())	? $this->view->tagImg($url_img,	['alt' => $domain->getLibelle(), 'title' => $domain->getLibelle()]): $domain->getLibelle())
+			.'</li>';
+	}
+
+
+	protected function getBrowsingDomainUrl($domain, $parents) {
+		return 
+			$domain->hasSousDomaines() 
+			?	$this->view->url(array_filter(['controller' =>'domains',
+																			 'action' => 'browse',
+																			 'id'=> $domain->getId(),
+																			 'parents' => $parents]),null,true)
+			: $this->view->url(array_filter(['controller' =>'recherche',
+																			 'action' => 'simple',
+																			 'id_catalogue'=> $domain->getId(),
+																			 'parents' => $parents]),null,true);
+	}
+
+}
+
+?>
\ No newline at end of file
-- 
GitLab