Files
sm-bm-plugin/models/course.go
Jakub Zych 71b848a376 Adopt SummerCMS v0.1.1 admin features
Datepickers on native time.Time / lagoon.Date fields, file uploads on
materials, readings and class sessions managed from the course form
(course_id made nullable).
2026-10-03 06:03:34 +02:00

78 lines
2.7 KiB
Go

// Code generated by summer make. DO NOT EDIT.
package models
import (
"time"
"gorm.io/gorm"
)
// Course forms, the values of Course.Form.
const (
FormWyklad = "wyklad"
FormCwiczenia = "cwiczenia"
FormKonwersatorium = "konwersatorium"
FormSeminarium = "seminarium"
FormInne = "inne"
)
// CourseForms lists the allowed Course.Form values.
var CourseForms = []string{FormWyklad, FormCwiczenia, FormKonwersatorium, FormSeminarium, FormInne}
// Course is one przedmiot of the programme in one form (a lecture and its
// tutorial are two courses).
type Course struct {
ID uint `gorm:"column:id;primaryKey"`
Code *string `gorm:"column:code"`
Name string `gorm:"column:name"`
Form string `gorm:"column:form"`
Lecturer *string `gorm:"column:lecturer"`
Semester int `gorm:"column:semester"`
ECTS *float64 `gorm:"column:ects"`
Assessment *string `gorm:"column:assessment"`
// ElectiveGroup marks alternatives ("do wyboru"): courses that share a
// value are options of one choice, such as "specjalnosc".
ElectiveGroup *string `gorm:"column:elective_group"`
Description *string `gorm:"column:description"`
SyllabusURL *string `gorm:"column:syllabus_url"`
SortOrder int `gorm:"column:sort_order"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
// Readings and Sessions are the hasMany relations the course form's
// relation managers edit.
Readings []Reading `gorm:"foreignKey:CourseID"`
Sessions []ClassSession `gorm:"foreignKey:CourseID"`
}
// TableName is the plugin table.
func (Course) TableName() string { return "jz_bm_courses" }
// Fillable lists the columns mass assignment may set.
func (Course) Fillable() []string {
return []string{"code", "name", "form", "lecturer", "semester", "ects", "assessment", "elective_group", "description", "syllabus_url", "sort_order"}
}
// Rules are checked by the admin API on every save.
func (Course) Rules() map[string]string {
return map[string]string{
"code": "nullable|max:50",
"name": "required|max:255",
"form": "required|in:wyklad,cwiczenia,konwersatorium,seminarium,inne",
"lecturer": "nullable|max:255",
"semester": "required|integer|between:1,4",
"ects": "nullable|numeric|between:0,60",
"assessment": "nullable|max:100",
"elective_group": "nullable|max:100",
"syllabus_url": "nullable|max:2048",
"sort_order": "nullable|integer",
}
}
// BeforeSave stores NULL for empty optional text.
func (c *Course) BeforeSave(*gorm.DB) error {
blank(&c.Code, &c.Lecturer, &c.Assessment, &c.ElectiveGroup, &c.Description, &c.SyllabusURL)
return nil
}