예제 #1
0
// 顶部导航栏的话题列表。
// 如果用户已经登陆,则获取用户关注的话题,
// 如果未登陆则获取全站的最流行话题列表.
func getTopNavTopics(ctx *goku.HttpContext, user *models.User) {
	var topics []models.Topic
	topicLen := 35
	if user == nil {
		topics, _ = models.Topic_GetTops(1, topicLen)
	} else {
		tuser, _ := models.User_GetFollowTopics(user.Id, 1, topicLen, "link_count desc")
		if len(tuser) < topicLen {
			// 不够 topicLen 条,则合并
			tall, _ := models.Topic_GetTops(1, topicLen-len(tuser))
			topics = make([]models.Topic, 0, len(tall))
			tmp := map[string]bool{}
			for _, v := range tuser {
				tmp[v.Name] = true
			}
			topics = append(topics, tuser...)
			for _, v := range tall {
				if _, ok := tmp[v.Name]; !ok {
					topics = append(topics, v)
				}
			}
		} else {
			topics = tuser
		}
	}
	ctx.ViewData["TopNavTopics"] = topics
}
예제 #2
0
파일: base.go 프로젝트: yonglehou/ohlala
func init() {
	var err error
	topTopics, err = models.Topic_GetTops(1, 200)
	if err != nil {
		log.Fatalln("load top topics error:", err.Error())
	}
	lenTopTopics = len(topTopics)
}
예제 #3
0
파일: topic.go 프로젝트: yonglehou/ohlala
	"regexp"
	"strconv"
	"time"
)

/**
 * Controller: topic
 */
var _ = goku.Controller("topic").

	/**
	 * 话题列表页
	 */
	Get("index", func(ctx *goku.HttpContext) goku.ActionResulter {

		topics, _ := models.Topic_GetTops(1, 30)
		ctx.ViewData["TopTab"] = "topic"
		return ctx.View(models.Topic_ToVTopics(topics, ctx))

	}).

	/**
	 * 查看话题信息页
	 */
	Get("show", func(ctx *goku.HttpContext) goku.ActionResulter {

		ctx.ViewData["TopTab"] = "topic"
		topicName, _ := ctx.RouteData.Params["name"]
		topic, _ := models.Topic_GetByName(topicName)

		if topic == nil {