protected static NSMutableDictionary convertEvent(Reason.Event event) { NSMutableDictionary dict = new NSMutableDictionary(event.reason(), "reason"); if (event.reason().verification() == null) dict.takeValueForKey("grey", "cellClass"); dict.takeValueForKey(event.date(), "date"); EduCourse course = event.course(); dict.takeValueForKey(course.eduGroup(), "eduGroup"); dict.takeValueForKey(course.cycle().grade(), "grade"); Substitute sub = null; if (event instanceof Variation) { Variation var = (Variation) event; dict.takeValueForKey(var.relatedLesson(), "lesson"); Variation back = var.getPaired(); NSArray subs = (NSArray) var.valueForKeyPath("relatedLesson.substitutes"); if (subs != null && subs.count() > 0) { if (subs.count() == 1) { sub = (Substitute) subs.objectAtIndex(0); } else { dict.takeValueForKey(subs, "multiply"); } } if (var.value().intValue() > 0) { dict.takeValueForKey(var.course(), "plusCourse"); if (back != null) { dict.takeValueForKey(back.course(), "minusCourse"); dict.takeValueForKey(back.course().teacher(), "minusTeacher"); } if (sub == null) { if (var.reason().namedFlags().flagForKey("toReturn")) dict.takeValueForKey("@", "value"); else dict.takeValueForKey(var.value(), "value"); dict.takeValueForKey(var.course().teacher(), "plusTeacher"); } } else { dict.takeValueForKey(var.course(), "minusCourse"); dict.takeValueForKey(var.course().teacher(), "minusTeacher"); if (back != null) { dict.takeValueForKey(back.course(), "plusCourse"); if (sub == null) { dict.takeValueForKey(back.course().teacher(), "plusTeacher"); if (back.reason().namedFlags().flagForKey("toReturn")) dict.takeValueForKey("@", "value"); else dict.takeValueForKey(back.value(), "value"); } } else if (sub == null) { dict.takeValueForKey(new Integer(-var.value().intValue()), "value"); } } } else if (event instanceof Substitute) { sub = (Substitute) event; dict.takeValueForKey(sub.course(), "minusCourse"); dict.takeValueForKey(sub.course(), "plusCourse"); dict.takeValueForKey(sub.course().teacher(), "minusTeacher"); dict.takeValueForKey(sub.lesson(), "lesson"); } if (sub != null) { dict.takeValueForKey(sub.teacher(), "plusTeacher"); dict.takeValueForKey(sub.value(), "value"); } return dict; }
public static WOActionResults exportJournalZPU( NSArray journal, WOContext context, String filename) { WOSession ses = context.session(); if (journal == null || journal.count() == 0) { WOResponse response = WOApplication.application().createResponseInContext(context); response.appendContentString( (String) ses.valueForKeyPath("strings.RujelCurriculum_Curriculum.Tabel.noData")); response.setHeader("application/octet-stream", "Content-Type"); response.setHeader("attachment; filename=\"noData.txt\"", "Content-Disposition"); return response; } Export export = new ExportCSV(context, filename); export.beginRow(); export.addValue(ses.valueForKeyPath("strings.Reusables_Strings.dataTypes.Date")); export.addValue(ses.valueForKeyPath("strings.RujelCurriculum_Curriculum.OrigTeacher")); export.addValue(ses.valueForKeyPath("strings.RujelInterfaces_Names.EduCycle.subject")); export.addValue(ses.valueForKeyPath("strings.RujelInterfaces_Names.EduGroup.this")); export.addValue(ses.valueForKeyPath("strings.RujelCurriculum_Curriculum.Reason.Reason")); export.addValue(ses.valueForKeyPath("strings.RujelCurriculum_Curriculum.Reason.verification")); export.addValue( ses.valueForKeyPath("strings.RujelCurriculum_Curriculum.Substitute.Substitutor")); export.addValue(ses.valueForKeyPath("strings.RujelInterfaces_Names.EduCycle.subject")); export.addValue(ses.valueForKeyPath("strings.RujelCurriculum_Curriculum.Substitute.factor")); Enumeration enu = journal.objectEnumerator(); StringBuilder buf = new StringBuilder(); while (enu.hasMoreElements()) { NSDictionary dict = (NSDictionary) enu.nextElement(); export.beginRow(); export.addValue(MyUtility.dateFormat().format(dict.valueForKey("date"))); EduCourse course = (EduCourse) dict.valueForKey("minusCourse"); if (course != null) { Teacher teacher = (Teacher) dict.valueForKey("minusTeacher"); if (teacher != null) export.addValue(Person.Utility.fullName(teacher, true, 2, 1, 1)); else export.addValue(ses.valueForKeyPath("strings.RujelBase_Base.vacant")); if (course.comment() == null) { export.addValue(course.cycle().subject()); } else { buf.delete(0, buf.length()); buf.append(course.cycle().subject()); buf.append(' ').append('(').append(course.comment()).append(')'); export.addValue(buf.toString()); } } else { export.addValue(null); export.addValue(null); } if (dict.valueForKey("eduGroup") != null) export.addValue(dict.valueForKeyPath("eduGroup.name")); else export.addValue(dict.valueForKey("grade")); export.addValue(dict.valueForKeyPath("reason.title")); export.addValue(dict.valueForKeyPath("reason.verification")); course = (EduCourse) dict.valueForKey("plusCourse"); if (course != null) { Teacher teacher = (Teacher) dict.valueForKey("plusTeacher"); export.addValue(Person.Utility.fullName(teacher, true, 2, 1, 1)); if (course.comment() == null) { export.addValue(course.cycle().subject()); } else { buf.delete(0, buf.length()); buf.append(course.cycle().subject()); buf.append(' ').append('(').append(course.comment()).append(')'); export.addValue(buf.toString()); } } else { export.addValue(null); export.addValue(null); } export.addValue(dict.valueForKey("value")); } return export; }