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

Instance Method Details

#course_department(course) ⇒ LUSI::API::Course::CourseDepartment

Returns the major department for the course

Parameters:

  • course (LUSI::API::Course::Module)

    the LUSI course module

Returns:

  • (LUSI::API::Course::CourseDepartment)

    the major department



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

Parameters:

  • course (LUSI::API::VLE::VLESpace)

    the course

  • cohort (LUSI::API::Course::Cohort)

    the course cohort

  • offset (Integer, Symbol) (defaults to: nil)

    a numerical year offset or symbol specifying the number of years from the current course year for which the ID is required. This allows generation of course IDs for years other than the specified course. The following symbols are shorthand for numeric offsets:

    :previous, :rollover - equivalent to offset: -1
    :next                - equivalent to offset: 1
    

Returns:

  • (String)

    the Moodle course ID



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

Parameters:

  • course (LUSI::API::Course::Module) (defaults to: nil)

    the LUSI course module

Returns:

  • (LUSI::API::Organisation::Unit)

    the organisation unit instance of the major department for the course



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

#departmentsObject

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

Parameters:

  • value (String)

    the field value

  • length (Integer) (defaults to: nil)

    the maximum field length

  • empty (Object, nil) (defaults to: nil)

    the value to return if the field value is nil or empty

Returns:

  • (String)

    the formatted field value



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

Parameters:

  • year (LUSI::API::Calendar::Year)

    the course year

  • course (LUSI::API::VLE::VLESpace)

    the course

  • cohort (LUSI::API::Course::Cohort)

    the course cohort

Returns:

  • (Array<LUSI::API::Course::StaffModuleEnrolment>)

    the course instructors



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_rolesHash<String, LUSI::API::Person::StaffCourseRole>

Returns course instructor roles from the :staff_course_roles lookup table

Returns:

  • (Hash<String, LUSI::API::Person::StaffCourseRole>)

    the roles



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

Parameters:

  • usernames (Array<String>)

    the instructor usernames

Returns:

  • (String, nil)

    the 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

Parameters:

  • course (LUSI::API::Course::Module) (defaults to: nil)

    the LUSI course module

Returns:

  • (Array<LUSI::API::Organisation::Unit>)

    the organisation units in furthest-to-nearest order [institution, faculty, dept]



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