package models import ( "time" "git.golem15.com/golem15/summercms/modules/lagoon" ) // DefinitionTheme is the fixed theme key of the one sitemap definition of an // application (D-11). The theme column stays so the table matches PHP; the // import commands write this key whatever the PHP theme was. const DefinitionTheme = "default" // Definition is a sitemap definition stored on golem15_sitemap_definitions, // the PHP Golem15\Sitemap\Models\Definition. Data holds the items as JSON // text (PHP $jsonable data). type Definition struct { ID uint `gorm:"column:id;primaryKey"` Theme *string `gorm:"column:theme"` Data lagoon.Jsonable[DefinitionItems] `gorm:"column:data"` CreatedAt *time.Time `gorm:"column:created_at"` UpdatedAt *time.Time `gorm:"column:updated_at"` } func (Definition) TableName() string { return "golem15_sitemap_definitions" } // MorphName is the PHP class string of the model. func (Definition) MorphName() string { return `Golem15\Sitemap\Models\Definition` } // Fillable is exactly theme and data, the PHP $fillable with $guarded = ['*'] // (MassAssignmentTest). func (Definition) Fillable() []string { return []string{"theme", "data"} } // Rules is empty: the PHP model validated nothing. The admin form checks // each item row's reference against its type. func (Definition) Rules() map[string]string { return map[string]string{} } // Items returns the stored items. func (d Definition) Items() []DefinitionItem { return d.Data.Get() } // SetItems stores items as the definition's data. func (d *Definition) SetItems(items []DefinitionItem) { d.Data = lagoon.Jsonable[DefinitionItems]{Data: DefinitionItems(items), Valid: true} } func init() { Register(Definition{}) }