Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor attendanceMap method to classSessionService

  • Loading branch information...
commit 3f3e0e6a9283edd417d91c9bd8c67ae1596659c1 1 parent ce56d24
@NathanNeff authored
View
43 grails-app/controllers/org/bworks/bworksdb/ClassSessionController.groovy
@@ -25,47 +25,18 @@ class ClassSessionController {
def attendanceSheet = {
def classSessionInstance = ClassSession.get(params.id)
- def attendanceContacts = attendanceMapForSession(classSessionInstance)
-
- def model = [ classSessionInstance: classSessionInstance,
- attendanceContacts: attendanceContacts,
- lessonDates: classSessionInstance.lessonDates ]
-
- def renderHash = [ template:"attendanceSheet",
- model:model,
- filename:'attendance.pdf']
-
- if(params.html) {
- render(renderHash)
- }
- else {
- renderPdf(renderHash)
- }
- }
+ def enrollmentData = classSessionService.attendanceMapForSession(classSessionInstance)
- def attendanceMapForSession(classSessionInstance) {
+ def model = [ classSessionInstance: classSessionInstance, enrollmentData: enrollmentData]
- def attendanceContacts = []
+ def renderHash = [ template:"attendanceSheet", model:model, filename:'attendance.pdf']
- def sessionStudents = classSessionInstance.enrollments.collect {
- it.student
+ if(params.html) {
+ render(renderHash)
}
-
- def contacts = sessionStudents.collect {
- it.contact
- }.unique().sort { it.lastName + ":" + it.firstName }
-
- contacts.each { contact ->
- def data = [ contact: contact, info: contact.abbrevPhoneNumbers() ]
- data['students'] = sessionStudents.findAll { sessionStudent ->
- contact.students.find { contactStudent ->
- contactStudent.id == sessionStudent.id
- }
- }
- attendanceContacts << data
+ else {
+ renderPdf(renderHash)
}
-
- return attendanceContacts
}
def quickCallList = {
View
46 grails-app/services/org/bworks/bworksdb/ClassSessionService.groovy
@@ -5,23 +5,6 @@ class ClassSessionService {
boolean transactional = true
- def attendanceMapForSession(classSessionInstance) {
- def enrolledStudents = []
-
- def students = classSessionInstance.enrollments.each { enr ->
- def row = [:]
- def phonez = enr.student.contact.phoneNumbers?.collect{
- it.phoneNumber
- }.join(", ")
- row.studentName = enr.student.toString() + phonez
- classSessionInstance.lessonDates.each { ld ->
- row["attended_${ld.id}"] = " "
- }
- enrolledStudents << row
- }
- return enrolledStudents
- }
-
// returns a map like this:
// <studentId> : [ attendanceCount:6, totalLessons:6,
// missed : [lessonDate1, lessonDate2] ]
@@ -206,4 +189,33 @@ class ClassSessionService {
}
return interests
}
+
+ def attendanceMapForSession(classSessionInstance) {
+
+ def attendanceContacts = []
+
+ def sessionStudents = classSessionInstance.enrollments.collect {
+ it.student
+ }
+
+ def contacts = sessionStudents.collect {
+ it.contact
+ }.unique().sort { it.lastName + ":" + it.firstName }
+
+ contacts.each { contact ->
+ def data = [ contact: contact, info: contact.abbrevPhoneNumbers() ]
+ data['students'] = sessionStudents.findAll { sessionStudent ->
+ contact.students.find { contactStudent ->
+ contactStudent.id == sessionStudent.id
+ }
+ }
+ attendanceContacts << data
+ }
+
+ return attendanceContacts
+ }
+
+
+
+
}
View
2  grails-app/views/classSession/_attendanceSheet.gsp
@@ -40,7 +40,7 @@
</tr>
</thead>
<tbody>
- <g:each status="i" var="contact" in="${attendanceContacts}">
+ <g:each status="i" var="contact" in="${enrollmentData}">
<g:each status="s" var="student" in="${contact.students}">
<tr class="${ i%2 == 0 ? 'contact-even' : 'contact-odd'}">
<g:if test="${s == 0}">
Please sign in to comment.
Something went wrong with that request. Please try again.