當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Model.NewComment函數代碼示例

本文整理匯總了Golang中Model.NewComment函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewComment函數的具體用法?Golang NewComment怎麽用?Golang NewComment使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewComment函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: PostComment

// 發表評論。入topics_reply庫,更新topics和topics_ex庫
// objname 注冊的評論對象名
func PostComment(objid, objtype, uid int, content string, objname string) error {
	comment := model.NewComment()
	comment.Objid = objid
	comment.Objtype = objtype
	comment.Uid = uid
	comment.Content = content

	// TODO:評論樓層怎麽處理,避免衝突?最後的樓層信息保存在內存中?

	// 暫時隻是從數據庫中取出最後的評論樓層
	stringBuilder := util.NewBuffer()
	stringBuilder.Append("objid=").AppendInt(objid).Append(" AND objtype=").AppendInt(objtype)
	tmpCmt, err := model.NewComment().Where(stringBuilder.String()).Order("ctime DESC").Find()
	if err != nil {
		logger.Errorln("post comment service error:", err)
		return err
	} else {
		comment.Floor = tmpCmt.Floor + 1
	}
	// 入評論庫
	cid, err := comment.Insert()
	if err != nil {
		logger.Errorln("post comment service error:", err)
		return err
	}
	// 回調,不關心處理結果(有些對象可能不需要回調)
	if commenter, ok := commenters[objname]; ok {
		logger.Debugf("評論[objid:%d] [objtype:%d] [uid:%d] 成功,通知被評論者更新", objid, objtype, uid)
		go commenter.UpdateComment(cid, objid, uid, time.Now().Format("2006-01-02 15:04:05"))
	}

	return nil
}
開發者ID:jimmykuu,項目名稱:studygolang,代碼行數:35,代碼來源:comment.go

示例2: PostComment

