Module: LUSIAlmaCourseLoader::Helpers
- Includes:
- LUSI::API::Core::Util
- Included in:
- Reader
- Defined in:
- lib/lusi_alma_course_loader/reader.rb
Overview
Methods for handling LUSI data
Constant Summary collapse
- COURSE_ID_OFFSETS =
Course ID year offsets
{ next: 1, previous: -1, rollover: -1 }.freeze
- INSTRUCTOR_ROLES =
LUSI instructor roles
{ 'administrative staff'.to_sym => true, 'co-course convenor'.to_sym => true, 'course convenor'.to_sym => true, 'partner administrative staff'.to_sym => true, 'partner course convenor'.to_sym => true, 'teaching staff (not timetabled)'.to_sym => true, 'teaching staff (timetabled)'.to_sym => true, }.freeze
Instance Method Summary collapse
-
#course_department(course) ⇒ LUSI::API::Course::CourseDepartment
Returns the major department for the course.
-
#course_id(course, cohort, offset = nil) ⇒ String
Returns the Moodle course ID for a given course/cohort.
-
#department(course = nil) ⇒ LUSI::API::Organisation::Unit
Returns the organisation unit for a course department.
-
#departments ⇒ Object
Returns the organisation units from LUSI.
-
#field(value, length = nil, empty = nil) ⇒ String
Returns a string row field trimmed to the specified length.
-
#instructor_enrolments(year, course, cohort) ⇒ Array<LUSI::API::Course::StaffModuleEnrolment>
Returns a list of instructor enrolments for the course/cohort.
-
#instructor_roles ⇒ Hash<String, LUSI::API::Person::StaffCourseRole>
Returns course instructor roles from the :staff_course_roles lookup table.
-
#instructor_usernames(usernames) ⇒ String?
Returns a comma-separated list of instructor usernames.
-
#org_units(course = nil) ⇒ Array<LUSI::API::Organisation::Unit>
Returns the ancestor organisation units of the course’s major department.
Instance Method Details
#course_department(course) ⇒ LUSI::API::Course::CourseDepartment
Returns the major department for the course
32 33 34 35 36 |
# File 'lib/lusi_alma_course_loader/reader.rb', line 32 def course_department(course) return nil unless course && course.course_departments # There should only be one major department course.course_departments.select(&:is_major_department)[0] end |
#course_id(course, cohort, offset = nil) ⇒ String
Returns the Moodle course ID for a given course/cohort
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lusi_alma_course_loader/reader.rb', line 49 def course_id(course, cohort, offset = nil) offset = COURSE_ID_OFFSETS[offset] || offset.to_i year = if offset != 0 # Get the year identity lusi_year_identity(course.lusi_year_id, offset: offset) else course.lusi_year_id end if course.space_type == 'SHARED' "lusi-#{course.lusi_vle_space_id}-#{year}" else c = course.vle_space_courses[0] "lusi-#{c.identity.course}-#{year}-#{c.identity.cohort}" end end |
#department(course = nil) ⇒ LUSI::API::Organisation::Unit
Returns the organisation unit for a course department
69 70 71 72 |
# File 'lib/lusi_alma_course_loader/reader.rb', line 69 def department(course = nil) dept = course_department(course) dept ? dept.org_unit : nil end |
#departments ⇒ Object
Returns the organisation units from LUSI
75 76 77 78 79 80 81 82 |
# File 'lib/lusi_alma_course_loader/reader.rb', line 75 def departments return @departments unless @departments.nil? organisation = LUSI::API::Organisation::Organisation.new organisation.load(@lusi_api, in_use_only: false) @departments = {} organisation.each(:department) { |o| @departments[o.talis_code] = o } @departments end |
#field(value, length = nil, empty = nil) ⇒ String
Returns a string row field trimmed to the specified length
90 91 92 93 |
# File 'lib/lusi_alma_course_loader/reader.rb', line 90 def field(value, length = nil, empty = nil) value = empty if value.nil? || value.empty? length && value ? value[0...length] : value end |
#instructor_enrolments(year, course, cohort) ⇒ Array<LUSI::API::Course::StaffModuleEnrolment>
Returns a list of instructor enrolments for the course/cohort
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/lusi_alma_course_loader/reader.rb', line 101 def instructor_enrolments(year, course, cohort) result = [] course.vle_space_courses.each do |c| enrolments = LUSI::API::Course::StaffModuleEnrolment.get_instance( @lusi_api, @lusi_lookup, active_vle_space_only: false, course_identity: c.identity.course, cohort_identity: c.identity.cohort, require_username: true, year_identity: c.identity.year ) e = enrolments.select do |e| @instructor_roles.key?(e.enrolment_role.identity) end result.concat(e) end result end |
#instructor_roles ⇒ Hash<String, LUSI::API::Person::StaffCourseRole>
Returns course instructor roles from the :staff_course_roles lookup table
122 123 124 125 126 127 128 |
# File 'lib/lusi_alma_course_loader/reader.rb', line 122 def instructor_roles roles = @lusi_lookup.service(:staff_course_role) return [] if roles.nil? roles.select do |_k, v| INSTRUCTOR_ROLES.include?(v.description.downcase.to_sym) end end |
#instructor_usernames(usernames) ⇒ String?
Returns a comma-separated list of instructor usernames
133 134 135 136 |
# File 'lib/lusi_alma_course_loader/reader.rb', line 133 def instructor_usernames(usernames) result = usernames.join(',') result.nil? || result.empty? ? nil : result end |
#org_units(course = nil) ⇒ Array<LUSI::API::Organisation::Unit>
Returns the ancestor organisation units of the course’s major department
142 143 144 145 146 147 148 149 150 |
# File 'lib/lusi_alma_course_loader/reader.rb', line 142 def org_units(course = nil) dept = department(course) result = [] until dept.nil? result.unshift(dept) dept = dept.parent end result end |