/*
 * Created on April 21, 2006
 *	by mrsp
 */
package net.sourceforge.fenixedu.presentationTier.backBeans.scientificCouncil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.sourceforge.fenixedu.domain.organizationalStructure.Unit;
import net.sourceforge.fenixedu.presentationTier.backBeans.manager.personManagement.ManagerFunctionsManagementBackingBean;

import org.joda.time.YearMonthDay;

public class ScientificCouncilFunctionsManagementBackingBean extends ManagerFunctionsManagementBackingBean {

    protected void getUnitsList(Unit parentUnit, Unit parentUnitParent, StringBuilder buffer, YearMonthDay currentDate) {

        openLITag(buffer);

        List<Unit> subUnits = new ArrayList<Unit>(getSubUnits(parentUnit, currentDate));
        Collections.sort(subUnits, Unit.UNIT_COMPARATOR_BY_NAME);

        if (!subUnits.isEmpty()) {
            putImage(parentUnit, buffer, parentUnitParent);
        }

        buffer.append("<a href=\"").append(getContextPath()).append(
                "/scientificCouncil/functionsManagement/chooseFunction.faces?personID=")
                .append(personID).append("&unitID=").append(parentUnit.getIdInternal()).append("\">")
                .append(parentUnit.getPresentationName()).append("</a>").append("</li>");

        if (!subUnits.isEmpty()) {
            openULTag(parentUnit, buffer, parentUnitParent);
        }

        for (Unit subUnit : subUnits) {
            getUnitsList(subUnit, parentUnit, buffer, currentDate);
        }

        if (!subUnits.isEmpty()) {
            closeULTag(buffer);
        }
    }
}
