Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-qtype_stack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-qtype_stack
Commits
3d474b52
Commit
3d474b52
authored
13 years ago
by
Tim Hunt
Browse files
Options
Downloads
Patches
Plain Diff
Save the new question test when the form is submitted
parent
dedee458
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
questiontestedit.php
+47
-1
47 additions, 1 deletion
questiontestedit.php
questiontestform.php
+6
-3
6 additions, 3 deletions
questiontestform.php
with
53 additions
and
4 deletions
questiontestedit.php
+
47
−
1
View file @
3d474b52
...
@@ -48,6 +48,13 @@ $testcase = optional_param('testcase', null, PARAM_INT);
...
@@ -48,6 +48,13 @@ $testcase = optional_param('testcase', null, PARAM_INT);
$questiondata
=
$DB
->
get_record
(
'question'
,
array
(
'id'
=>
$questionid
),
'*'
,
MUST_EXIST
);
$questiondata
=
$DB
->
get_record
(
'question'
,
array
(
'id'
=>
$questionid
),
'*'
,
MUST_EXIST
);
$question
=
question_bank
::
load_question
(
$questionid
);
$question
=
question_bank
::
load_question
(
$questionid
);
$context
=
$question
->
get_context
();
$context
=
$question
->
get_context
();
if
(
$testcase
)
{
$testcasedata
=
$DB
->
get_record
(
'qtype_stack_qtests'
,
array
(
'questionid'
=>
$question
->
id
,
'testcase'
=>
$testcase
),
'*'
,
MUST_EXIST
);
}
else
{
$testcasedata
=
new
stdClass
();
$testcasedata
->
questionid
=
$question
->
id
;
}
// Check permissions.
// Check permissions.
require_login
();
require_login
();
...
@@ -86,7 +93,46 @@ if ($mform->is_cancelled()) {
...
@@ -86,7 +93,46 @@ if ($mform->is_cancelled()) {
}
else
if
(
$data
=
$mform
->
get_data
())
{
}
else
if
(
$data
=
$mform
->
get_data
())
{
// Process form submission.
// Process form submission.
// TODO.
$transaction
=
$DB
->
start_delegated_transaction
();
if
(
!
$testcase
)
{
// Find the first unused testcase number.
$testcase
=
$DB
->
get_field_sql
(
'
SELECT COALESCE(MIN(qt.testcase), 0) + 1
FROM {qtype_stack_qtests} qt
LEFT JOIN {qtype_stack_qtests} qt2 ON qt2.questionid = qt.questionid AND
qt2.testcase = qt.testcase + 1
WHERE qt.questionid = ? AND qt2.id IS NULL
'
,
array
(
$questionid
));
$testcasedata
->
testcase
=
$testcase
;
$DB
->
insert_record
(
'qtype_stack_qtests'
,
$testcasedata
);
}
// Save the input data.
$DB
->
delete_records
(
'qtype_stack_qtest_inputs'
,
array
(
'questionid'
=>
$question
->
id
,
'testcase'
=>
$testcase
));
foreach
(
$question
->
inputs
as
$inputname
=>
$notused
)
{
$testinput
=
new
stdClass
();
$testinput
->
questionid
=
$question
->
id
;
$testinput
->
testcase
=
$testcase
;
$testinput
->
inputname
=
$inputname
;
$testinput
->
value
=
$data
->
$inputname
;
$DB
->
insert_record
(
'qtype_stack_qtest_inputs'
,
$testinput
);
}
// Save the expected outcome data.
$DB
->
delete_records
(
'qtype_stack_qtest_expected'
,
array
(
'questionid'
=>
$question
->
id
,
'testcase'
=>
$testcase
));
foreach
(
$question
->
prts
as
$prtname
=>
$notused
)
{
$expected
=
new
stdClass
();
$expected
->
questionid
=
$question
->
id
;
$expected
->
testcase
=
$testcase
;
$expected
->
prtname
=
$prtname
;
$expected
->
expectedscore
=
$data
->
{
$prtname
.
'score'
};
$expected
->
expectedpenalty
=
$data
->
{
$prtname
.
'penalty'
};
$expected
->
expectedanswernote
=
$data
->
{
$prtname
.
'answernote'
};
$DB
->
insert_record
(
'qtype_stack_qtest_expected'
,
$expected
);
}
$transaction
->
allow_commit
();
redirect
(
$backurl
);
redirect
(
$backurl
);
}
}
...
...
This diff is collapsed.
Click to expand it.
questiontestform.php
+
6
−
3
View file @
3d474b52
...
@@ -56,9 +56,12 @@ class qtype_stack_question_test_form extends moodleform {
...
@@ -56,9 +56,12 @@ class qtype_stack_question_test_form extends moodleform {
foreach
(
$question
->
prts
as
$prtname
=>
$prt
)
{
foreach
(
$question
->
prts
as
$prtname
=>
$prt
)
{
$elements
=
array
(
$elements
=
array
(
$mform
->
createElement
(
'text'
,
$prtname
.
'score'
,
get_string
(
'score'
,
'qtype_stack'
),
array
(
'size'
=>
2
)),
$mform
->
createElement
(
'text'
,
$prtname
.
'score'
,
$mform
->
createElement
(
'text'
,
$prtname
.
'penalty'
,
get_string
(
'penalty'
,
'qtype_stack'
),
array
(
'size'
=>
2
)),
get_string
(
'score'
,
'qtype_stack'
),
array
(
'size'
=>
2
)),
$mform
->
createElement
(
'text'
,
$prtname
.
'answernote'
,
get_string
(
'answernote'
,
'qtype_stack'
),
array
(
'size'
=>
15
)),
$mform
->
createElement
(
'text'
,
$prtname
.
'penalty'
,
get_string
(
'penalty'
,
'qtype_stack'
),
array
(
'size'
=>
2
)),
$mform
->
createElement
(
'text'
,
$prtname
.
'answernote'
,
get_string
(
'answernote'
,
'qtype_stack'
),
array
(
'size'
=>
15
)),
);
);
// TODO change the answernote field to be a dropdown list of the answer notes
// TODO change the answernote field to be a dropdown list of the answer notes
// that this PRT can generate.
// that this PRT can generate.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment