@@ -65,69 +65,85 @@ public function definition() {
65
65
$ mform ->setType ("id " , PARAM_INT );
66
66
67
67
foreach ($ this ->_customdata ['tasks ' ] as $ task ) {
68
+ $ taskprefix = "task_ $ index " ;
68
69
69
- $ group = [] ;
70
+ $ mform -> addElement ( ' header ' , "{ $ taskprefix } _header " , $ task -> name ) ;
70
71
71
- $ mform ->addElement ('header ' , 'task ' , $ task ->name );
72
- $ group [] = $ mform ->createElement ('hidden ' , 'name ' , $ task ->name );
73
-
74
- $ mform ->addElement ('html ' , '<div>Description<pre> ' . $ task ->description . '</pre></div> ' );
75
- $ group [] = $ mform ->createElement ('hidden ' , 'description ' , $ task ->description );
76
-
77
- $ mform ->addElement ('html ' , '<div>Task ID<pre> ' . $ task ->id . '</pre></div> ' );
78
- $ group [] = $ mform ->createElement ('hidden ' , 'dispatchtaskid ' , $ task ->id );
79
-
80
- $ mform ->addElement ('html ' , '<div>Scenario Template ID<pre> ' . $ task ->scenarioTemplateId . '</pre></div> ' );
81
- $ group [] = $ mform ->createElement ('hidden ' , 'scenariotemplateid ' , $ task ->scenarioTemplateId );
82
-
83
- $ mform ->addElement ('html ' , '<div>VM Mask<pre> ' . $ task ->vmMask . '</pre></div> ' );
84
- $ input = isset ($ task ->inputString ) ? $ task ->inputString : '' ;
85
- $ mform ->addElement ('html ' , '<div>Input String<pre> ' . $ input . '</pre></div> ' );
86
- $ mform ->addElement ('html ' , '<div>Expected Output<pre> ' . $ task ->expectedOutput . '</pre></div> ' );
87
-
88
- $ group [] = $ mform ->createElement ('checkbox ' , 'visible ' , get_string ('visible ' , 'crucible ' ));
89
- // $mform->addHelpButton('visible', 'visiblehelp', 'crucible');
90
-
91
- $ group [] = $ mform ->createElement ('checkbox ' , 'gradable ' , get_string ('gradable ' , 'crucible ' ));
92
- // $mform->addHelpButton('gradble', 'gradablehelp', 'crucible');
93
-
94
- $ group [] = $ mform ->createElement ('checkbox ' , 'multiple ' , get_string ('multiple ' , 'crucible ' ));
95
- // $mform->addHelpButton('mutiple', 'multiplehelp', 'crucible');
96
-
97
- $ group [] = $ mform ->createElement ('text ' , 'points ' , get_string ('points ' , 'crucible ' ), ['size ' => '5 ' ]);
98
- // $mform->addHelpButton('points', 'pointshelp', 'crucible');
99
-
100
- $ group [] = $ mform ->createElement ('html ' , get_string ('points ' , 'crucible ' ));
101
-
102
- $ mform ->addGroup ($ group , "options- $ index " , 'Options ' , [' ' ], true );
103
-
104
- $ mform ->setType ("options- " . $ index . "[name] " , PARAM_RAW );
105
- $ mform ->setType ("options- " . $ index . "[description] " , PARAM_RAW );
106
- $ mform ->setType ("options- " . $ index . "[dispatchtaskid] " , PARAM_ALPHANUMEXT );
107
- $ mform ->setType ("options- " . $ index . "[scenariotemplateid] " , PARAM_ALPHANUMEXT );
108
- $ mform ->setType ("options- " . $ index . "[points] " , PARAM_INT );
109
-
110
- $ rec = $ DB ->get_record_sql ('SELECT * from {crucible_tasks} WHERE '
111
- . $ DB ->sql_compare_text ('dispatchtaskid ' ) . ' = '
112
- . $ DB ->sql_compare_text (':dispatchtaskid ' ), ['dispatchtaskid ' => $ task ->id ]);
113
-
114
- if ($ rec === false ) {
115
- $ mform ->setDefault ("options- " . $ index . "[visible] " , 1 );
116
- $ mform ->setDefault ("options- " . $ index . "[gradable] " , 1 );
117
- $ mform ->setDefault ("options- " . $ index . "[multiple] " , 1 );
118
- $ mform ->setDefault ("options- " . $ index . "[points] " , 1 );
72
+ // HTML display of description.
73
+ if (!empty ($ task ->description )) {
74
+ $ mform ->addElement ('html ' , '<div><strong>Description</strong><pre> ' . s ($ task ->description ) . '</pre></div> ' );
75
+ }
76
+
77
+ if (!empty ($ task ->id )) {
78
+ $ mform ->addElement ('html ' , '<div><strong>Task ID</strong><pre> ' . s ($ task ->id ) . '</pre></div> ' );
79
+ }
80
+
81
+ if (!empty ($ task ->scenarioTemplateId )) {
82
+ $ mform ->addElement ('html ' , '<div><strong>Scenario Template ID</strong><pre> ' . s ($ task ->scenarioTemplateId ) . '</pre></div> ' );
83
+ }
84
+
85
+ if (!empty ($ task ->vmMask )) {
86
+ $ mform ->addElement ('html ' , '<div><strong>VM Mask</strong><pre> ' . s ($ task ->vmMask ) . '</pre></div> ' );
87
+ }
88
+
89
+ if (!empty ($ task ->inputString )) {
90
+ $ mform ->addElement ('html ' , '<div><strong>Input String</strong><pre> ' . s ($ task ->inputString ) . '</pre></div> ' );
91
+ }
92
+
93
+ if (!empty ($ task ->expectedOutput )) {
94
+ $ mform ->addElement ('html ' , '<div><strong>Expected Output</strong><pre> ' . s ($ task ->expectedOutput ) . '</pre></div> ' );
95
+ }
96
+
97
+ // Hidden fields to track values.
98
+ $ mform ->addElement ('hidden ' , "{$ taskprefix }_name " , $ task ->name );
99
+ $ mform ->setType ("{$ taskprefix }_name " , PARAM_RAW );
100
+
101
+ $ mform ->addElement ('hidden ' , "{$ taskprefix }_description " , $ task ->description );
102
+ $ mform ->setType ("{$ taskprefix }_description " , PARAM_RAW );
103
+
104
+ $ mform ->addElement ('hidden ' , "{$ taskprefix }_dispatchtaskid " , $ task ->id );
105
+ $ mform ->setType ("{$ taskprefix }_dispatchtaskid " , PARAM_ALPHANUMEXT );
106
+
107
+ $ mform ->addElement ('hidden ' , "{$ taskprefix }_scenariotemplateid " , $ task ->scenarioTemplateId );
108
+ $ mform ->setType ("{$ taskprefix }_scenariotemplateid " , PARAM_ALPHANUMEXT );
109
+
110
+ // Input fields per task.
111
+ $ mform ->addElement ('checkbox ' , "{$ taskprefix }_visible " , get_string ('visible ' , 'crucible ' ));
112
+ $ mform ->addElement ('checkbox ' , "{$ taskprefix }_gradable " , get_string ('gradable ' , 'crucible ' ));
113
+ $ mform ->addElement ('checkbox ' , "{$ taskprefix }_multiple " , get_string ('multiple ' , 'crucible ' ));
114
+ $ mform ->addElement ('html ' , '<div><strong> ' . get_string ('points ' , 'crucible ' ) . '</strong></div> ' );
115
+ $ mform ->addElement ('text ' , "{$ taskprefix }_points " , '' , ['size ' => '5 ' ]);
116
+ $ mform ->setType ("{$ taskprefix }_points " , PARAM_INT );
117
+ $ mform ->disabledIf ("{$ taskprefix }_points " , "{$ taskprefix }_gradable " );
118
+
119
+ // Help Buttons
120
+ $ mform ->addHelpButton ("{$ taskprefix }_visible " , 'visible ' , 'crucible ' );
121
+ $ mform ->addHelpButton ("{$ taskprefix }_gradable " , 'gradable ' , 'crucible ' );
122
+ $ mform ->addHelpButton ("{$ taskprefix }_multiple " , 'multiple ' , 'crucible ' );
123
+ $ mform ->addHelpButton ("{$ taskprefix }_points " , 'points ' , 'crucible ' );
124
+
125
+ // Set defaults based on DB record.
126
+ $ rec = $ DB ->get_record_sql (
127
+ 'SELECT * FROM {crucible_tasks} WHERE ' . $ DB ->sql_compare_text ('dispatchtaskid ' ) . ' = ' . $ DB ->sql_compare_text (':dispatchtaskid ' ),
128
+ ['dispatchtaskid ' => $ task ->id ]
129
+ );
130
+
131
+ if ($ rec ) {
132
+ $ mform ->setDefault ("{$ taskprefix }_visible " , $ rec ->visible );
133
+ $ mform ->setDefault ("{$ taskprefix }_gradable " , $ rec ->gradable );
134
+ $ mform ->setDefault ("{$ taskprefix }_multiple " , $ rec ->multiple );
135
+ $ mform ->setDefault ("{$ taskprefix }_points " , $ rec ->points );
119
136
} else {
120
- $ mform ->setDefault ("options- " . $ index . " [visible] " , $ rec -> visible );
121
- $ mform ->setDefault ("options- " . $ index . " [gradable] " , $ rec -> gradable );
122
- $ mform ->setDefault ("options- " . $ index . " [multiple] " , $ rec -> multiple );
123
- $ mform ->setDefault ("options- " . $ index . " [points] " , $ rec -> points );
137
+ $ mform ->setDefault ("{ $ taskprefix } _visible " , 1 );
138
+ $ mform ->setDefault ("{ $ taskprefix } _gradable " , 1 );
139
+ $ mform ->setDefault ("{ $ taskprefix } _multiple " , 1 );
140
+ $ mform ->setDefault ("{ $ taskprefix } _points " , 1 );
124
141
}
125
142
126
- $ mform ->disabledIf ("options- " . $ index . "[points] " , "options- " .$ index . "[gradable] " );
127
-
128
143
$ index ++;
129
144
}
130
145
$ this ->add_action_buttons ();
146
+
131
147
}
132
148
133
149
/**
0 commit comments