/**
  * SELECT de la liste des planning semaine
  *
  * @return
  */
 @SuppressWarnings("unchecked")
 public static List<Planning_Semaine> getAll() {
   Session session = PilotageSession.getCurrentSession();
   List<Planning_Semaine> lps = session.createCriteria(Planning_Semaine.class).list();
   session.getTransaction().commit();
   return lps;
 }
  @SuppressWarnings("unchecked")
  public static boolean hasSemaineWithVacation(int id) {
    Session session = PilotageSession.getCurrentSession();

    Planning_Vacation pv = (Planning_Vacation) session.load(Planning_Vacation.class, id);
    List<Long> results =
        (List<Long>)
            session
                .createCriteria(Planning_Semaine.class)
                .add(
                    Restrictions.or(
                        Restrictions.eq("lundi", pv),
                        Restrictions.or(
                            Restrictions.eq("mardi", pv),
                            Restrictions.or(
                                Restrictions.eq("mercredi", pv),
                                Restrictions.or(
                                    Restrictions.eq("jeudi", pv),
                                    Restrictions.or(
                                        Restrictions.eq("vendredi", pv),
                                        Restrictions.or(
                                            Restrictions.eq("samedi", pv),
                                            Restrictions.eq("dimanche", pv))))))))
                .setProjection(Projections.rowCount())
                .list();
    session.getTransaction().commit();

    if (results != null && results.size() > 0 && results.get(0) > 0) {
      return true;
    } else {
      return false;
    }
  }
 /**
  * SELECT d'un planning semaine
  *
  * @return
  */
 public static Planning_Semaine get(Integer selectRow) {
   Session session = PilotageSession.getCurrentSession();
   Planning_Semaine ps =
       (Planning_Semaine)
           session
               .createCriteria(Planning_Semaine.class)
               .add(Restrictions.eq("id", selectRow))
               .setMaxResults(1)
               .uniqueResult();
   session.getTransaction().commit();
   return ps;
 }
 /**
  * SELECT des semaines du cycle
  *
  * @param idCycle
  * @return
  */
 @SuppressWarnings("unchecked")
 public static List<Planning_Semaine> getSemaineByCycle(Integer idCycle) {
   Session session = PilotageSession.getCurrentSession();
   Planning_Cycle pc = (Planning_Cycle) session.load(Planning_Cycle.class, idCycle);
   List<Planning_Semaine> semaineList =
       session
           .createCriteria(Planning_Semaine.class)
           .add(Restrictions.eq("idNomCycle", pc))
           .addOrder(Order.asc("numeroSemaine"))
           .list();
   session.getTransaction().commit();
   return semaineList;
 }
 public static Integer getId(Integer idCycle, Integer numSemaine) {
   Session session = PilotageSession.getCurrentSession();
   Planning_Cycle pc = (Planning_Cycle) session.load(Planning_Cycle.class, idCycle);
   Planning_Semaine ps =
       (Planning_Semaine)
           session
               .createCriteria(Planning_Semaine.class)
               .add(Restrictions.eq("idNomCycle", pc))
               .add(Restrictions.eq("numeroSemaine", numSemaine))
               .setMaxResults(1)
               .uniqueResult();
   session.getTransaction().commit();
   return ps.getId();
 }
 @SuppressWarnings("unchecked")
 public static List<Planning_Semaine> getSemaineByCycleAndDate(
     Integer idCycle, DateTime deb, DateTime fin) {
   Session session = PilotageSession.getCurrentSession();
   Planning_Cycle pc = (Planning_Cycle) session.load(Planning_Cycle.class, idCycle);
   List<Planning_Semaine> semaineList =
       session
           .createCriteria(Planning_Semaine.class)
           .add(Restrictions.eq("idNomCycle", pc))
           .add(Restrictions.or(Restrictions.isNull("dateFin"), Restrictions.ge("dateFin", deb)))
           .add(Restrictions.le("dateDeb", fin))
           .addOrder(Order.asc("numeroSemaine"))
           .addOrder(Order.asc("dateDeb"))
           .list();
   session.getTransaction().commit();
   return semaineList;
 }
  public static List<Planning_Semaine> getBySemAndCycle(Integer idCycle, Integer numSemaine) {
    Session session = PilotageSession.getCurrentSession();

    Planning_Cycle pc = (Planning_Cycle) session.load(Planning_Cycle.class, idCycle);

    @SuppressWarnings("unchecked")
    List<Planning_Semaine> semaineList =
        (List<Planning_Semaine>)
            session
                .createCriteria(Planning_Semaine.class)
                .add(Restrictions.eq("idNomCycle", pc))
                .add(Restrictions.eq("numeroSemaine", numSemaine))
                .addOrder(Order.asc("dateDeb"))
                .list();
    // fait exprès car fonction utilisé dans PlanningCyclesDatabaseService
    // session.getTransaction().commit();
    return semaineList;
  }