--- /dev/null
+<%/**
+*Copyright © Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+*
+*This file is part of the work and learning management system Pentila Nero.
+*
+*Pentila Nero is free software. You can redistribute it and/or modify since
+*you respect the terms of either (at least one of the both license) :
+*- under the terms of the GNU Affero General Public License as
+*published by the Free Software Foundation, either version 3 of the
+*License, or (at your option) any later version.
+*- the CeCILL-C as published by CeCILL-C; either version 1 of the
+*License, or any later version
+*- the GNU Lesser General Public License as published by the
+*Free Software Foundation, either version 3 of the license,
+*or (at your option) any later version.
+*
+*There are special exceptions to the terms and conditions of the
+*licenses as they are applied to this software. View the full text of
+*the exception in file LICENSE-PROJECT.txt in the directory of this software
+*distribution.
+*
+*Pentila Nero 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
+*Licenses for more details.
+*
+*You should have received a copy of the GNU Affero General Public License
+*and the CeCILL-C and the GNU Lesser General Public License along with
+*Pentila Nero. If not, see :
+*<http://www.gnu.org/licenses/> and
+*<http://www.cecill.info/licences.fr.html>.
+*/%>
+<%@page import="com.liferay.portal.kernel.servlet.HttpHeaders"%>
+<%@page import="com.pentila.entSavoie.directory.OrganizationFinderServiceUtil"%>
+<%@page import="com.liferay.portal.webserver.WebServerServletTokenUtil"%>
+<%@page import="com.pentila.entSavoie.userProperties.service.UserPropertiesLocalServiceUtil"%>
+<%@page import="com.pentila.entSavoie.userProperties.model.UserProperties"%>
+<%@page import="com.pentila.entSavoie.portlets.amis.proxys.ProxyAmis"%>
+<%@page import="com.pentila.entSavoie.portlets.amis.AmiLastNameComparator"%>
+<%@page import="com.liferay.portal.kernel.util.OrderByComparator"%>
+<%@page import="com.sun.jmx.remote.util.OrderClassLoaders"%>
+<%@page import="java.util.Collections"%>
+<%@page import="com.liferay.portal.kernel.dao.orm.QueryUtil"%>
+<%@page import="com.liferay.portal.model.User"%>
+<%@page import="com.liferay.portal.service.ExtUserLocalServiceUtil"%>
+<%@page import="com.pentila.entSavoie.amis.service.RelationshipLocalServiceUtil"%>
+<%@page import="com.pentila.entSavoie.amis.model.Relationship"%>
+
+<%@page import="com.liferay.portal.kernel.json.JSONArray"%>
+<%@page import="com.liferay.portal.kernel.json.JSONFactoryUtil"%>
+<%@page import="com.liferay.portal.kernel.json.JSONObject"%>
+<%@page import="java.util.Comparator"%>
+<%@page import="java.util.ArrayList"%>
+<%@page import="javax.portlet.PortletURL"%>
+<%@page import="javax.portlet.PortletPreferences"%>
+<%@page import="java.util.List"%>
+<%@page import="com.liferay.portal.service.RoleLocalServiceUtil"%>
+<%@page import="com.liferay.portal.kernel.language.LanguageUtil"%>
+<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
+
+<%@page import="com.pentila.entSavoie.ENTDisplayUtil"%>
+
+<%@ include file="./init.jsp" %>
+
+<%
+ renderResponse.setContentType("text/xml");
+ response.setContentType("text/xml");
+ response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache");
+
+ final Long userId = ParamUtil.getLong(renderRequest, "userId", 0);
+
+ List<Relationship> listRes = new ArrayList<Relationship>();
+ List<Relationship> listMesAmis = new ArrayList<Relationship>();
+ List<ProxyAmis> mesAmis = new ArrayList<ProxyAmis>();
+ List<ProxyAmis> otherAmis = new ArrayList<ProxyAmis>();
+
+
+ OrderByComparator obc = new AmiLastNameComparator(true);
+
+
+
+ //On récupère les amis de notre "futur" ami
+ if (userId!=0){
+ listRes = RelationshipLocalServiceUtil.getRelationshipByUserIdStateId(userId, 2, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
+
+ //On récupère nos amis
+ listMesAmis = RelationshipLocalServiceUtil.getRelationshipByUserIdStateId(user.getUserId(), 2, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
+ }
+
+ for(Relationship r : listRes){
+ boolean exist = false;
+ if (user.getUserId() != r.getFriendId()) {
+ for (Relationship monAmi: listMesAmis) {
+
+ if (monAmi.getFriendId() == r.getFriendId()) {
+ ProxyAmis pa = new ProxyAmis(r.getFriendId());
+ mesAmis.add(pa);
+ exist = true;
+ break;
+ }
+ }
+
+ if (exist == false) {
+ ProxyAmis pa = new ProxyAmis(r.getFriendId());
+ otherAmis.add(pa);
+ }
+ }
+ }
+
+ //ProxyAmis pa = new ProxyAmis(r.getFriendId());
+ //listFinal.add(pa);
+
+ //on trie
+ Collections.sort(mesAmis);
+ Collections.sort(otherAmis);
+
+
+ int mesAmisSize = mesAmis.size();
+ mesAmis.addAll(otherAmis);
+%>
+
+ <amis>
+ <%
+ for(ProxyAmis pa : mesAmis){
+
+ String url = "";
+ User u = ExtUserLocalServiceUtil.getUser(pa.getId());
+ if (u.isFemale()) {
+ url = themeDisplay.getPathImage() + "/user_female_portrait?img_id=";
+ } else {
+ url = themeDisplay.getPathImage() + "/user_male_portrait?img_id=";
+ }
+
+ boolean portraitVisible = true;
+
+ try {
+ UserProperties up = UserPropertiesLocalServiceUtil.getUserPropertiesByUserId(pa.getId());
+ portraitVisible = up.getPortraitVisible();
+ } catch (Exception e){
+ }
+
+ String urlImg = "";
+
+ if(portraitVisible){
+ urlImg = url + u.getPortraitId() + "&t=" + WebServerServletTokenUtil.getToken(u.getPortraitId());
+ } else {
+ urlImg = url + "0";
+ }
+
+ String status = ENTDisplayUtil.displayUserRoles(user, u);
+
+ String etabName = messages.getString("etablissement-non-communique");
+ try{
+ etabName = ENTDisplayUtil.formatSCONETName(user, OrganizationFinderServiceUtil.getEtabRatachement(u).getName());
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ %>
+
+ <ami>
+ <userId><%=pa.getId()%></userId>
+ <name><%=pa.getLastName()%></name>
+ <firstName><%=pa.getFirstName()%></firstName>
+ <img><![CDATA[<%=urlImg%>]]></img>
+ <etab><%=etabName%></etab>
+ <status><%=status%></status>
+ <commonFriends><%=RelationshipLocalServiceUtil.countCommonRelationShip(user.getUserId(),pa.getId())%></commonFriends>
+
+ <%
+ if (mesAmisSize > 0) {
+ %>
+ <myFriend>1</myFriend>
+ <grouping><%= messages.getString("amis-communs") %></grouping>
+
+ <%
+ mesAmisSize--;
+ }
+ else {
+ %>
+ <myFriend>2</myFriend>
+ <grouping><%= messages.getString("autres-amis") %></grouping>
+
+ <%
+ }
+
+ %>
+ </ami>
+ <%
+
+ }
+ %>
+
+ </amis>