blog_post.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package fetdata
  2. import (
  3. "html/template"
  4. "time"
  5. "golang-fave/engine/utils"
  6. "golang-fave/engine/wrapper"
  7. )
  8. type BlogPost struct {
  9. wrap *wrapper.Wrapper
  10. object *utils.MySql_blog_post
  11. user *User
  12. category *BlogCategory
  13. }
  14. func (this *BlogPost) load() *BlogPost {
  15. return this
  16. }
  17. func (this *BlogPost) Id() int {
  18. if this == nil {
  19. return 0
  20. }
  21. return this.object.A_id
  22. }
  23. func (this *BlogPost) User() *User {
  24. if this == nil {
  25. return nil
  26. }
  27. if this.user != nil {
  28. return this.user
  29. }
  30. this.user = (&User{wrap: this.wrap}).load()
  31. this.user.loadById(this.object.A_user)
  32. return this.user
  33. }
  34. func (this *BlogPost) Name() string {
  35. if this == nil {
  36. return ""
  37. }
  38. return this.object.A_name
  39. }
  40. func (this *BlogPost) Alias() string {
  41. if this == nil {
  42. return ""
  43. }
  44. return this.object.A_alias
  45. }
  46. func (this *BlogPost) Category() *BlogCategory {
  47. if this == nil {
  48. return nil
  49. }
  50. if this.category != nil {
  51. return this.category
  52. }
  53. this.category = (&BlogCategory{wrap: this.wrap}).load(nil)
  54. this.category.loadById(this.object.A_category)
  55. return this.category
  56. }
  57. func (this *BlogPost) Briefly() template.HTML {
  58. if this == nil {
  59. return template.HTML("")
  60. }
  61. return template.HTML(this.object.A_briefly)
  62. }
  63. func (this *BlogPost) Content() template.HTML {
  64. if this == nil {
  65. return template.HTML("")
  66. }
  67. return template.HTML(this.object.A_content)
  68. }
  69. func (this *BlogPost) DateTimeUnix() int {
  70. if this == nil {
  71. return 0
  72. }
  73. return this.object.A_datetime
  74. }
  75. func (this *BlogPost) DateTimeFormat(format string) string {
  76. if this == nil {
  77. return ""
  78. }
  79. return time.Unix(int64(this.object.A_datetime), 0).Format(format)
  80. }
  81. func (this *BlogPost) Active() bool {
  82. if this == nil {
  83. return false
  84. }
  85. return this.object.A_active > 0
  86. }
  87. func (this *BlogPost) Permalink() string {
  88. if this == nil {
  89. return ""
  90. }
  91. return "/blog/" + this.object.A_alias + "/"
  92. }