--- /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.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.AmiLastNameComparator"%>
+<%@page import="com.liferay.portal.kernel.util.OrderByComparator"%>
+<%@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" %>
+
+<%
+ final JSONObject ret = JSONFactoryUtil.createJSONObject();
+ ret.put("success", true);
+
+ List<Relationship> listRes = new ArrayList<Relationship>();
+ final JSONArray relations = JSONFactoryUtil.createJSONArray();
+
+ //les status:
+ //O = en attente (receveur)
+ //1 = en attente de validation (emetteur)
+ //2 = valide
+
+ boolean hide= false;
+
+ listRes = RelationshipLocalServiceUtil.getRelationshipByUserIdStateId(user.getUserId(), 0, QueryUtil.ALL_POS,QueryUtil.ALL_POS);
+
+ for(Relationship r : listRes){
+ JSONObject rel = JSONFactoryUtil.createJSONObject();
+ User friend = ExtUserLocalServiceUtil.getUserById(r.getFriendId());
+
+ rel.put("relationId",r.getRelationId());
+ rel.put("name",friend.getFirstName()+" "+friend.getLastName());
+
+ if(!r.getMessage().equals("")){
+ if(r.getMessage().length()>100){
+ hide = false;
+ }else{
+ hide = true;
+ }
+ }else{
+ hide = true;
+ }
+ String url = "";
+
+ if (friend.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(r.getFriendId());
+ portraitVisible = up.getPortraitVisible();
+ } catch (Exception e){
+ }
+
+ String urlImg = "";
+
+ if(portraitVisible){
+ urlImg = url + friend.getPortraitId() + "&t=" + WebServerServletTokenUtil.getToken(friend.getPortraitId());
+ } else {
+ urlImg = url + "0";
+ }
+ String status = ENTDisplayUtil.displayUserRoles(user, friend);
+ rel.put("userId",friend.getUserId());
+ rel.put("message",r.getMessage());
+ rel.put("hideMsg",hide);
+ rel.put("img",urlImg);
+ rel.put("status",status);
+ rel.put("etab", ENTDisplayUtil.formatSCONETName(user, OrganizationFinderServiceUtil.getEtabRatachement(friend).getName()));
+ rel.put("commonFriends",RelationshipLocalServiceUtil.countCommonRelationShip(user.getUserId(),r.getFriendId()));
+ relations.put(rel);
+ }
+
+ ret.put("relations", relations);
+%>
+<%= ret.toString() %>