package models import ( "time" translate "git.golem15.com/golem15/sm-translate-plugin/models" "git.golem15.com/golem15/summercms/modules/lagoon" ) // Content is the stored question and answer list: the PHP $jsonable content, // one {question, answer} object per row. type Content = []map[string]any // FAQ is one FAQ in one locale, stored on golem15_faq_faqs: the PHP // Golem15\FAQ\Models\FAQ. A site keeps one row per locale under the same // slug, told apart by locale_id (the translate Locale). type FAQ struct { ID uint `gorm:"column:id;primaryKey"` Name string `gorm:"column:name"` Slug string `gorm:"column:slug"` LocaleID uint `gorm:"column:locale_id"` Locale *translate.Locale `gorm:"foreignKey:LocaleID" json:"-"` IsActive bool `gorm:"column:is_active"` Description *string `gorm:"column:description"` Content lagoon.Jsonable[Content] `gorm:"column:content"` CreatedAt *time.Time `gorm:"column:created_at"` UpdatedAt *time.Time `gorm:"column:updated_at"` } func (FAQ) TableName() string { return "golem15_faq_faqs" } // MorphName is the PHP class string of the model. func (FAQ) MorphName() string { return `Golem15\FAQ\Models\FAQ` } // Fillable is the list an admin save may set. The locale is set through the // locale relation field, which writes locale_id. func (FAQ) Fillable() []string { return []string{"name", "slug", "locale_id", "is_active", "description", "content"} } // Rules require a name and a slug. The locale is required too, but the admin // sets locale_id from the locale relation field after validation, so the // controller checks it once the row is written (a missing locale rolls the // save back). func (FAQ) Rules() map[string]string { return map[string]string{ "name": "required", "slug": "required", } } // Items returns the stored rows. func (f FAQ) Items() Content { return f.Content.Get() } func init() { Register(FAQ{}) }