source: trunk/grails-app/controllers/SandboxController.groovy @ 153

Last change on this file since 153 was 146, checked in by keesvb, 11 years ago

added helper functions to Subject and Template classes to easily get the template fields, and added a demonstration of use in the sandbox

File size: 866 bytes
Line 
1import dbnp.studycapturing.*
2
3// The sandbox is meant for internal communication over code examples etc.
4
5class SandboxController {
6
7        def index = {
8
9                // Get the example study in a lazy way
10                def st = Study.get(1)
11                def f = st.template.subjectFields
12
13                // This is a way to iterate over the fields in your controller
14                // And print them to the console
15                // Most of the time, you would just iterate over them in the view using <g:each>
16                // See also views/sandbox/index.gsp
17                f.each {field ->
18                        println field.name + "(" + field.type + ")"
19                }
20
21                //Let's get a certain field for a certain subject
22                def subject = Subject.findByName('A1')
23                println st.template.getSubjectFieldType('Age')
24                println subject.getFieldValue('Age')
25
26
27                // Specify which variables we want to be available in the controller (implicit return statement)
28                [fields: f, subjects: st.subjects]
29}
30}
Note: See TracBrowser for help on using the repository browser.