예제 #1
0
파일: post.go 프로젝트: trigrass2/wego
func (this *Navs) Get() error {
	sortSlug := this.Params().Get(":sortSlug")

	cnt, err := models.CountByExample(&models.Post{})
	if err != nil {
		return err
	}

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

	this.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	this.setCategories(&cats)
	this.Data["SortSlug"] = sortSlug
	this.Data["CategorySlug"] = "home"
	//new best posts
	var newBestPosts []models.Post
	this.setNewBestPosts(&newBestPosts)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPosts(&mostReplysPosts)
	this.setSidebarBuilletinInfo()
	return this.Render("post/home.html", this.Data)
}
예제 #2
0
파일: post.go 프로젝트: trigrass2/wego
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)
}
예제 #3
0
파일: post.go 프로젝트: trigrass2/wego
//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)
}
예제 #4
0
파일: post.go 프로젝트: trigrass2/wego
//Get the posts by category
func (this *Category) Get() error {
	//check category slug
	slug := this.Params().Get(":slug")
	cat, err := models.GetCategoryBySlug(slug)
	if err != nil {
		return err
	}

	//get posts by category slug, order by Created desc
	cnt, err := models.CountByExample(&models.Post{CategoryId: cat.Id})
	if err != nil {
		return err
	}

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

	this.Data["Category"] = cat
	this.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	this.setCategories(&cats)
	var topics []models.Topic
	this.setTopicsOfCategory(&topics, cat)
	this.Data["CategorySlug"] = cat.Slug
	this.Data["SortSlug"] = ""
	var newBestPosts []models.Post
	this.setNewBestPostsOfCategory(&newBestPosts, cat)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPostsOfCategory(&mostReplysPosts, cat)
	this.setSidebarBuilletinInfo()

	return this.Render("post/home.html", this.Data)
}