Thanks, that worked well. I'm just going to include a brief tutorial on it, so
anyone in the future with a similar problem (maybe, me in three weeks) can benefit.
1) Create the non-programmatically generated fields as you normally would. (In
my case, this was things like Name, Region, Office, etc).
2) Put all the survey questions in a class methods called 'questions'
mine looks like this:
questions
^#('Event Free Tool Use'
'Understands Tasks'
'Peer Checking'
'Co-worker Coaching'
'...'
'Other')
3) Create instance variables to hold the data on your object. I added two,
questionArray and commentArray, so my class description looks like this:
Object subclass: #EmployeeSurvey
instanceVariableNames: 'region office questionArray commentArray'
classVariableNames: ''
poolDictionaries: ''
category: 'MyEmployeeSurvey'
4) Modify your initialization method to initialize the arrays
initialize
questionArray := (Array new: ((self class questions) size)).
commentArray := (Array new: ((self class questions) size)).
5) Modify this method that generates an array Magritte Descriptions (one for the
field, one for the comment, my appologies for how the code formatting):
createQuestionLabel: aLabel priority: aPriority
^(Array new: 2)
at: 1 put: ((MASingleOptionDescription accessor:
(MAChainAccessor accessor: (MAAutoSelectorAccessor selector: #questionArray)
next: (MADictionaryAccessor key: aPriority))
label: aLabel priority: 9+2*aPriority)
options: #( 'Needs Improvement' 'Meets Expectation'
'Outstanding');
reference: MANumberDescription new;
yourself);
at: 2 put: (MAMemoDescription accessor:
(MAChainAccessor accessor: (MAAutoSelectorAccessor selector: #commentArray)
next: (MADictionaryAccessor key: aPriority))
label: 'Comment'
priority: 9+2*aPriority+1);
yourself.
6) Override your classes 'description' method to look like this:
description
| desc cfields |
desc := (super description copy).
(self questions) doWithIndex: [ :val :index | cfields := self
createQuestionLabel: val priority: index.
desc add: (cfields at: 1).
desc add: (cfields at: 2). ].
^desc
Cheers,
Warren Wilkinson
Quoting Lukas Renggli <renggli(a)iam.unibe.ch>ch>:
For this
particular survey, there are 18 questions; I'd like some
advice on how
to best use magritte to describe them. I've heard of
'multiplicites' in the
context of OneToMany relations -- so this is probably not what I
want -- but is
there a count attribute in magritte descriptions?
Yes, OneToMany relations is probably not what you want.
I'd like to avoid copy/pasting 18 field
descriptions if possible.
You can also create descriptions (or copy them from somewhere else)
programmatically. Just override #description on the instance (or
class) side of your object and return whatever you want.
Question>>description
^ super description copy
addAll: OtherClass1 description copy;
addAll: OtherClass2 description copy;
yourself
The problem you probably now run into is that Question do not
understand the stuff from OtherClass1 and OtherClass2. To solve this
you might want to override #readUsing: and #write:using: in Question
to dispatch the reading/writing to other objects/dictionaries/
whatever ...
Hope this helps?
Cheers,
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki