MCPcopy Create free account
hub / github.com/codecombat/codecombat / getLevels

Method getLevels

app/models/Classroom.js:137–171  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

135 }
136
137 getLevels (options) {
138 // options: courseID, withoutLadderLevels, projectLevels, assessmentLevels, levelsCollection
139 // TODO: find a way to get the i18n in here so that level names can be translated (Courses don't include in their denormalized copy of levels)
140 if (options == null) { options = {} }
141 const Levels = require('collections/Levels')
142 const courses = this.get('courses')
143 if (!courses) { return new Levels() }
144 const levelObjects = []
145 for (const course of Array.from(courses)) {
146 if (options.courseID && (options.courseID !== course._id)) {
147 continue
148 }
149 if (options.levelsCollection) {
150 for (const level of Array.from(course.levels)) {
151 const matchedLevel = options.levelsCollection.findWhere({ original: level.original })
152 levelObjects.push((matchedLevel != null ? matchedLevel.attributes : undefined) || matchedLevel)
153 }
154 } else {
155 levelObjects.push(course.levels)
156 }
157 }
158 const levels = new Levels(_.flatten(levelObjects))
159 const language = __guard__(this.get('aceConfig'), x => x.language)
160 if (language) { levels.remove(levels.filter(level => level.get('primerLanguage') === language)) }
161 if (options.withoutLadderLevels) {
162 levels.remove(levels.filter(level => level.isLadder()))
163 }
164 if (options.projectLevels) {
165 levels.remove(levels.filter(level => level.get('shareable') !== 'project'))
166 }
167 if (options.assessmentLevels) {
168 levels.remove(levels.filter(level => !level.get('assessment')))
169 }
170 return levels
171 }
172
173 getLevelsByModules () {
174 const courseModuleLevelsMap = {}

Callers 2

getLevelsByModulesMethod · 0.95
statsForSessionsMethod · 0.95

Calls 4

filterMethod · 0.80
isLadderMethod · 0.80
__guard__Function · 0.70
getMethod · 0.45

Tested by

no test coverage detected