Beispiel #1
0
func (h *Home) Get() error {
	//get posts by Created datetime desc order
	cnt, err := models.CountByExample(&models.Post{})
	if err != nil {
		return err
	}

	pager := h.SetPaginator(setting.PostCountPerPage, cnt)
	posts, err := models.FindPosts(setting.PostCountPerPage, pager.Offset())
	if err != nil {
		return err
	}

	h.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	h.setCategories(&cats)
	h.Data["SortSlug"] = ""
	h.Data["CategorySlug"] = "home"

	//new best posts
	var newBestPosts []models.Post
	h.setNewBestPosts(&newBestPosts)

	//most replys posts
	var mostReplysPosts []models.Post
	h.setMostReplysPosts(&mostReplysPosts)
	h.setSidebarBuilletinInfo()

	return h.Render("post/home.html", h.Data)
}
Beispiel #2
0
//Topic Home Page
func (this *Topic) Get() error {
	//check topic slug
	slug := this.Params().Get(":slug")
	topic, err := models.GetTopicBySlug(slug)
	if err != nil {
		return err
	}

	//get topic category
	var category models.Category
	err = models.GetById(topic.CategoryId, &category)
	if err != nil {
		return err
	}

	//get posts by topic
	cnt, err := models.CountByExample(&models.Post{TopicId: topic.Id})
	if err != nil {
		return err
	}

	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	posts, err := models.FindPosts(setting.PostCountPerPage, pager.Offset())
	if err != nil {
		return err
	}

	this.Data["Posts"] = posts
	this.Data["Topic"] = &topic
	this.Data["Category"] = &category

	//check whether added it into favorite list
	var hasFavorite bool
	if this.IsLogin {
		hasFavorite, _ = models.HasUserFollowTopic(int64(this.User.Id), topic.Id)
	}
	this.Data["HasFavorite"] = hasFavorite

	//new best post
	var newBestPosts []models.Post
	this.setNewBestPostsOfTopic(&newBestPosts, topic)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPostsOfTopic(&mostReplysPosts, topic)
	this.setSidebarBuilletinInfo()
	return this.Render("post/topic.html", this.Data)
}