Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plugins bot
moodle-plugins-snapshots
Commits
f417416c
Commit
f417416c
authored
Jan 31, 2017
by
Andrew Nicols
Browse files
Merge branch 'MDL-57296-master' of
git://github.com/ankitagarwal/moodle
parents
010e2216
6c6bd6e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
grade/report/grader/lib.php
View file @
f417416c
...
...
@@ -45,6 +45,13 @@ class grade_report_grader extends grade_report {
*/
private
$allgrades
;
/**
* Contains all grade items expect GRADE_TYPE_NONE.
*
* @var array $allgradeitems
*/
private
$allgradeitems
;
/**
* Array of errors for bulk grades updating.
* @var array $gradeserror
...
...
@@ -520,6 +527,22 @@ class grade_report_grader extends grade_report {
return
$this
->
users
;
}
/**
* Load all grade items.
*/
protected
function
get_allgradeitems
()
{
if
(
!
empty
(
$this
->
allgradeitems
))
{
return
$this
->
allgradeitems
;
}
$allgradeitems
=
grade_item
::
fetch_all
(
array
(
'courseid'
=>
$this
->
courseid
));
// But hang on - don't include ones which are set to not show the grade at all.
$this
->
allgradeitems
=
array_filter
(
$allgradeitems
,
function
(
$item
)
{
return
$item
->
gradetype
!=
GRADE_TYPE_NONE
;
});
return
$this
->
allgradeitems
;
}
/**
* we supply the userids in this query, and get all the grades
* pulls out all the grades, this does not need to worry about paging
...
...
@@ -543,11 +566,16 @@ class grade_report_grader extends grade_report {
WHERE g.itemid = gi.id AND gi.courseid = :courseid
{
$this
->
userselect
}
"
;
$userids
=
array_keys
(
$this
->
users
);
$allgradeitems
=
$this
->
get_allgradeitems
();
if
(
$grades
=
$DB
->
get_records_sql
(
$sql
,
$params
))
{
foreach
(
$grades
as
$graderec
)
{
$grade
=
new
grade_grade
(
$graderec
,
false
);
$this
->
allgrades
[
$graderec
->
userid
][
$graderec
->
itemid
]
=
$grade
;
if
(
!
empty
(
$allgradeitems
[
$graderec
->
itemid
]))
{
// Note: Filter out grades which have a grade type of GRADE_TYPE_NONE.
// Only grades without this type are present in $allgradeitems.
$this
->
allgrades
[
$graderec
->
userid
][
$graderec
->
itemid
]
=
$grade
;
}
if
(
in_array
(
$graderec
->
userid
,
$userids
)
and
array_key_exists
(
$graderec
->
itemid
,
$this
->
gtree
->
get_items
()))
{
// some items may not be present!!
$this
->
grades
[
$graderec
->
userid
][
$graderec
->
itemid
]
=
$grade
;
$this
->
grades
[
$graderec
->
userid
][
$graderec
->
itemid
]
->
grade_item
=
$this
->
gtree
->
get_item
(
$graderec
->
itemid
);
// db caching
...
...
@@ -568,6 +596,18 @@ class grade_report_grader extends grade_report {
}
}
}
// Pre fill grades for any remaining items which might be collapsed.
foreach
(
$userids
as
$userid
)
{
foreach
(
$allgradeitems
as
$itemid
=>
$gradeitem
)
{
if
(
!
isset
(
$this
->
allgrades
[
$userid
][
$itemid
]))
{
$this
->
allgrades
[
$userid
][
$itemid
]
=
new
grade_grade
();
$this
->
allgrades
[
$userid
][
$itemid
]
->
itemid
=
$itemid
;
$this
->
allgrades
[
$userid
][
$itemid
]
->
userid
=
$userid
;
$this
->
allgrades
[
$userid
][
$itemid
]
->
grade_item
=
$gradeitem
;
}
}
}
}
/**
...
...
@@ -922,12 +962,7 @@ class grade_report_grader extends grade_report {
// grade items (in case one has been hidden) as the course total shown needs to be adjusted for this particular
// user.
if
(
!
$this
->
canviewhidden
)
{
$allgradeitems
=
grade_item
::
fetch_all
(
array
(
'courseid'
=>
$this
->
courseid
));
// But hang on - don't include ones which are set to not show the grade at all.
$allgradeitems
=
array_filter
(
$allgradeitems
,
function
(
$item
)
{
return
$item
->
gradetype
!=
GRADE_TYPE_NONE
;
});
$allgradeitems
=
$this
->
get_allgradeitems
();
}
foreach
(
$this
->
users
as
$userid
=>
$user
)
{
...
...
grade/report/grader/tests/behat/switch_views.feature
View file @
f417416c
...
...
@@ -12,6 +12,7 @@ Feature: We can change what we are viewing on the grader report
|
username
|
firstname
|
lastname
|
email
|
|
teacher1
|
Teacher
|
1
|
teacher1@example.com
|
|
student1
|
Student
|
1
|
student1@example.com
|
|
student2
|
Student
|
1
|
student2@example.com
|
And the following "course enrolments" exist
:
|
user
|
course
|
role
|
|
teacher1
|
C1
|
editingteacher
|
...
...
@@ -94,6 +95,9 @@ Feature: We can change what we are viewing on the grader report
|
capability
|
permission
|
|
moodle/grade:viewhidden
|
Prevent
|
And
I log out
And the following "course enrolments" exist
:
|
user
|
course
|
role
|
|
student2
|
C1
|
student
|
And
I log in as
"teacher1"
And
I follow
"Course 1"
And
I navigate to
"View > Grader report"
in the course gradebook
...
...
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