Skip to content

Commit 21a3261

Browse files
committed
fix: add logic for total progress milestones to monitor for when teacher adds more lessons or quizes to class
1 parent 7ac2bb5 commit 21a3261

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

provider-middleware/kolibri.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@ func (ks *KolibriService) GetUsers(db *gorm.DB) ([]models.ImportUser, error) {
9999
**/
100100
func (ks *KolibriService) ImportCourses(db *gorm.DB) error { //add more to this:::
101101
log.Println("Importing channel and classroom courses from Kolibri")
102-
var courses []map[string]interface{}
102+
var courses []map[string]interface{} //modified to left join as quizzes only activate when teachers click 'START QUIZ'
103103
sql := `SELECT id, name, description, thumbnail, total_resource_count, root_id, 'channel' as course_type FROM content_channelmetadata
104104
UNION
105-
SELECT col.id, name, '' as description, '' as thumbnail, lesson.resource_count+exam.resource_count as total_resource_count, col.id as root_id, 'class' as course_type
105+
SELECT col.id, name, '' as description, '' as thumbnail, lesson.resource_count+COALESCE(exam.resource_count,0) as total_resource_count, col.id as root_id, 'class' as course_type
106106
FROM kolibriauth_collection col
107107
inner join (SELECT col.id, count(col.id) as resource_count
108108
FROM kolibriauth_collection col
109109
inner join lessons_lesson lesson on col.id = lesson.collection_id
110110
where kind = 'classroom'
111111
group by col.id
112112
) lesson on col.id = lesson.id
113-
inner join (SELECT exam.collection_id, count(exam.collection_id) as resource_count
113+
left join (SELECT exam.collection_id, count(exam.collection_id) as resource_count
114114
FROM kolibriauth_collection col
115115
inner join exams_exam exam on col.id = exam.collection_id
116116
where kind = 'classroom'
@@ -124,6 +124,9 @@ func (ks *KolibriService) ImportCourses(db *gorm.DB) error { //add more to this:
124124
for _, course := range courses {
125125
id := course["id"].(string)
126126
if db.Where("provider_platform_id = ? AND external_id = ?", ks.ProviderPlatformID, id).First(&models.Course{}).Error == nil {
127+
if course["thumbnail"].(string) == "" {
128+
updateTotalProgress(db, ks.ProviderPlatformID, course)
129+
}
127130
continue
128131
}
129132
prog := ks.IntoCourse(course)
@@ -135,6 +138,16 @@ func (ks *KolibriService) ImportCourses(db *gorm.DB) error { //add more to this:
135138
return nil
136139
}
137140

141+
func updateTotalProgress(db *gorm.DB, providerPlatformID uint, course map[string]interface{}) {
142+
id := course["id"].(string)
143+
totalResourceCount := course["total_resource_count"].(int64)
144+
if db.Where("provider_platform_id = ? AND external_id = ? AND total_progress_milestones = ?", providerPlatformID, id, totalResourceCount).First(&models.Course{}).Error != nil {
145+
if err := db.Table("courses as c").Where("provider_platform_id = ? AND external_id = ?", providerPlatformID, id).Update("total_progress_milestones", totalResourceCount).Error; err != nil {
146+
log.Errorln("error updating course total_progress_milestones in db, error is: ", err) //just logging the error if it occurs, logic will continue
147+
}
148+
}
149+
}
150+
138151
type milestonePO struct {
139152
course map[string]interface{}
140153
usersMap map[string]uint

0 commit comments

Comments
 (0)