--- /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;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import com.liferay.portal.kernel.language.LanguageUtil;
+import com.liferay.portal.kernel.util.StringUtil;
+import com.liferay.portal.model.Role;
+import com.liferay.portal.model.User;
+
+public class ENTDisplayUtil {
+
+ public static String formatSCONETName(User user, String name) {
+ return formatSCONETName(name, true);
+ }
+
+ public static String formatSCONETName(User user, String name, boolean showEtabLabel) {
+ return formatSCONETName(name, showEtabLabel);
+ }
+
+ public static String formatSCONETName(long companyId, String name) {
+ return formatSCONETName(name, true);
+ }
+
+ public static String formatSCONETName(long companyId, String name, boolean showEtabLabel) {
+ return formatSCONETName(name, showEtabLabel);
+ }
+
+ public static String formatSCONETName(String name, boolean showEtabLabel) {
+ // on ne traite que les entrees commencant par CLG-
+ if (!name.startsWith("CLG-") &&
+ !name.startsWith("LGT-") &&
+ !name.startsWith("LG-") &&
+ !name.startsWith("Lyc") &&
+ !name.startsWith("CLG PR-") &&
+ !name.startsWith("LGT PR-") &&
+ !name.startsWith("LP PR-") &&
+ !name.startsWith("LP-") &&
+ !name.startsWith("LPO-") &&
+ !name.startsWith("I.A.-") &&
+ !name.startsWith("EREA-") &&
+ !name.startsWith("Erea-") &&
+ !name.startsWith("SEGPA-") &&
+ !name.startsWith("GRETA-") &&
+ !name.startsWith("SEP-") &&
+ !name.startsWith("LP LYC METIER-") &&
+ !name.startsWith("LPO LYC METIER-") &&
+ !name.startsWith("Lpo") &&
+ !name.startsWith("Lp") &&
+ !name.startsWith("Lgt") &&
+ !name.startsWith("Site") &&
+ !name.startsWith("RECTORAT-")) {
+ return name;
+ }
+
+ if (name.contains("LFR_ORGANIZATION")) {
+ name = name.replace("LFR_ORGANIZATION", "");
+ name = name.trim();
+ }
+
+ String[] first = StringUtil.split(name, " - ");
+ if (first.length > 1) {
+ String res = "";
+ if (showEtabLabel) {
+ // on a une classe et on veut le nom du college
+ res = getEtabLabel(first[0]);
+ }
+
+ for (int i=1; i<first.length; i++) {
+ res += " - " + first[i];
+ }
+
+ if (res.startsWith(" - ")){
+ res = res.substring(3);
+ }
+
+ return res;
+ }
+ else {
+ if (first.length == 0) {
+ // cas peu probable !!!!
+ return name;
+ }
+ // on a un college
+ String res = first[0];
+ return getEtabLabel(res);
+ }
+ }
+
+ private static String getEtabLabel(String etabLabel) {
+ if (etabLabel.startsWith("CLG-")){
+ etabLabel = etabLabel.replace("CLG-", "clg ");
+ }
+ if (etabLabel.startsWith("SEP-")){
+ etabLabel = etabLabel.replace("SEP-", "sep ");
+ }
+ if (etabLabel.startsWith("LGT-")){
+ etabLabel = etabLabel.replace("LGT-", "lgt ");
+ }
+ if (etabLabel.startsWith("LG-")){
+ etabLabel = etabLabel.replace("LG-", "lg ");
+ }
+ if (etabLabel.startsWith("CLG PR-")){
+ etabLabel = etabLabel.replace("CLG PR-", "clg pr ");
+ }
+ if (etabLabel.startsWith("LGT PR-")){
+ etabLabel = etabLabel.replace("LGT PR-", "lgt pr ");
+ }
+ if (etabLabel.startsWith("LP PR-")){
+ etabLabel = etabLabel.replace("LP PR-", "lp pr ");
+ }
+ if (etabLabel.startsWith("LP-")){
+ etabLabel = etabLabel.replace("LP-", "lp ");
+ }
+ if (etabLabel.startsWith("LPO-")){
+ etabLabel = etabLabel.replace("LPO-", "lpo ");
+ }
+ if (etabLabel.startsWith("I.A.-")){
+ etabLabel = etabLabel.replace("I.A.-", "I.A. ");
+ }
+ if (etabLabel.startsWith("SEGPA-")){
+ etabLabel = etabLabel.replace("SEGPA-", "SEGPA ");
+ }
+ if (etabLabel.startsWith("GRETA-")){
+ etabLabel = etabLabel.replace("GRETA-", "GRETA ");
+ }
+ if (etabLabel.startsWith("LP LYC METIER-")){
+ etabLabel = etabLabel.replace("LP LYC METIER-", "lp lyc metier ");
+ }
+ if (etabLabel.startsWith("LPO LYC METIER-")){
+ etabLabel = etabLabel.replace("LPO LYC METIER-", "lpo lyc metier ");
+ }
+ if (etabLabel.startsWith("RECTORAT-")){
+ etabLabel = etabLabel.replace("RECTORAT-", "Rectorat ");
+ }
+ etabLabel = etabLabel.replace("-ac-GRENOBLE", "");
+ etabLabel = etabLabel.replace("-ac-ROUEN", "");
+ etabLabel = capitalize(etabLabel);
+ return etabLabel;
+ }
+
+ /**
+ * Capitalize a string
+ * Manages string that contains a double space
+ * @param s
+ * @return
+ */
+ public static String capitalize(String s){
+ StringBuilder bob = new StringBuilder();
+ for (String string : s.split(" ")) {
+ if (!string.equals("")) {
+ bob.append(string.substring(0, 1).toUpperCase());
+ bob.append(string.substring(1).toLowerCase());
+ bob.append(" ");
+ }
+ }
+ s = bob.toString().trim();
+ return s;
+ }
+
+
+ /*
+ * Permet l'affichage des roles de la personne dans les differnetes interface de l'ENT
+ *
+ */
+ public static String displayUserRoles(User currentUser, User user) {
+ String roleStr = "";
+ final Role[] lesRoles = ENTRoleUtilFactory.getInstance(currentUser.getCompanyId()).getENTRoles(user);
+
+ Set<String> roleLabels = new HashSet<String>();
+
+ for (int i=0; i<lesRoles.length; i++) {
+ roleLabels.add(LanguageUtil.get(currentUser.getLocale(), lesRoles[i].getName()));
+ }
+
+ Iterator<String> it = roleLabels.iterator();
+
+ for (int i=0; it.hasNext(); i++) {
+ roleStr += it.next();
+ if (it.hasNext()) {
+ roleStr += ", ";
+ }
+ }
+
+ return roleStr;
+ }
+
+
+
+
+
+}