// 發表評論(或回複)。
// objid 注冊的評論對象
// uid 評論人
func PostComment(uid, objid int, form url.Values) (*model.Comment, error) {
	comment := model.NewComment()
	comment.Objid = objid
	objtype := util.MustInt(form.Get("objtype"))
	comment.Objtype = objtype
	comment.Uid = uid
	comment.Content = form.Get("content")

	// TODO:評論樓層怎麽處理,避免衝突?最後的樓層信息保存在內存中?

	// 暫時隻是從數據庫中取出最後的評論樓層
	stringBuilder := util.NewBuffer()
	stringBuilder.Append("objid=").AppendInt(objid).Append(" AND objtype=").AppendInt(objtype)
	tmpCmt, err := model.NewComment().Where(stringBuilder.String()).Order("ctime DESC").Find()
	if err != nil {
		logger.Errorln("post comment service error:", err)
		return nil, err
	} else {
		comment.Floor = tmpCmt.Floor + 1
	}
	// 入評論庫
	cid, err := comment.Insert()
	if err != nil {
		logger.Errorln("post comment service error:", err)
		return nil, err
	}
	comment.Cid = cid
	comment.Ctime = util.TimeNow()
	decodeCmtContent(comment)

	// 回調,不關心處理結果(有些對象可能不需要回調)
	if commenter, ok := commenters[objtype]; ok {
		logger.Debugf("評論[objid:%d] [objtype:%d] [uid:%d] 成功,通知被評論者更新", objid, objtype, uid)
		go commenter.UpdateComment(cid, objid, uid, time.Now().Format("2006-01-02 15:04:05"))
	}

	// 發評論,活躍度+5
	go IncUserWeight("uid="+strconv.Itoa(uid), 5)

	// 給被評論對象所有者發係統消息
	ext := map[string]interface{}{
		"objid":   objid,
		"objtype": objtype,
		"cid":     cid,
		"uid":     uid,
	}
	go SendSystemMsgTo(0, objtype, ext)

	// @某人 發係統消息
	go SendSysMsgAtUids(form.Get("uid"), ext)
	go SendSysMsgAtUsernames(form.Get("usernames"), ext)

	return comment, nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:57,代碼來源:comment.go

示例3: FindTopicByTid

// 獲得帖子詳細信息(包括詳細回複)
// 為了避免轉換,tid傳string類型
func FindTopicByTid(tid string) (topicMap map[string]interface{}, replies []map[string]interface{}, err error) {
	condition := "tid=" + tid
	// 帖子信息
	topic := model.NewTopic()
	err = topic.Where(condition).Find()
	if err != nil {
		logger.Errorln("topic service FindTopicByTid Error:", err)
		return
	}
	// 帖子不存在
	if topic.Tid == 0 {
		return
	}
	topicMap = make(map[string]interface{})
	util.Struct2Map(topicMap, topic)
	topicEx := model.NewTopicEx()
	err = topicEx.Where(condition).Find()
	if err != nil {
		logger.Errorln("topic service FindTopicByTid Error:", err)
		return
	}
	if topicEx.Tid == 0 {
		return
	}
	util.Struct2Map(topicMap, topicEx)
	// 節點名字
	topicMap["node"] = model.GetNodeName(topic.Nid)

	// 回複信息(評論)
	replyList, err := model.NewComment().Where("objid=" + tid + " and objtype=" + strconv.Itoa(model.TYPE_TOPIC)).FindAll()
	if err != nil {
		logger.Errorln("topic service FindTopicByTid Error:", err)
		return
	}

	replyNum := len(replyList)
	uids := make(map[int]int, replyNum+1)
	uids[topic.Uid] = topic.Uid
	for _, reply := range replyList {
		uids[reply.Uid] = reply.Uid
	}

	// 獲得用戶信息
	userMap := getUserInfos(uids)
	topicMap["user"] = userMap[topic.Uid]

	// 有人回複
	if topic.Lastreplyuid != 0 {
		topicMap["lastreplyusername"] = userMap[topicMap["lastreplyuid"].(int)].Username
	}

	replies = make([]map[string]interface{}, 0, replyNum)
	for _, reply := range replyList {
		tmpMap := make(map[string]interface{})
		util.Struct2Map(tmpMap, reply)
		tmpMap["user"] = userMap[reply.Uid]
		replies = append(replies, tmpMap)
	}
	return
}
開發者ID:sndnvaps,項目名稱:studygolang,代碼行數:62,代碼來源:topic.go

示例4: FindObjComments

// 獲得某個對象的所有評論
// owner: 被評論對象屬主
// TODO:分頁暫不做
func FindObjComments(objid, objtype string, owner, lastCommentUid int /*, page, pageNum int*/) (comments []map[string]interface{}, ownerUser, lastReplyUser *model.User) {
	commentList, err := model.NewComment().Where("objid=" + objid + " and objtype=" + objtype).FindAll()
	if err != nil {
		logger.Errorln("comment service FindObjComments Error:", err)
		return
	}

	commentNum := len(commentList)
	uids := make(map[int]int, commentNum+1)
	uids[owner] = owner
	// 避免某些情況下最後回複人沒在回複列表中
	uids[lastCommentUid] = lastCommentUid
	for _, comment := range commentList {
		uids[comment.Uid] = comment.Uid
	}

	// 獲得用戶信息
	userMap := getUserInfos(uids)
	ownerUser = userMap[owner]
	if lastCommentUid != 0 {
		lastReplyUser = userMap[lastCommentUid]
	}
	comments = make([]map[string]interface{}, 0, commentNum)
	for _, comment := range commentList {
		tmpMap := make(map[string]interface{})
		util.Struct2Map(tmpMap, comment)
		tmpMap["content"] = decodeCmtContent(comment)
		tmpMap["user"] = userMap[comment.Uid]
		comments = append(comments, tmpMap)
	}
	return
}
開發者ID:BillyMC,項目名稱:studygolang,代碼行數:35,代碼來源:comment.go

示例5: FindObjComments

// 獲得某個對象的所有評論
// owner: 被評論對象屬主
// TODO:分頁暫不做
func FindObjComments(objid, objtype string, owner, lastCommentUid int /*, page, pageNum int*/) (comments []map[string]interface{}, ownerUser, lastReplyUser *model.User) {
	commentList, err := model.NewComment().Where("objid=" + objid + " and objtype=" + objtype).FindAll()
	if err != nil {
		logger.Errorln("comment service FindObjComments Error:", err)
		return
	}

	uids := util.Models2Intslice(commentList, "Uid")

	// 避免某些情況下最後回複人沒在回複列表中
	uids = append(uids, owner, lastCommentUid)

	// 獲得用戶信息
	userMap := GetUserInfos(uids)
	ownerUser = userMap[owner]
	if lastCommentUid != 0 {
		lastReplyUser = userMap[lastCommentUid]
	}
	comments = make([]map[string]interface{}, 0, len(commentList))
	for _, comment := range commentList {
		tmpMap := make(map[string]interface{})
		util.Struct2Map(tmpMap, comment)
		tmpMap["content"] = template.HTML(decodeCmtContent(comment))
		tmpMap["user"] = userMap[comment.Uid]
		comments = append(comments, tmpMap)
	}
	return
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:31,代碼來源:comment.go

示例6: CommentsTotal

// 某類型的評論總數
func CommentsTotal(objtype int) (total int) {
	total, err := model.NewComment().Where("objtype=" + strconv.Itoa(objtype)).Count()
	if err != nil {
		logger.Errorln("comment service CommentsTotal error:", err)
		return
	}
	return
}
開發者ID:BillyMC,項目名稱:studygolang,代碼行數:9,代碼來源:comment.go

示例7: FindRecentComments

// 獲得某人在某種類型最近的評論
func FindRecentComments(uid, objtype int) []*model.Comment {
	comments, err := model.NewComment().Where("uid=" + strconv.Itoa(uid) + " AND objtype=" + strconv.Itoa(objtype)).Order("ctime DESC").Limit("0, 5").FindAll()
	if err != nil {
		logger.Errorln("comment service FindRecentComments error:", err)
		return nil
	}
	return comments
}
開發者ID:BillyMC,項目名稱:studygolang,代碼行數:9,代碼來源:comment.go

示例8: ModifyComment

func ModifyComment(cid, content string) (errMsg string, err error) {
	err = model.NewComment().Set("content=?", content).Where("cid=" + cid).Update()
	if err != nil {
		logger.Errorf("更新評論內容 【%s】 失敗:%s\n", cid, err)
		errMsg = "對不起,服務器內部錯誤,請稍後再試!"
		return
	}

	return
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:10,代碼來源:comment.go

示例9: FindCommentsByIds

// 獲取多個評論信息
func FindCommentsByIds(cids []int) []*model.Comment {
	if len(cids) == 0 {
		return nil
	}
	inCids := util.Join(cids, ",")
	comments, err := model.NewComment().Where("cid in(" + inCids + ")").FindAll()
	if err != nil {
		logger.Errorln("comment service FindCommentsByIds error:", err)
		return nil
	}
	return comments
}
開發者ID:BillyMC,項目名稱:studygolang,代碼行數:13,代碼來源:comment.go

示例10: FindObjectComments

// 獲得某個對象的所有評論(新版)
// TODO:分頁暫不做
func FindObjectComments(objid, objtype string) (commentList []*model.Comment, err error) {
	commentList, err = model.NewComment().Where("objid=" + objid + " and objtype=" + objtype).FindAll()
	if err != nil {
		logger.Errorln("comment service FindObjectComments Error:", err)
	}

	for _, comment := range commentList {
		decodeCmtContent(comment)
	}

	return
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:14,代碼來源:comment.go

示例11: CommentsTotal

// 評論總數(objtype != -1 時,取某一類型的評論總數)
func CommentsTotal(objtype int) (total int) {
	var cond string
	if objtype != -1 {
		cond = "objtype=" + strconv.Itoa(objtype)
	}

	total, err := model.NewComment().Where(cond).Count()
	if err != nil {
		logger.Errorln("comment service CommentsTotal error:", err)
		return
	}
	return
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:14,代碼來源:comment.go

示例12: FindRecentComments

// 獲得最近的評論
// 如果 uid!=0,表示獲取某人的評論;
// 如果 objtype!=-1,表示獲取某類型的評論;
func FindRecentComments(uid, objtype int, limit string) []*model.Comment {
	cond := ""
	if uid != 0 {
		cond = "uid=" + strconv.Itoa(uid)
	}
	if objtype != -1 {
		if cond != "" {
			cond += " AND "
		}
		cond += "objtype=" + strconv.Itoa(objtype)
	}

	comments, err := model.NewComment().Where(cond).Order("cid DESC").Limit(limit).FindAll()
	if err != nil {
		logger.Errorln("comment service FindRecentComments error:", err)
		return nil
	}

	cmtMap := make(map[int][]*model.Comment, len(model.PathUrlMap))
	for _, comment := range comments {
		decodeCmtContent(comment)

		if _, ok := cmtMap[comment.Objtype]; !ok {
			cmtMap[comment.Objtype] = make([]*model.Comment, 0, 10)
		}

		cmtMap[comment.Objtype] = append(cmtMap[comment.Objtype], comment)
	}

	cmtObjs := []CommentObjecter{
		model.TYPE_TOPIC:    TopicComment{},
		model.TYPE_ARTICLE:  ArticleComment{},
		model.TYPE_RESOURCE: ResourceComment{},
		model.TYPE_WIKI:     nil,
		model.TYPE_PROJECT:  ProjectComment{},
	}
	for cmtType, cmts := range cmtMap {
		FillCommentObjs(cmts, cmtObjs[cmtType])
	}

	return comments
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:45,代碼來源:comment.go


注:本文中的Model.NewComment函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。