Esempio n. 1
0
  public PdfWebTable getTable(
      boolean html, boolean color, ExamReportForm form, Collection<ExamInfo> exams) {
    if (exams == null || exams.isEmpty()) return null;
    boolean timeVertical = RequiredTimeTable.getTimeGridVertical(sessionContext.getUser());
    boolean timeText = RequiredTimeTable.getTimeGridAsText(sessionContext.getUser());

    String nl = (html ? "<br>" : "\n");
    PdfWebTable table =
        new PdfWebTable(
            9,
            "Not-assigned Examinations",
            "unassignedExams.do?ord=%%",
            new String[] {
              (form.getShowSections() ? "Classes / Courses" : "Examination"),
              "Length",
              "Seating" + nl + "Type",
              "Size",
              "Max" + nl + "Rooms",
              "Instructor",
              "Period" + nl + "Preferences",
              "Room" + nl + "Preferences",
              "Distribution" + nl + "Preferences"
            },
            new String[] {
              "left", "right", "center", "right", "right", "left", "left", "left", "left"
            },
            new boolean[] {true, true, true, false, false, true, true, true, true});
    table.setRowStyle("white-space:nowrap");
    try {
      for (ExamInfo exam : exams) {
        String perPref = "", roomPref = "", distPref = "";

        if (html) {
          roomPref += exam.getExam().getEffectivePrefHtmlForPrefType(RoomPref.class);
          if (roomPref.length() > 0) roomPref += nl;
          roomPref += exam.getExam().getEffectivePrefHtmlForPrefType(BuildingPref.class);
          if (roomPref.length() > 0) roomPref += nl;
          roomPref += exam.getExam().getEffectivePrefHtmlForPrefType(RoomFeaturePref.class);
          if (roomPref.length() > 0) roomPref += nl;
          roomPref += exam.getExam().getEffectivePrefHtmlForPrefType(RoomGroupPref.class);
          if (roomPref.endsWith(nl))
            roomPref = roomPref.substring(0, roomPref.length() - nl.length());
          if (timeText) {
            perPref += exam.getExam().getEffectivePrefHtmlForPrefType(ExamPeriodPref.class);
          } else {
            if (exam.getExam().getExamType().getType() == ExamType.sExamTypeMidterm) {
              MidtermPeriodPreferenceModel epx =
                  new MidtermPeriodPreferenceModel(
                      exam.getExam().getSession(), exam.getExam().getExamType());
              epx.load(exam.getExam());
              perPref += epx.toString(true);
            } else {
              PeriodPreferenceModel px =
                  new PeriodPreferenceModel(exam.getExam().getSession(), exam.getExamTypeId());
              px.load(exam.getExam());
              perPref =
                  "<img border='0' src='pattern?v="
                      + (timeVertical ? 1 : 0)
                      + "&x="
                      + exam.getExamId()
                      + "' title='"
                      + px.toString()
                      + "'>";
            }
          }
          distPref += exam.getExam().getEffectivePrefHtmlForPrefType(DistributionPref.class);
        } else {
          for (Iterator j = exam.getExam().effectivePreferences(RoomPref.class).iterator();
              j.hasNext(); ) {
            Preference pref = (Preference) j.next();
            if (roomPref.length() > 0) roomPref += nl;
            roomPref +=
                (color
                        ? "@@COLOR "
                            + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog())
                            + " "
                        : "")
                    + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
                    + " "
                    + pref.preferenceText();
          }
          for (Iterator j = exam.getExam().effectivePreferences(BuildingPref.class).iterator();
              j.hasNext(); ) {
            Preference pref = (Preference) j.next();
            if (roomPref.length() > 0) roomPref += nl;
            roomPref +=
                (color
                        ? "@@COLOR "
                            + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog())
                            + " "
                        : "")
                    + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
                    + " "
                    + pref.preferenceText();
          }
          for (Iterator j = exam.getExam().effectivePreferences(RoomFeaturePref.class).iterator();
              j.hasNext(); ) {
            Preference pref = (Preference) j.next();
            if (roomPref.length() > 0) roomPref += nl;
            roomPref +=
                (color
                        ? "@@COLOR "
                            + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog())
                            + " "
                        : "")
                    + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
                    + " "
                    + pref.preferenceText();
          }
          for (Iterator j = exam.getExam().effectivePreferences(RoomGroupPref.class).iterator();
              j.hasNext(); ) {
            Preference pref = (Preference) j.next();
            if (roomPref.length() > 0) roomPref += nl;
            roomPref +=
                (color
                        ? "@@COLOR "
                            + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog())
                            + " "
                        : "")
                    + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
                    + " "
                    + pref.preferenceText();
          }
          if (ExamType.sExamTypeMidterm == exam.getExamType().getType()) {
            MidtermPeriodPreferenceModel epx =
                new MidtermPeriodPreferenceModel(exam.getExam().getSession(), exam.getExamType());
            epx.load(exam.getExam());
            perPref += epx.toString(false, true);
          } else {
            if (timeText || !color) {
              for (Iterator j =
                      exam.getExam().effectivePreferences(ExamPeriodPref.class).iterator();
                  j.hasNext(); ) {
                Preference pref = (Preference) j.next();
                if (perPref.length() > 0) perPref += nl;
                perPref +=
                    (color
                            ? "@@COLOR "
                                + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog())
                                + " "
                            : "")
                        + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
                        + " "
                        + pref.preferenceText();
              }
            } else {
              PeriodPreferenceModel px =
                  new PeriodPreferenceModel(
                      exam.getExam().getSession(), exam.getExamType().getUniqueId());
              px.load(exam.getExam());
              RequiredTimeTable rtt = new RequiredTimeTable(px);
              Image image = rtt.createBufferedImage(timeVertical);
              if (image != null) {
                table.addImage(exam.getExamId().toString(), image);
                perPref += "@@IMAGE " + exam.getExamId().toString() + " ";
              } else {
                for (Iterator j =
                        exam.getExam().effectivePreferences(ExamPeriodPref.class).iterator();
                    j.hasNext(); ) {
                  Preference pref = (Preference) j.next();
                  if (perPref.length() > 0) perPref += nl;
                  perPref +=
                      (color
                              ? "@@COLOR "
                                  + PreferenceLevel.prolog2color(
                                      pref.getPrefLevel().getPrefProlog())
                                  + " "
                              : "")
                          + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
                          + " "
                          + pref.preferenceText();
                }
              }
            }
          }
          for (Iterator j = exam.getExam().effectivePreferences(DistributionPref.class).iterator();
              j.hasNext(); ) {
            DistributionPref pref = (DistributionPref) j.next();
            if (distPref.length() > 0) distPref += nl;
            distPref +=
                (color
                        ? "@@COLOR "
                            + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog())
                            + " "
                        : "")
                    + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
                    + " "
                    + pref.preferenceText(true, true, " (", ", ", ")")
                        .replaceAll("&lt;", "<")
                        .replaceAll("&gt;", ">");
          }
        }

        String instructors = exam.getInstructorName(", ");

        table.addLine(
            "onClick=\"showGwtDialog('Examination Assignment', 'examInfo.do?examId="
                + exam.getExamId()
                + "','900','90%');\"",
            new String[] {
              (html ? "<a name='" + exam.getExamId() + "'>" : "")
                  + (form.getShowSections() ? exam.getSectionName(nl) : exam.getExamName())
                  + (html ? "</a>" : ""),
              String.valueOf(exam.getLength()),
              (Exam.sSeatingTypeNormal == exam.getSeatingType() ? "Normal" : "Exam"),
              String.valueOf(exam.getNrStudents()),
              String.valueOf(exam.getMaxRooms()),
              instructors,
              perPref,
              roomPref,
              distPref
            },
            new Comparable[] {
              exam,
              exam.getLength(),
              exam.getSeatingType(),
              exam.getNrStudents(),
              exam.getMaxRooms(),
              instructors,
              perPref,
              roomPref,
              distPref
            },
            exam.getExamId().toString());
      }
    } catch (Exception e) {
      Debug.error(e);
      table.addLine(new String[] {"<font color='red'>ERROR:" + e.getMessage() + "</font>"}, null);
    }
    return table;
  }
