--- /dev/null
+/*******************************************************************************
+ * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+ *
+ * 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>.
+ ******************************************************************************/
+package com.pentila.entSavoie.utils;
+
+import com.liferay.portal.kernel.json.JSONFactoryUtil;
+import com.liferay.portal.kernel.json.JSONObject;
+import com.liferay.portal.kernel.log.Log;
+import com.liferay.portal.kernel.log.LogFactoryUtil;
+import com.liferay.portal.model.Organization;
+import com.liferay.portal.model.User;
+import com.pentila.entSavoie.ENTRolesConstants;
+import com.pentila.entSavoie.carnetDAdresses.model.Fiche;
+import com.pentila.entSavoie.directory.OrganizationFinderServiceUtil;
+
+public class JsonUserFactory {
+
+ private static Log _log = LogFactoryUtil.getLog(JsonUserFactory.class);
+
+ public static JSONObject convertUserToJson (User user) {
+
+ JSONObject jsonUser = JSONFactoryUtil.createJSONObject();
+
+ jsonUser.put("userId", user.getUserId());
+ jsonUser.put("userFirstName", user.getFirstName());
+ jsonUser.put("userLastName", user.getLastName());
+
+ try {
+ boolean isFemale = user.getJobTitle().equals("Mme") || user.getJobTitle().equals("Mlle");
+ jsonUser.put("isMale", !isFemale);
+
+ Organization school = OrganizationFinderServiceUtil.getEtabRatachement(user);
+ if (school != null) {
+ jsonUser.put("schoolId", school.getOrganizationId());
+ jsonUser.put("schoolName", school.getName());
+ }
+
+ // Role
+ if (ENTRolesConstants.isStudent(user)) {
+ jsonUser.put("role", "El\u00E8ve");
+ } else if (ENTRolesConstants.isParent(user)) {
+ jsonUser.put("role", "Parent");
+ } else if (ENTRolesConstants.isTeacher(user)) {
+ jsonUser.put("role", "Enseignant");
+ } else {
+ jsonUser.put("role", "Personnel");
+ }
+
+// ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute("THEME_DISPLAY");
+// if (contactUser.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(contactFiche.getRelUserId());
+// portraitVisible = up.getPortraitVisible();
+// } catch (Exception e) {
+// }
+//
+// String urlImg = "";
+// if (portraitVisible) {
+// urlImg = url + contactUser.getPortraitId() + "&t=" + WebServerServletTokenUtil.getToken(contactUser.getPortraitId());
+// } else {
+// urlImg = url + "0";
+// }
+
+ } catch (Exception e) {
+ _log.error("Error when getting informations on user "+user.getUserId(), e);
+ }
+ return jsonUser;
+ }
+
+ public static JSONObject convertUserToJson(Fiche fiche) {
+
+ JSONObject jsonUser = JSONFactoryUtil.createJSONObject();
+
+ try {
+ JSONObject properties = JSONFactoryUtil.createJSONObject(fiche.getProperties());
+
+ jsonUser.put("userId", 0);
+ jsonUser.put("userFirstName", properties.getString("prenom"));
+ jsonUser.put("userLastName", properties.getString("nom"));
+
+ jsonUser.put("isMale", properties.getBoolean("isMale", true));
+
+ if (!properties.getString("organisation").isEmpty()) {
+ jsonUser.put("schoolName", properties.getString("organisation"));
+ }
+
+ jsonUser.put("role", "Externe");
+ } catch (Exception e) {
+ _log.error("Error when getting informations on fiche "+fiche.getFicheId(), e);
+ }
+
+ return jsonUser;
+ }
+}