reprogl
1package models2
3import (4"database/sql"5"errors"6"strconv"7"strings"8"time"9)
10
11var RecordNotFound = errors.New("models: no matching record found")12
13const (14DisabledComments = "d"15EnabledComments = "e"16)
17
18type ArticleBasePart struct {19ID int20Title string21Slug string22Text string23Preview string24CreatedAt time.Time25UpdatedAt time.Time26CategoryName string27CategorySlug string28Hidden bool29
30CommentsCount int31}
32
33type Article struct {34ArticleBasePart
35Description sql.NullString36FeaturedImage
37Tags TagList
38
39DisabledComments bool40RecentPostsID string41Views int42}
43
44type ArticleListItem struct {45ArticleBasePart
46FeaturedImage
47Tags TagList
48}
49
50type ArticleList []*ArticleListItem51
52type Category struct {53ID int54Name string55Slug string56LeftKey sql.NullInt6457RightKey sql.NullInt6458Depth int59}
60
61type CategoryList []*Category62
63type Tag struct {64ID int65Name string66Slug string67}
68
69type TagList []*Tag70
71type RecentPost struct {72Title string73Slug string74}
75
76type RecentPostList []*RecentPost77
78type ArticleForComment struct {79ID int80Slug string81Hidden bool82}
83
84func (cat *Category) HeaderLineDescription() string {85return "Записи из категории"86}
87
88func (cat *Category) HeaderLineText() string {89return cat.Name90}
91
92func (cat *Category) NameWithTreePrefix() string {93var prefix string94if cat.Depth > 1 {95prefix = strings.Repeat("..", cat.Depth-1)96}97
98return prefix + cat.Name99}
100
101func (tag *Tag) HeaderLineDescription() string {102return "Записи с отметкой"103}
104
105func (tag *Tag) HeaderLineText() string {106return tag.Name107}
108
109func (a *ArticleBasePart) HasPreview() bool {110return strings.Contains(a.Text, "<!-- cut -->")111}
112
113func (a *ArticleBasePart) IdString() string {114return strconv.Itoa(a.ID)115}
116
117func (a *ArticleBasePart) IsArticle() bool {118return true119}
120
121func (a *Article) DisabledCommentsFlag() (flag string) {122if a.DisabledComments {123flag = DisabledComments124} else {125flag = EnabledComments126}127
128return129}
130