Esempio n. 2
0
 private String[] room(Class_ clazz) {
   Assignment assgn = (iUseCommitedAssignments ? clazz.getCommittedAssignment() : null);
   if (assgn == null || assgn.getRoomLocations().isEmpty()) {
     List<RoomLocation> roomLocations = TimetableDatabaseLoader.computeRoomLocations(clazz);
     if (roomLocations.size() == clazz.getNbrRooms().intValue()) {
       String[] rooms = new String[roomLocations.size()];
       for (int x = 0; x < roomLocations.size(); x++) {
         RoomLocation r = (RoomLocation) roomLocations.get(x);
         rooms[x] = r.getName();
       }
       return rooms;
     }
     Vector roomPrefs = new Vector();
     boolean allRoomReq = true;
     for (Iterator i = clazz.effectivePreferences(BuildingPref.class).iterator(); i.hasNext(); ) {
       Preference pref = (Preference) i.next();
       roomPrefs.add(
           PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
               + " "
               + pref.preferenceText());
       allRoomReq = false;
     }
     for (Iterator i = clazz.effectivePreferences(RoomPref.class).iterator(); i.hasNext(); ) {
       Preference pref = (Preference) i.next();
       roomPrefs.add(
           PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
               + " "
               + pref.preferenceText());
       if (!PreferenceLevel.sRequired.equals(pref.getPrefLevel().getPrefProlog()))
         allRoomReq = false;
     }
     for (Iterator i = clazz.effectivePreferences(RoomFeaturePref.class).iterator();
         i.hasNext(); ) {
       Preference pref = (Preference) i.next();
       roomPrefs.add(
           PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
               + " "
               + pref.preferenceText());
       allRoomReq = false;
     }
     for (Iterator i = clazz.effectivePreferences(RoomGroupPref.class).iterator(); i.hasNext(); ) {
       Preference pref = (Preference) i.next();
       roomPrefs.add(
           PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog())
               + " "
               + pref.preferenceText());
       allRoomReq = false;
     }
     if (allRoomReq) {
       roomPrefs.clear();
       for (Iterator i = clazz.effectivePreferences(RoomPref.class).iterator(); i.hasNext(); ) {
         Preference pref = (Preference) i.next();
         roomPrefs.add(pref.preferenceText());
       }
     }
     String[] rooms = new String[roomPrefs.size()];
     for (int x = 0; x < roomPrefs.size(); x++) {
       rooms[x] = roomPrefs.elementAt(x).toString();
     }
     return rooms;
   }
   String[] rooms = new String[assgn.getRoomLocations().size()];
   for (int x = 0; x < assgn.getRoomLocations().size(); x++) {
     RoomLocation r = (RoomLocation) assgn.getRoomLocations().elementAt(x);
     rooms[x] = r.getName();
   }
   return rooms;
 }