Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KNIGHT
Asyst Moodle Plugin
Commits
0faa1bc2
Commit
0faa1bc2
authored
1 year ago
by
Artem Baranovskyi
Browse files
Options
Download
Email Patches
Plain Diff
Added check if the answers already graded.
parent
6d93bfa3
asystgrade-master-project
2-please-don-t-call-curl_init-directly-and-instead-use-moodle-s-curl-class
4-can-the-post-be-sanitised-before-passing-to-the-external-service
2 merge requests
!3
Fixed whole Docker infrastructure with dummy moodle plugin.
,
!2
Draft: Resolve "can the post be sanitised before passing to the external service?"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
asystgrade/classes/db/QuizQuery.php
+20
-0
asystgrade/classes/db/QuizQuery.php
asystgrade/lib.php
+15
-3
asystgrade/lib.php
with
35 additions
and
3 deletions
+35
-3
asystgrade/classes/db/QuizQuery.php
+
20
-
0
View file @
0faa1bc2
...
@@ -72,4 +72,24 @@ class QuizQuery implements QuizQueryInterface
...
@@ -72,4 +72,24 @@ class QuizQuery implements QuizQueryInterface
MUST_EXIST
MUST_EXIST
)
->
value
;
)
->
value
;
}
}
/**
* Checks if scores exist for a given quizid and userid.
* *
* * @param int $quizid quiz ID.
* * @param int $userid user ID.
* * @return bool Returns true if scores exist for a given quizid and userid, otherwise false.
*/
public
function
gradesExist
(
int
$quizid
,
int
$userid
):
bool
{
global
$DB
;
// Check for the presence of an entry in the mdl_quiz_grades table for this quizid and userid
return
$DB
->
record_exists
(
'quiz_grades'
,
[
'quiz'
=>
$quizid
,
'userid'
=>
$userid
]
);
}
}
}
This diff is collapsed.
Click to expand it.
asystgrade/lib.php
+
15
-
3
View file @
0faa1bc2
...
@@ -44,11 +44,21 @@ function local_asystgrade_before_footer()
...
@@ -44,11 +44,21 @@ function local_asystgrade_before_footer()
if
(
$PAGE
->
url
->
compare
(
new
moodle_url
(
'/mod/quiz/report.php'
),
URL_MATCH_BASE
)
&&
$slot
)
{
if
(
$PAGE
->
url
->
compare
(
new
moodle_url
(
'/mod/quiz/report.php'
),
URL_MATCH_BASE
)
&&
$slot
)
{
$quizQuery
=
new
QuizQuery
();
$quizQuery
=
new
QuizQuery
();
if
(
$quizQuery
->
gradesExist
(
$qid
,
$slot
))
{
error_log
(
'Grades already exist in the database.'
);
return
;
}
$question_attempts
=
$quizQuery
->
get_question_attempts
(
$qid
,
$slot
);
$question_attempts
=
$quizQuery
->
get_question_attempts
(
$qid
,
$slot
);
$referenceAnswer
=
$quizQuery
->
get_reference_answer
(
$qid
);
$referenceAnswer
=
$quizQuery
->
get_reference_answer
(
$qid
);
$data
=
prepare_api_data
(
$quizQuery
,
$question_attempts
,
$referenceAnswer
);
$data
=
prepare_api_data
(
$quizQuery
,
$question_attempts
,
$referenceAnswer
);
foreach
(
$data
[
'studentAnswers'
]
as
$index
=>
$studentAnswer
)
{
$userid
=
$data
[
'studentIds'
][
$index
];
if
(
$quizQuery
->
gradesExist
(
$qid
,
$userid
))
{
return
;
}
}
$inputNames
=
$data
[
'inputNames'
];
$inputNames
=
$data
[
'inputNames'
];
error_log
(
'Data prepared: '
.
print_r
(
$data
,
true
));
error_log
(
'Data prepared: '
.
print_r
(
$data
,
true
));
...
@@ -105,6 +115,7 @@ function prepare_api_data(QuizQuery $database, $question_attempts, $referenceAns
...
@@ -105,6 +115,7 @@ function prepare_api_data(QuizQuery $database, $question_attempts, $referenceAns
{
{
$studentAnswers
=
[];
$studentAnswers
=
[];
$inputNames
=
[];
$inputNames
=
[];
$studentIds
=
[];
foreach
(
$question_attempts
as
$question_attempt
)
{
foreach
(
$question_attempts
as
$question_attempt
)
{
$quizattempt_steps
=
$database
->
get_attempt_steps
(
$question_attempt
->
id
);
$quizattempt_steps
=
$database
->
get_attempt_steps
(
$question_attempt
->
id
);
...
@@ -114,7 +125,7 @@ function prepare_api_data(QuizQuery $database, $question_attempts, $referenceAns
...
@@ -114,7 +125,7 @@ function prepare_api_data(QuizQuery $database, $question_attempts, $referenceAns
$studentAnswer
=
$database
->
get_student_answer
(
$quizattempt_step
->
id
);
$studentAnswer
=
$database
->
get_student_answer
(
$quizattempt_step
->
id
);
$studentAnswers
[]
=
$studentAnswer
;
$studentAnswers
[]
=
$studentAnswer
;
$inputNames
[]
=
"q"
.
$question_attempt
->
questionusageid
.
":"
.
$question_attempt
->
slot
.
"_-mark"
;
$inputNames
[]
=
"q"
.
$question_attempt
->
questionusageid
.
":"
.
$question_attempt
->
slot
.
"_-mark"
;
$studentIds
[]
=
$quizattempt_step
->
userid
;
error_log
(
"Student Answer:
$studentAnswer
, Input Name: "
.
end
(
$inputNames
));
error_log
(
"Student Answer:
$studentAnswer
, Input Name: "
.
end
(
$inputNames
));
}
}
}
}
...
@@ -127,7 +138,8 @@ function prepare_api_data(QuizQuery $database, $question_attempts, $referenceAns
...
@@ -127,7 +138,8 @@ function prepare_api_data(QuizQuery $database, $question_attempts, $referenceAns
return
[
return
[
'referenceAnswer'
=>
$referenceAnswer
,
'referenceAnswer'
=>
$referenceAnswer
,
'studentAnswers'
=>
$studentAnswers
,
'studentAnswers'
=>
$studentAnswers
,
'inputNames'
=>
$inputNames
'inputNames'
=>
$inputNames
,
'studentIds'
=>
$studentIds
];
];
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets