Class: Course

Inherits:
ApplicationRecord show all
Includes:
CourseComponentsConcern, DuplicationConcern, LessonPlanConcern, SearchConcern, TimeZoneConcern
Defined in:
app/models/course.rb

Defined Under Namespace

Modules: AchievementConditionalConcern, AchievementsAbilityComponent, ActivityFeedsConcern, AnnouncementsAbilityComponent, AnnouncementsHelper, AssessmentConditionalConcern, AssessmentsAbilityComponent, ClosingReminderConcern, ConditionsAbilityComponent, ControllerHelper, CourseAbilityComponent, CourseComponentsConcern, CourseUserAbilityComponent, Discussion, DiscussionsAbilityComponent, DuplicationAbilityComponent, DuplicationConcern, ExperiencePointsDisbursementAbilityComponent, ExperiencePointsRecordsAbilityComponent, ForumParticipationConcern, ForumsAbilityComponent, GroupsAbilityComponent, GroupsHelper, LeaderboardsHelper, LessonPlan, LessonPlanAbilityComponent, LessonPlanConcern, LevelsAbilityComponent, LevelsConcern, MaterialsAbilityComponent, ObjectDuplicationsHelper, OpeningReminderConcern, ReminderServiceConcern, SearchConcern, StatisticsAbilityComponent, StatisticsHelper, SurveysAbilityComponent, UsersBreadcrumbConcern, UsersControllerManagementConcern, UsersHelper, VideosAbilityComponent, VirtualClassroomsAbilityComponent, VirtualClassroomsHelper Classes: Achievement, AchievementNotifier, AchievementsComponent, Announcement, AnnouncementNotifier, AnnouncementsComponent, AnnouncementsController, Assessment, AssessmentNotifier, AssessmentsComponent, ComponentController, Condition, ConditionsController, ConsolidatedOpeningReminderNotifier, Controller, ControllerComponentHost, CourseOwnerPreloadService, CourseUserPreloadService, CoursesController, DuplicationComponent, DuplicationJob, DuplicationsController, EnrolRequest, EnrolRequestsController, ExperiencePointsComponent, ExperiencePointsRecord, ExperiencePointsRecordsController, Forum, ForumsComponent, Group, GroupManagerPreloadService, GroupUser, GroupsComponent, GroupsController, LeaderboardComponent, LeaderboardsController, LessonPlanComponent, Level, LevelNotifier, LevelsComponent, LevelsController, Mailer, Material, MaterialsComponent, ModelComponentHost, Notification, ObjectDuplicationJob, ObjectDuplicationsController, QuestionAssessment, Registration, Settings, SettingsComponent, StatisticsComponent, StatisticsController, Survey, SurveyComponent, UserAchievement, UserInvitation, UserInvitationService, UserInvitationsController, UserNotificationsController, UserRegistrationService, UserRegistrationsController, UsersComponent, UsersController, Video, VideoNotifier, VideosComponent, VirtualClassroom, VirtualClassroomsComponent, VirtualClassroomsController

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TimeZoneConcern

#time_zone

Methods included from CourseComponentsConcern

#available_components, #disableable_components

Methods included from CourseComponentQueryConcern

#available_components, #disableable_components, #enabled_components, #enabled_components_keys=, #set_component_enabled_boolean, #set_component_enabled_boolean!, #undisableable_components, #user_enabled_components

Methods included from DuplicationConcern

#course_duplicable?, #disabled_cherrypickable_types, #duplication_manifest, #initialize_duplicate, #objects_duplicable?

Methods included from LessonPlanConcern

#grouped_lesson_plan_items_with_milestones

Class Method Details

.use_relative_model_naming?Boolean

Returns:

  • (Boolean)

92
93
94
# File 'app/models/course.rb', line 92

def self.use_relative_model_naming?
  true
end

Instance Method Details

#advance_start_at_durationActiveSupport::Duration

This is the max time span that the student can access a future assignment. Used in self directed mode, which will allow students to access course contents in advance before they have started.

Returns:

  • (ActiveSupport::Duration)

130
131
132
# File 'app/models/course.rb', line 130

def advance_start_at_duration
  settings(:course).advance_start_at_duration || 0
end

#advance_start_at_duration=(time) ⇒ Object


134
135
136
# File 'app/models/course.rb', line 134

def advance_start_at_duration=(time)
  settings(:course).advance_start_at_duration = time
end

#advance_start_at_duration_days=(value) ⇒ Object

Convert the days to time duration and store it.


139
140
141
142
143
144
145
146
# File 'app/models/course.rb', line 139

def advance_start_at_duration_days=(value)
  value = if value.present? && value.to_i > 0
            value.to_i.days
          else
            nil
          end
  settings(:course).advance_start_at_duration = value
end

#code_registration_enabled?Boolean

Returns:

  • (Boolean)

101
102
103
# File 'app/models/course.rb', line 101

def code_registration_enabled?
  registration_key.present?
end

#containing_userObject

Selects all the courses with user as one of its members


76
77
78
# File 'app/models/course.rb', line 76

scope :containing_user, (lambda do |user|
  joins(:course_users).where('course_users.user_id = ?', user.id)
end)

#default_video_tabCourse::Video::Tab

Returns the first video tab in this course. Usually this will be the default video tab created automatically, but may vary according to settings.

Returns:


153
154
155
# File 'app/models/course.rb', line 153

def default_video_tab
  video_tabs.first
end

#generate_registration_keyObject

Generates a registration key for use with the course.


97
98
99
# File 'app/models/course.rb', line 97

def generate_registration_key
  self.registration_key = 'C' + SecureRandom.base64(8)
end

#root_folderCourse::Material::Folder

Returns the root folder of the course.

Returns:


107
108
109
110
111
112
113
# File 'app/models/course.rb', line 107

def root_folder
  if new_record?
    material_folders.find(&:root?) || (raise ActiveRecord::RecordNotFound)
  else
    material_folders.find_by!(parent: nil)
  end
end

#root_folder?Boolean

Test if the course has a root folder.

Returns:

  • (Boolean)

    True if there is a root folder, otherwise false.


117
118
119
120
121
122
123
# File 'app/models/course.rb', line 117

def root_folder?
  if new_record?
    material_folders.find(&:root?).present?
  else
    material_folders.find_by(parent: nil).present?
  end
end

#show_public_test_cases_outputObject

TODO: Need to replace this with an assessment settings adapter in future Course setting to enable public test cases output


159
160
161
# File 'app/models/course.rb', line 159

def show_public_test_cases_output
  settings(:course_assessments_component).show_public_test_cases_output
end

#show_public_test_cases_output=(option) ⇒ Object


163
164
165
166
# File 'app/models/course.rb', line 163

def show_public_test_cases_output=(option)
  option = ActiveRecord::Type::Boolean.new.cast(option)
  settings(:course_assessments_component).show_public_test_cases_output = option
end

#show_stdout_and_stderrObject


168
169
170
# File 'app/models/course.rb', line 168

def show_stdout_and_stderr
  settings(:course_assessments_component).show_stdout_and_stderr
end

#show_stdout_and_stderr=(option) ⇒ Object


172
173
174
175
# File 'app/models/course.rb', line 172

def show_stdout_and_stderr=(option)
  option = ActiveRecord::Type::Boolean.new.cast(option)
  settings(:course_assessments_component).show_stdout_and_stderr = option
end