2020-10-27 00:50:13 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-17 06:37:46 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2017 - present Instructure, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
class GradebookUserIds
|
|
|
|
def initialize(course, user)
|
2020-02-06 00:51:25 +08:00
|
|
|
settings = (user.get_preference(:gradebook_settings, course.global_id) || {}).with_indifferent_access
|
2017-06-17 06:37:46 +08:00
|
|
|
@course = course
|
2018-01-10 23:58:39 +08:00
|
|
|
@user = user
|
2017-06-17 06:37:46 +08:00
|
|
|
@include_inactive = settings[:show_inactive_enrollments] == "true"
|
|
|
|
@include_concluded = settings[:show_concluded_enrollments] == "true"
|
|
|
|
@column = settings[:sort_rows_by_column_id] || "student"
|
|
|
|
@sort_by = settings[:sort_rows_by_setting_key] || "name"
|
|
|
|
@selected_grading_period_id = settings.dig(:filter_columns_by, :grading_period_id)
|
2017-06-24 06:05:33 +08:00
|
|
|
@selected_section_id = settings.dig(:filter_rows_by, :section_id)
|
2019-02-12 05:53:58 +08:00
|
|
|
@selected_student_group_id = settings.dig(:filter_rows_by, :student_group_id)
|
2017-06-17 06:37:46 +08:00
|
|
|
@direction = settings[:sort_rows_by_direction] || "ascending"
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_ids
|
|
|
|
if @column == "student"
|
Add more gradebook sort options
flag=new_gradebook_sort_options
closes TALLY-210
Test plan:
- Have a course using new gradebook
- Have several students with pseudonyms (i.e., logins; see below)
- Have at least one pseudonym-less student
- Have a mechanism to filter students (section or student group)
- Enable the feature:
- Open the Settings page for your root account and allow the
"Additional Sort Options for New Gradebook" feature
- Open the Settings page for your course and enable the above setting
for the course
- Open new Gradebook
- In the student column header menu, the "Sort by" item should now show
several sort fields and (separately) a sort order
- Check that the sort fields work as expected:
- (Note that you will need to use the "Secondary info" menu item to
show the relevant info field under users' names; selecting a sort
option will not automatically change the secondary info to match)
- "Name" should sort by the user's (sortable) name
- "SIS ID" should sort by the SIS user ID on the user's account
- "Integration ID" should sort by the account's integration ID
- "Login ID" should sort by the user's login name
- "A-Z" and "Z-A" should switch between ascending and descending
sort order for the selected sort field
- In all cases, students with no value for the selected field (e.g., a
student with no login ID) should appear at the bottom of the list,
regardless of the selected sort order
- Check that filtering by section or group still works as expected
- Selecting a specific filter, as well as removing the filter, should
respect the sort field and order
- Turn OFF the feature flag for the course
- Go back to New Gradebook
- Check that the sort menu has returned to its previous state, with
only "A-Z" and "Z-A" options that sort by name
- (If you were sorting by a different criterion when you had the flag
enabled, said criterion will initially still be in effect, but
adjusting the sort order will bounce it back to sorting by name)
APPENDIX: adding pseudonyms
To create a pseudonym for a student in a Rails console:
> user = <a student>
> user.pseudonyms.create!(
account: user.account,
sis_user_id: "some_sis_id_or_other",
integration_id: "some_integration_id_or_other",
unique_id: "a_login_id"
)
Or you could do it the boring way by just adding a login from their user
details page, but I'm not sure how to update the SIS ID and integration
ID from there.
Change-Id: I290bced84432a4776a9c20efbaeb26aeb7e18638
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/200805
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Tested-by: Jenkins
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: Jonathan Fenton <jfenton@instructure.com>
2019-07-09 04:38:12 +08:00
|
|
|
sort_by_student_field
|
2018-01-05 07:18:35 +08:00
|
|
|
elsif @column =~ /assignment_\d+$/
|
2017-06-17 06:37:46 +08:00
|
|
|
assignment_id = @column[/\d+$/]
|
|
|
|
send("sort_by_assignment_#{@sort_by}", assignment_id)
|
2018-01-05 07:18:35 +08:00
|
|
|
elsif @column =~ /^assignment_group_\d+$/
|
|
|
|
assignment_id = @column[/\d+$/]
|
|
|
|
sort_by_assignment_group(assignment_id)
|
2017-06-17 06:37:46 +08:00
|
|
|
elsif @column == "total_grade"
|
|
|
|
sort_by_total_grade
|
|
|
|
else
|
|
|
|
sort_by_student_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
Add more gradebook sort options
flag=new_gradebook_sort_options
closes TALLY-210
Test plan:
- Have a course using new gradebook
- Have several students with pseudonyms (i.e., logins; see below)
- Have at least one pseudonym-less student
- Have a mechanism to filter students (section or student group)
- Enable the feature:
- Open the Settings page for your root account and allow the
"Additional Sort Options for New Gradebook" feature
- Open the Settings page for your course and enable the above setting
for the course
- Open new Gradebook
- In the student column header menu, the "Sort by" item should now show
several sort fields and (separately) a sort order
- Check that the sort fields work as expected:
- (Note that you will need to use the "Secondary info" menu item to
show the relevant info field under users' names; selecting a sort
option will not automatically change the secondary info to match)
- "Name" should sort by the user's (sortable) name
- "SIS ID" should sort by the SIS user ID on the user's account
- "Integration ID" should sort by the account's integration ID
- "Login ID" should sort by the user's login name
- "A-Z" and "Z-A" should switch between ascending and descending
sort order for the selected sort field
- In all cases, students with no value for the selected field (e.g., a
student with no login ID) should appear at the bottom of the list,
regardless of the selected sort order
- Check that filtering by section or group still works as expected
- Selecting a specific filter, as well as removing the filter, should
respect the sort field and order
- Turn OFF the feature flag for the course
- Go back to New Gradebook
- Check that the sort menu has returned to its previous state, with
only "A-Z" and "Z-A" options that sort by name
- (If you were sorting by a different criterion when you had the flag
enabled, said criterion will initially still be in effect, but
adjusting the sort order will bounce it back to sorting by name)
APPENDIX: adding pseudonyms
To create a pseudonym for a student in a Rails console:
> user = <a student>
> user.pseudonyms.create!(
account: user.account,
sis_user_id: "some_sis_id_or_other",
integration_id: "some_integration_id_or_other",
unique_id: "a_login_id"
)
Or you could do it the boring way by just adding a login from their user
details page, but I'm not sure how to update the SIS ID and integration
ID from there.
Change-Id: I290bced84432a4776a9c20efbaeb26aeb7e18638
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/200805
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Tested-by: Jenkins
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: Jonathan Fenton <jfenton@instructure.com>
2019-07-09 04:38:12 +08:00
|
|
|
def sort_by_student_field
|
2020-01-21 07:03:09 +08:00
|
|
|
if ["name", "sortable_name"].include?(@sort_by) || !pseudonym_sort_field
|
Add more gradebook sort options
flag=new_gradebook_sort_options
closes TALLY-210
Test plan:
- Have a course using new gradebook
- Have several students with pseudonyms (i.e., logins; see below)
- Have at least one pseudonym-less student
- Have a mechanism to filter students (section or student group)
- Enable the feature:
- Open the Settings page for your root account and allow the
"Additional Sort Options for New Gradebook" feature
- Open the Settings page for your course and enable the above setting
for the course
- Open new Gradebook
- In the student column header menu, the "Sort by" item should now show
several sort fields and (separately) a sort order
- Check that the sort fields work as expected:
- (Note that you will need to use the "Secondary info" menu item to
show the relevant info field under users' names; selecting a sort
option will not automatically change the secondary info to match)
- "Name" should sort by the user's (sortable) name
- "SIS ID" should sort by the SIS user ID on the user's account
- "Integration ID" should sort by the account's integration ID
- "Login ID" should sort by the user's login name
- "A-Z" and "Z-A" should switch between ascending and descending
sort order for the selected sort field
- In all cases, students with no value for the selected field (e.g., a
student with no login ID) should appear at the bottom of the list,
regardless of the selected sort order
- Check that filtering by section or group still works as expected
- Selecting a specific filter, as well as removing the filter, should
respect the sort field and order
- Turn OFF the feature flag for the course
- Go back to New Gradebook
- Check that the sort menu has returned to its previous state, with
only "A-Z" and "Z-A" options that sort by name
- (If you were sorting by a different criterion when you had the flag
enabled, said criterion will initially still be in effect, but
adjusting the sort order will bounce it back to sorting by name)
APPENDIX: adding pseudonyms
To create a pseudonym for a student in a Rails console:
> user = <a student>
> user.pseudonyms.create!(
account: user.account,
sis_user_id: "some_sis_id_or_other",
integration_id: "some_integration_id_or_other",
unique_id: "a_login_id"
)
Or you could do it the boring way by just adding a login from their user
details page, but I'm not sure how to update the SIS ID and integration
ID from there.
Change-Id: I290bced84432a4776a9c20efbaeb26aeb7e18638
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/200805
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Tested-by: Jenkins
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: Jonathan Fenton <jfenton@instructure.com>
2019-07-09 04:38:12 +08:00
|
|
|
sort_by_student_name
|
|
|
|
else
|
|
|
|
sort_by_pseudonym_field
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-17 06:37:46 +08:00
|
|
|
def sort_by_student_name
|
2017-06-28 06:37:54 +08:00
|
|
|
students.
|
2018-08-07 23:13:18 +08:00
|
|
|
order(Arel.sql("enrollments.type = 'StudentViewEnrollment'")).
|
2017-06-23 08:17:41 +08:00
|
|
|
order_by_sortable_name(direction: @direction.to_sym).
|
|
|
|
pluck(:id).
|
|
|
|
uniq
|
2017-06-17 06:37:46 +08:00
|
|
|
end
|
|
|
|
|
Add more gradebook sort options
flag=new_gradebook_sort_options
closes TALLY-210
Test plan:
- Have a course using new gradebook
- Have several students with pseudonyms (i.e., logins; see below)
- Have at least one pseudonym-less student
- Have a mechanism to filter students (section or student group)
- Enable the feature:
- Open the Settings page for your root account and allow the
"Additional Sort Options for New Gradebook" feature
- Open the Settings page for your course and enable the above setting
for the course
- Open new Gradebook
- In the student column header menu, the "Sort by" item should now show
several sort fields and (separately) a sort order
- Check that the sort fields work as expected:
- (Note that you will need to use the "Secondary info" menu item to
show the relevant info field under users' names; selecting a sort
option will not automatically change the secondary info to match)
- "Name" should sort by the user's (sortable) name
- "SIS ID" should sort by the SIS user ID on the user's account
- "Integration ID" should sort by the account's integration ID
- "Login ID" should sort by the user's login name
- "A-Z" and "Z-A" should switch between ascending and descending
sort order for the selected sort field
- In all cases, students with no value for the selected field (e.g., a
student with no login ID) should appear at the bottom of the list,
regardless of the selected sort order
- Check that filtering by section or group still works as expected
- Selecting a specific filter, as well as removing the filter, should
respect the sort field and order
- Turn OFF the feature flag for the course
- Go back to New Gradebook
- Check that the sort menu has returned to its previous state, with
only "A-Z" and "Z-A" options that sort by name
- (If you were sorting by a different criterion when you had the flag
enabled, said criterion will initially still be in effect, but
adjusting the sort order will bounce it back to sorting by name)
APPENDIX: adding pseudonyms
To create a pseudonym for a student in a Rails console:
> user = <a student>
> user.pseudonyms.create!(
account: user.account,
sis_user_id: "some_sis_id_or_other",
integration_id: "some_integration_id_or_other",
unique_id: "a_login_id"
)
Or you could do it the boring way by just adding a login from their user
details page, but I'm not sure how to update the SIS ID and integration
ID from there.
Change-Id: I290bced84432a4776a9c20efbaeb26aeb7e18638
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/200805
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Tested-by: Jenkins
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: Jonathan Fenton <jfenton@instructure.com>
2019-07-09 04:38:12 +08:00
|
|
|
def sort_by_pseudonym_field
|
2020-01-21 07:03:09 +08:00
|
|
|
sort_column = Pseudonym.best_unicode_collation_key("pseudonyms.#{pseudonym_sort_field}")
|
Add more gradebook sort options
flag=new_gradebook_sort_options
closes TALLY-210
Test plan:
- Have a course using new gradebook
- Have several students with pseudonyms (i.e., logins; see below)
- Have at least one pseudonym-less student
- Have a mechanism to filter students (section or student group)
- Enable the feature:
- Open the Settings page for your root account and allow the
"Additional Sort Options for New Gradebook" feature
- Open the Settings page for your course and enable the above setting
for the course
- Open new Gradebook
- In the student column header menu, the "Sort by" item should now show
several sort fields and (separately) a sort order
- Check that the sort fields work as expected:
- (Note that you will need to use the "Secondary info" menu item to
show the relevant info field under users' names; selecting a sort
option will not automatically change the secondary info to match)
- "Name" should sort by the user's (sortable) name
- "SIS ID" should sort by the SIS user ID on the user's account
- "Integration ID" should sort by the account's integration ID
- "Login ID" should sort by the user's login name
- "A-Z" and "Z-A" should switch between ascending and descending
sort order for the selected sort field
- In all cases, students with no value for the selected field (e.g., a
student with no login ID) should appear at the bottom of the list,
regardless of the selected sort order
- Check that filtering by section or group still works as expected
- Selecting a specific filter, as well as removing the filter, should
respect the sort field and order
- Turn OFF the feature flag for the course
- Go back to New Gradebook
- Check that the sort menu has returned to its previous state, with
only "A-Z" and "Z-A" options that sort by name
- (If you were sorting by a different criterion when you had the flag
enabled, said criterion will initially still be in effect, but
adjusting the sort order will bounce it back to sorting by name)
APPENDIX: adding pseudonyms
To create a pseudonym for a student in a Rails console:
> user = <a student>
> user.pseudonyms.create!(
account: user.account,
sis_user_id: "some_sis_id_or_other",
integration_id: "some_integration_id_or_other",
unique_id: "a_login_id"
)
Or you could do it the boring way by just adding a login from their user
details page, but I'm not sure how to update the SIS ID and integration
ID from there.
Change-Id: I290bced84432a4776a9c20efbaeb26aeb7e18638
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/200805
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Tested-by: Jenkins
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: Jonathan Fenton <jfenton@instructure.com>
2019-07-09 04:38:12 +08:00
|
|
|
|
|
|
|
students.joins("LEFT JOIN #{Pseudonym.quoted_table_name} ON pseudonyms.user_id=users.id AND
|
|
|
|
pseudonyms.workflow_state <> 'deleted'").
|
|
|
|
order(Arel.sql("#{sort_column} #{sort_direction} NULLS LAST")).
|
|
|
|
order(Arel.sql("pseudonyms.id IS NULL")).
|
|
|
|
order(Arel.sql("users.id #{sort_direction}")).
|
|
|
|
pluck(:id).
|
|
|
|
uniq
|
|
|
|
end
|
|
|
|
|
2020-01-21 07:03:09 +08:00
|
|
|
def pseudonym_sort_field
|
|
|
|
# The sort keys integration_id and sis_user_id map to columns in Pseudonym,
|
|
|
|
# while login_id needs to be changed to unique_id
|
|
|
|
{
|
|
|
|
"login_id" => "unique_id",
|
|
|
|
"sis_user_id" => "sis_user_id",
|
|
|
|
"integration_id" => "integration_id"
|
|
|
|
}.with_indifferent_access[@sort_by]
|
|
|
|
end
|
|
|
|
|
2017-06-17 06:37:46 +08:00
|
|
|
def sort_by_assignment_grade(assignment_id)
|
2017-06-28 06:37:54 +08:00
|
|
|
students.
|
2017-11-08 22:45:57 +08:00
|
|
|
joins("LEFT JOIN #{Submission.quoted_table_name} ON submissions.user_id=users.id AND
|
2018-01-05 07:18:35 +08:00
|
|
|
submissions.workflow_state<>'deleted' AND
|
2018-02-21 07:42:16 +08:00
|
|
|
submissions.assignment_id=#{Submission.connection.quote(assignment_id)}").
|
2018-08-07 23:13:18 +08:00
|
|
|
order(Arel.sql("enrollments.type = 'StudentViewEnrollment'")).
|
|
|
|
order(Arel.sql("submissions.score #{sort_direction} NULLS LAST")).
|
|
|
|
order(Arel.sql("submissions.id IS NULL")).
|
2017-06-28 06:37:54 +08:00
|
|
|
order_by_sortable_name(direction: @direction.to_sym).
|
|
|
|
pluck(:id).
|
2017-06-17 06:37:46 +08:00
|
|
|
uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
def sort_by_assignment_missing(assignment_id)
|
2017-06-28 06:37:54 +08:00
|
|
|
sort_user_ids(Submission.missing.where(assignment_id: assignment_id))
|
2017-06-17 06:37:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def sort_by_assignment_late(assignment_id)
|
2017-06-28 06:37:54 +08:00
|
|
|
sort_user_ids(Submission.late.where(assignment_id: assignment_id))
|
2017-06-17 06:37:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def sort_by_total_grade
|
2018-01-05 07:18:35 +08:00
|
|
|
grading_period_id ? sort_by_scores(:grading_period, grading_period_id) : sort_by_scores(:total_grade)
|
|
|
|
end
|
2018-01-03 06:10:33 +08:00
|
|
|
|
2018-01-05 07:18:35 +08:00
|
|
|
def sort_by_assignment_group(assignment_group_id)
|
|
|
|
sort_by_scores(:assignment_group, assignment_group_id)
|
2017-06-28 06:37:54 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def all_user_ids
|
|
|
|
@all_user_ids ||= students.order_by_sortable_name(direction: @direction.to_sym).pluck(:id).uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
def all_user_ids_index
|
|
|
|
@all_user_ids_index ||= index_user_ids(all_user_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def fake_user_ids
|
|
|
|
student_enrollments_scope.where(type: "StudentViewEnrollment").pluck(:user_id).uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted_fake_user_ids
|
|
|
|
@sorted_fake_user_ids ||= sort_using_index(fake_user_ids, all_user_ids_index)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted_real_user_ids
|
|
|
|
@sorted_real_user_ids ||= sort_using_index(all_user_ids - sorted_fake_user_ids, all_user_ids_index)
|
|
|
|
end
|
|
|
|
|
|
|
|
def real_user_ids_from_submissions(submissions)
|
|
|
|
submissions.where(user_id: sorted_real_user_ids).pluck(:user_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted_real_user_ids_from_submissions(submissions)
|
|
|
|
sort_using_index(real_user_ids_from_submissions(submissions), all_user_ids_index)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sort_user_ids(submissions)
|
|
|
|
sorted_real_user_ids_from_submissions(submissions).concat(sorted_real_user_ids, sorted_fake_user_ids).uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_user_ids(user_ids)
|
|
|
|
user_ids_index = {}
|
|
|
|
# Traverse the array once and cache all indexes so we don't incur traversal costs at the end
|
|
|
|
user_ids.each_with_index { |item, idx| user_ids_index[item] = idx }
|
|
|
|
user_ids_index
|
|
|
|
end
|
|
|
|
|
|
|
|
def sort_using_index(user_ids, user_ids_index)
|
|
|
|
user_ids.sort_by { |item| user_ids_index[item] }
|
2017-06-17 06:37:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def student_enrollments_scope
|
|
|
|
workflow_states = [:active, :invited]
|
|
|
|
workflow_states << :inactive if @include_inactive
|
2018-06-21 22:30:25 +08:00
|
|
|
workflow_states << :completed if @include_concluded || @course.completed?
|
2017-06-17 06:37:46 +08:00
|
|
|
student_enrollments = @course.enrollments.where(
|
|
|
|
workflow_state: workflow_states,
|
|
|
|
type: [:StudentEnrollment, :StudentViewEnrollment]
|
|
|
|
)
|
|
|
|
|
2018-01-10 23:58:39 +08:00
|
|
|
section_ids = section_id ? [section_id] : nil
|
|
|
|
@course.apply_enrollment_visibility(student_enrollments, @user, section_ids, include: workflow_states)
|
2017-06-17 06:37:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def students
|
2019-08-01 04:42:41 +08:00
|
|
|
# Because of AR internals (https://github.com/rails/rails/issues/32598),
|
|
|
|
# we avoid using Arel left_joins here so that sort_by_scores will have
|
|
|
|
# Enrollment defined.
|
|
|
|
students = User.
|
|
|
|
joins("LEFT JOIN #{Enrollment.quoted_table_name} ON enrollments.user_id=users.id").
|
|
|
|
merge(student_enrollments_scope)
|
2019-02-12 05:53:58 +08:00
|
|
|
|
|
|
|
if student_group_id.present?
|
|
|
|
students.joins(group_memberships: :group).
|
|
|
|
where(group_memberships: {group: student_group_id, workflow_state: :accepted})
|
|
|
|
else
|
|
|
|
students
|
|
|
|
end
|
2017-06-17 06:37:46 +08:00
|
|
|
end
|
|
|
|
|
2018-01-05 07:18:35 +08:00
|
|
|
def sort_by_scores(type = :total_grade, id = nil)
|
|
|
|
score_scope = if type == :assignment_group
|
2018-02-21 07:42:16 +08:00
|
|
|
"scores.assignment_group_id=#{Score.connection.quote(id)}"
|
2018-01-05 07:18:35 +08:00
|
|
|
elsif type == :grading_period
|
2018-02-21 07:42:16 +08:00
|
|
|
"scores.grading_period_id=#{Score.connection.quote(id)}"
|
2018-01-05 07:18:35 +08:00
|
|
|
else
|
|
|
|
"scores.course_score IS TRUE"
|
|
|
|
end
|
|
|
|
|
2019-08-01 04:42:41 +08:00
|
|
|
# Without doing the score conditions in the join, we lose data. For
|
|
|
|
# example, we might lose concluded enrollments who don't have a Score.
|
|
|
|
students.joins("LEFT JOIN #{Score.quoted_table_name} ON scores.enrollment_id=enrollments.id AND
|
2018-01-05 07:18:35 +08:00
|
|
|
scores.workflow_state='active' AND #{score_scope}").
|
2018-08-07 23:13:18 +08:00
|
|
|
order(Arel.sql("enrollments.type = 'StudentViewEnrollment'")).
|
|
|
|
order(Arel.sql("scores.unposted_current_score #{sort_direction} NULLS LAST")).
|
2018-01-05 07:18:35 +08:00
|
|
|
order_by_sortable_name(direction: @direction.to_sym).
|
|
|
|
pluck(:id).uniq
|
|
|
|
end
|
|
|
|
|
2017-06-17 06:37:46 +08:00
|
|
|
def sort_direction
|
|
|
|
@direction == "ascending" ? :asc : :desc
|
|
|
|
end
|
|
|
|
|
|
|
|
def grading_period_id
|
|
|
|
return nil unless @course.grading_periods?
|
|
|
|
return nil if @selected_grading_period_id == "0"
|
|
|
|
|
|
|
|
if @selected_grading_period_id.nil? || @selected_grading_period_id == "null"
|
|
|
|
GradingPeriod.current_period_for(@course)&.id
|
|
|
|
else
|
|
|
|
@selected_grading_period_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def section_id
|
2019-02-12 05:53:58 +08:00
|
|
|
return nil if @selected_section_id.nil? || @selected_section_id == "null" || @selected_section_id == "0"
|
2017-06-17 06:37:46 +08:00
|
|
|
@selected_section_id
|
|
|
|
end
|
2019-02-12 05:53:58 +08:00
|
|
|
|
|
|
|
def student_group_id
|
|
|
|
return nil if @selected_student_group_id.nil? || ["0", "null"].include?(@selected_student_group_id)
|
2019-08-16 00:54:33 +08:00
|
|
|
Group.active.exists?(id: @selected_student_group_id) ? @selected_student_group_id : nil
|
2019-02-12 05:53:58 +08:00
|
|
|
end
|
2017-06-17 06:37:46 +08:00
|
|
|
end
|