--- /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.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil"%>
+<%@page import="com.pentila.entSavoie.blogEntryInfos.model.BlogEntryDelegate"%>
+<%@page import="com.pentila.entSavoie.blogEntryInfos.service.BlogEntryDelegateLocalServiceUtil"%>
+<%@page import="com.liferay.contacts.util.OrganizationFilter"%>
+<%@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="com.pentila.entSavoie.ENTRolesConstants"%>
+<%@page import="com.liferay.portal.service.OrganizationLocalServiceUtil"%>
+<%@page import="com.pentila.entSavoie.communityInfos.service.CommunityInfosLocalServiceUtil"%>
+<%@page import="com.pentila.entSavoie.communityInfos.model.CommunityInfos"%>
+<%@page import="java.util.ArrayList"%>
+<%@page import="com.liferay.portal.util.comparator.GroupNameComparator"%>
+<%@page import="java.util.LinkedHashMap"%>
+<%@page import="com.liferay.portal.model.Organization"%>
+<%@page import="com.liferay.portal.service.UserGroupRoleLocalServiceUtil"%>
+<%@page import="com.pentila.entSavoie.ENTRoleUtilFactory"%>
+<%@page import="com.liferay.portal.model.RoleConstants"%>
+<%@page import="java.text.SimpleDateFormat"%>
+<%@page import="com.liferay.portal.model.Group"%>
+<%@page import="com.liferay.portal.service.GroupLocalServiceUtil"%>
+<%@page import="com.liferay.portal.kernel.util.ListUtil"%>
+<%@page import="javax.portlet.PortletURL"%>
+<%@page import="javax.portlet.PortletPreferences"%>
+<%@page import="com.liferay.portal.kernel.util.GetterUtil"%>
+<%@page import="com.liferay.portlet.blogs.service.BlogsEntryServiceUtil"%>
+<%@page import="com.liferay.portal.kernel.dao.search.SearchContainer"%>
+<%@page import="com.liferay.portal.kernel.util.DateUtil"%>
+<%@page import="java.util.Date"%>
+<%@page import="com.liferay.portal.kernel.dao.orm.QueryUtil"%>
+<%@page import="com.liferay.portal.kernel.dao.orm.QueryPos"%>
+<%@page import="com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil"%>
+<%@page import="com.liferay.portlet.blogs.model.BlogsEntry"%>
+<%@page import="com.pentila.entSavoie.blogEntryInfos.service.BlogEntryInfosLocalServiceUtil"%>
+<%@page import="com.pentila.entSavoie.blogEntryInfos.model.BlogEntryInfos"%>
+<%@page import="com.liferay.portal.service.UserGroupLocalServiceUtil"%>
+<%@page import="com.liferay.portal.model.UserGroup"%>
+<%@page import="java.util.HashSet"%>
+<%@page import="java.util.List"%>
+<%@page import="com.liferay.portal.service.RoleLocalServiceUtil"%>
+<%@page import="com.liferay.portal.model.Role"%>
+<%@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();
+
+ final JSONArray grps = JSONFactoryUtil.createJSONArray();
+
+ long actuId = ParamUtil.getLong(renderRequest, "actuId", 0);
+
+ List<Long> listGroupIds = new ArrayList<Long>();
+
+ //Si on est sur un édition
+ if (actuId != 0){
+ BlogEntryInfos bei = BlogEntryInfosLocalServiceUtil.getBlogEntryInfos(actuId);
+ listGroupIds = BlogEntryInfosLocalServiceUtil.getGroupIds(bei.getBlogEntryGroup());
+ }
+
+
+ Role communityOwnerRole = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(RoleConstants.SITE_OWNER);
+ Role communityAdminRole = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(RoleConstants.SITE_ADMINISTRATOR);
+ Role orgaAdminRole = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(RoleConstants.ORGANIZATION_ADMINISTRATOR);
+
+ Role student = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_1);
+ Boolean isStudent = RoleLocalServiceUtil.hasUserRole(user.getUserId(), student.getRoleId());
+
+ Role teacher = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_3);
+ Boolean isTeacher = RoleLocalServiceUtil.hasUserRole(user.getUserId(), teacher.getRoleId());
+
+ Role assistEducation = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_21);
+ Boolean isAssistEducation = RoleLocalServiceUtil.hasUserRole(user.getUserId(), assistEducation.getRoleId());
+
+ Role documentaliste = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_24);
+ Boolean isDocumentaliste = RoleLocalServiceUtil.hasUserRole(user.getUserId(), documentaliste.getRoleId());
+
+ Role persoEducation = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_25);
+ Boolean isPersoEducation = RoleLocalServiceUtil.hasUserRole(user.getUserId(), persoEducation.getRoleId());
+
+ Role medicoSociaux = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_28);
+ Boolean isMedicoSociaux = RoleLocalServiceUtil.hasUserRole(user.getUserId(), medicoSociaux.getRoleId());
+
+ Role conseilOrient = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_29);
+ Boolean isConseilOrient = RoleLocalServiceUtil.hasUserRole(user.getUserId(), conseilOrient.getRoleId());
+
+ Role adminGrpRole = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.GROUP_ADMIN);
+ Boolean isGrpAdmin = RoleLocalServiceUtil.hasUserRole(user.getUserId(), adminGrpRole.getRoleId());
+
+ Role headmasterRole = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_4);
+ Boolean isHeadMaster = RoleLocalServiceUtil.hasUserRole(user.getUserId(), headmasterRole.getRoleId());
+
+ Role externalRole = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.EXTERNAL);
+ Boolean isExternal = RoleLocalServiceUtil.hasUserRole(user.getUserId(), externalRole.getRoleId());
+
+ Group gScope = GroupLocalServiceUtil.getGroup(scopeGroupId);
+
+ List<BlogEntryDelegate> listBed = BlogEntryDelegateLocalServiceUtil.getEtabUserDelegate(user.getUserId());
+ Boolean isDelegate = false;
+ if (!listBed.isEmpty()) {
+ isDelegate = true;
+ }
+
+ //on recupere seulement notre communauté
+ if(gScope.isRegularSite()){
+ try {
+ CommunityInfos ci = CommunityInfosLocalServiceUtil.getCommunityInfosByGroupId(gScope.getGroupId());
+ if (ci.getStatus()==0) {
+
+ JSONObject orgJson = JSONFactoryUtil.createJSONObject();
+ orgJson.put("grpId", gScope.getGroupId());
+ orgJson.put("grpName", gScope.getName());
+ grps.put(orgJson);
+ }
+ }
+ catch(Exception e) {
+ // aucune info pour ce groupe --> surement le groupe Guest
+ }
+
+ ret.put("grps", grps);
+
+ }
+ //on recupere seulement notre organisation
+ else if(gScope.isOrganization()){
+
+ Organization org = OrganizationLocalServiceUtil.getOrganization(gScope.getOrganizationId());
+
+ JSONObject orgJson = JSONFactoryUtil.createJSONObject();
+ orgJson.put("grpId", org.getGroup().getGroupId());
+ orgJson.put("grpName", ENTDisplayUtil.formatSCONETName(user, org.getName()));
+ grps.put(orgJson);
+
+ ret.put("grps", grps);
+
+ }
+
+
+ //si on est sur notre page perso on recup tous ceux auxquels on appartient
+ else{
+
+
+
+ // CAS DES ORGANIZATIONS
+ List<Organization> userOrgs = null;
+ if (ENTMainUtilsLocalServiceUtil.isSchemaSupann(user.getCompanyId())){
+ userOrgs = new ArrayList<Organization>();
+ userOrgs.add(OrganizationFinderServiceUtil.getEtabRatachement(user));
+ }
+ else if (isHeadMaster || isDocumentaliste || isAssistEducation || isPersoEducation || isDelegate || isConseilOrient || isMedicoSociaux) {
+ userOrgs = OrganizationFilter.getAllUserSchoolOrganizations(user);
+ }
+ else {
+ userOrgs = user.getOrganizations();
+ }
+
+ for(Organization org : userOrgs){
+
+ if(listGroupIds.contains(org.getGroup().getGroupId())){
+
+ // on teste pour ne pas prendre les orgs migrate=done
+ PortletPreferences prefs = org.getPreferences();
+ if (prefs.getValue("migrate", "none").equals("done")) {
+ continue;
+ }
+
+
+ Boolean hasSubOrg = org.hasSuborganizations();
+ Boolean isOrgAdmin = UserGroupRoleLocalServiceUtil.hasUserGroupRole(user.getUserId(), org.getGroup().getGroupId(), orgaAdminRole.getRoleId());
+ //si ce n'est pas un eleve on lui donne
+ if(isDelegate || isOrgAdmin || isGrpAdmin || isHeadMaster || isDocumentaliste || isConseilOrient || isMedicoSociaux || isPersoEducation || isAssistEducation || isExternal || (isTeacher && !hasSubOrg)){
+ JSONObject orgJson = JSONFactoryUtil.createJSONObject();
+ orgJson.put("grpId", org.getGroup().getGroupId());
+ orgJson.put("grpName", ENTDisplayUtil.formatSCONETName(user, org.getName()));
+ grps.put(orgJson);
+ }
+ }
+ }
+
+ // CAS DES GROUPES COMMUNAUTAIRES
+ // presente l ensemble des groupes de l'utilisateur
+
+ List<Group> listUserGrp = user.getGroups();
+
+ for (Group gTmp: listUserGrp) {
+ try {
+ CommunityInfos ci = CommunityInfosLocalServiceUtil.getCommunityInfosByGroupId(gTmp.getGroupId());
+ if (ci.getStatus()==0) {
+
+ if (listGroupIds.contains(gTmp.getGroupId())){
+ Boolean isCommunityAdmin = UserGroupRoleLocalServiceUtil.hasUserGroupRole(user.getUserId(), gTmp.getGroupId(), communityAdminRole.getRoleId());
+ Boolean isCommunityOwner = UserGroupRoleLocalServiceUtil.hasUserGroupRole(user.getUserId(), gTmp.getGroupId(), communityOwnerRole.getRoleId());
+ //si c'est un élève, on ne recup que les grp dont il est admin
+ if(isCommunityAdmin || isCommunityOwner || isGrpAdmin || isHeadMaster ){
+ JSONObject orgJson = JSONFactoryUtil.createJSONObject();
+ orgJson.put("grpId", gTmp.getGroupId());
+ orgJson.put("grpName", gTmp.getName());
+ grps.put(orgJson);
+ }
+ }
+ }
+ }
+ catch(Exception e) {
+ // aucune info pour ce groupe --> surement le groupe Guest
+ }
+ }
+
+ ret.put("grps", grps);
+ }
+ ret.put("success", true);
+%>
+<%= ret.toString() %>