class LUSI::API::Enrolment::EnrolmentBase
The abstract base class for enrolment classes @abstract Subclasses must define the lusi_ws_* endpoint methods and additional attributes
Attributes
@!attribute [rw] enrolment_role
@return [LUSI::API::Enrolment::EnrolmentRole, nil] the role that members have against this enrolment
@!attribute [rw] identity
@return [LUSI::API::Enrolment::EnrolmentIdentity] the identity of the subject (person) of the enrolment
@!attribute [rw] is_current_enrolment
@return [Boolean, nil] true if the enrolment is current, false otherwise
@!attribute [rw] is_current_identity
@return [Boolean, nil] true if the member's identity is current, false otherwise
@!attribute [rw] username
@return [String, nil] the username of the subject (person) of the enrolment
Public Class Methods
Returns an array of instances matching the specified search criteria @param api [LUSI::API::Core::API] the LUSI
API
instance to use for searching @param lookup [LUSI::API::Core::Lookup::LookupService, nil] the lookup service for object resolution @param (see get_instance_params) @yield [obj] Passes the instance to the block
# File lib/lusi_api/enrolment.rb, line 84 def self.get_instance(api, lookup = nil, current_only: nil, **kwargs) current_only = current_only.nil? || current_only ? true : false if current_only # Filter nodes which have current enrolments and user identities filter = Proc.new do |node| LUSI::API::Core::XML.xml_boolean_at(node, 'xmlns:IsCurrentEnrolment', false) && LUSI::API::Core::XML.xml_boolean_at(node, 'xmlns:IsCurrentIdentity', false) end else filter = nil end params = self.get_instance_params(**kwargs) xml = api.call(self.lusi_ws_path, self.lusi_ws_endpoint, self.lusi_ws_method, **params) result = LUSI::API::Core::XML.xml(xml, "xmlns:#{self.lusi_ws_xml_root}", filter: filter) do |m| obj = self.new(m, lookup) yield(obj) if block_given? obj end # Return the array of instances result end
@see (LUSI::API::Core::Endpoint#lusi_ws_path
)
# File lib/lusi_api/enrolment.rb, line 128 def self.lusi_ws_path 'UserDetails' end
Initalises a new Enrolment
instance @param xml [Nokogiri::XML::Document, Nokogiri::XML::Node] the parsed XML root of the enrolment @param lookup [LUSI::API::Core::Lookup::LookupService, nil] the lookup service for object resolution @param enrolment_role
[LUSI::API::Enrolment::EnrolmentRole, nil] the default enrolment role @param identity [String, nil] the default user identity code @param is_current_enrolment
[Boolean, nil] the default current enrolment flag @param is_current_identity
[Boolean, nil] the default current identity flag @param username [String, nil] the default username @return [void]
# File lib/lusi_api/enrolment.rb, line 65 def initialize(xml = nil, lookup = nil, enrolment_role: nil, identity: nil, is_current_enrolment: nil, is_current_identity: nil, username: nil) is_current_enrolment = is_current_enrolment.nil? || is_current_enrolment ? true : false is_current_identity = is_current_identity.nil? || is_current_identity ? true : false @enrolment_role = EnrolmentRole.new(LUSI::API::Core::XML.xml_at(xml, 'xmlns:EnrolmentRole', enrolment_role), lookup) @identity = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Identity', identity) @is_current_enrolment = LUSI::API::Core::XML.xml_boolean_at(xml, 'xmlns:IsCurrentEnrolment', is_current_enrolment) @is_current_identity = LUSI::API::Core::XML.xml_boolean_at(xml, 'xmlns:IsCurrentIdentity', is_current_identity) @username = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Username', username) end
Protected Class Methods
Returns a hash of parameters for the LUSI
API
call. Subclasses may extend or override this method. @param active_vle_space_only [Boolean, nil] if true, restrict results to active VLE
spaces only @param asp_identity [String, nil] return instances matching the academically significant period (ASP) identity @param cohort_identity [String, nil] return instances matching the cohort identity @param course_identity [String, nil] return instances matching the course identity @param current_student_only [Boolean, nil] if true, restrict results to current students only @param department_identity [String, nil] return instances matching the department identity @param require_username [Boolean, nil] if true, include the student username, ignore students with no username @param year_identity (String, nil) return instances matching the year identity @return [Hash<String, String>] the parameters for the LUSI
API
call
# File lib/lusi_api/enrolment.rb, line 144 def self.get_instance_params(**kwargs) result = { ActiveVLESpaceOnly: kwargs.fetch(:active_vle_space_only, true) ? 'true' : 'false', ASPIdentity: kwargs.fetch(:asp_identity, ''), CohortIdentity: kwargs.fetch(:cohort_identity, ''), CourseIdentity: kwargs.fetch(:course_identity, ''), DepartmentIdentity: kwargs.fetch(:department_identity, ''), RequireUsername: kwargs.fetch(:require_username, true) ? 'true' : 'false', YearIdentity: kwargs.fetch(:year_identity, '') } if self.lusi_ws_endpoint == 'Student.asmx' result[:CurrentStudentOnly] = kwargs.fetch(:current_student_only, true) ? 'true' : 'false' end result end
Public Instance Methods
Returns the lookup indices supported by this enrolment type @return [Array<Symbol>] the supported lookup indices
# File lib/lusi_api/enrolment.rb, line 108 def lookup_indices [:identity, :role, :username] end
Returns the value to be used as a key for the specified lookup index @return [Object] the key value
# File lib/lusi_api/enrolment.rb, line 114 def lookup_key(index = nil) case index when :identity self.identity when :role self.enrolment_role ? self.enrolment_role.identity : nil when :username self.username else nil end end