本文整理汇总了Golang中Model.NewOpenProject函数的典型用法代码示例。如果您正苦于以下问题:Golang NewOpenProject函数的具体用法?Golang NewOpenProject怎么用?Golang NewOpenProject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewOpenProject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdateLike
// 更新该项目的喜欢数
// objid:被喜欢对象id;num: 喜欢数(负数表示取消喜欢)
func (self ProjectLike) UpdateLike(objid, num int) {
// 更新喜欢数(TODO:暂时每次都更新表)
err := model.NewOpenProject().Where("id=?", objid).Increment("likenum", num)
if err != nil {
logger.Errorln("更新项目喜欢数失败:", err)
}
}
示例2: ProjectsTotal
// 开源项目总数
func ProjectsTotal() (total int) {
total, err := model.NewOpenProject().Count()
if err != nil {
logger.Errorln("project service ProjectsTotal error:", err)
}
return
}
示例3: UpdateProjectStatus
func UpdateProjectStatus(id, status int, username string) error {
if status < model.StatusNew || status > model.StatusOffline {
return errors.New("status is illegal")
}
logger.Infoln("UpdateProjectStatus by username:", username)
return model.NewOpenProject().Set("status=?", status).Where("id=?", id).Update()
}
示例4: UpdateComment
// 更新该项目的评论信息
// cid:评论id;objid:被评论对象id;uid:评论者;cmttime:评论时间
func (self ProjectComment) UpdateComment(cid, objid, uid int, cmttime string) {
id := strconv.Itoa(objid)
// 更新评论数(TODO:暂时每次都更新表)
err := model.NewOpenProject().Where("id="+id).Increment("cmtnum", 1)
if err != nil {
logger.Errorln("更新项目评论数失败:", err)
}
}
示例5: FindUserRecentProjects
// 获得某个用户最近发布的开源项目
func FindUserRecentProjects(username string) []*model.OpenProject {
projectList, err := model.NewOpenProject().Where("username=?", username).Limit("0,5").Order("ctime DESC").FindAll()
if err != nil {
logger.Errorln("project service FindUserRecentProjects error:", err)
return nil
}
return projectList
}
示例6: getProjectOwner
// 通过objid获得 project 的所有者
func getProjectOwner(id int) int {
project := model.NewOpenProject()
err := project.Where("id=" + strconv.Itoa(id)).Find()
if err != nil {
logger.Errorln("project service getProjectOwner Error:", err)
return 0
}
user := FindUserByUsername(project.Username)
return user.Uid
}
示例7: FindProjectsByIds
// 获取多个项目详细信息
func FindProjectsByIds(ids []int) []*model.OpenProject {
if len(ids) == 0 {
return nil
}
inIds := util.Join(ids, ",")
projects, err := model.NewOpenProject().Where("id in(" + inIds + ")").FindAll()
if err != nil {
logger.Errorln("project service FindProjectsByIds error:", err)
return nil
}
return projects
}
示例8: ProjectUriExists
func ProjectUriExists(uri string) bool {
project := model.NewOpenProject()
err := project.Where("uri=?", uri).Find("id")
if err != nil {
return false
}
if project.Id > 0 {
return true
}
return false
}
示例9: flush
// flush 将浏览数刷入数据库中
func (this *view) flush() {
this.locker.Lock()
defer this.locker.Unlock()
objid := strconv.Itoa(this.objid)
switch this.objtype {
case model.TYPE_TOPIC:
model.NewTopicEx().Where("tid="+objid).Increment("view", this.num)
case model.TYPE_ARTICLE:
model.NewArticle().Where("id="+objid).Increment("viewnum", this.num)
case model.TYPE_RESOURCE:
model.NewResourceEx().Where("id="+objid).Increment("viewnum", this.num)
case model.TYPE_PROJECT:
model.NewOpenProject().Where("id="+objid).Increment("viewnum", this.num)
}
this.num = 0
}
示例10: NewProjectHandler
// 新建项目
// uri: /project/new{json:(|.json)}
func NewProjectHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
name := req.PostFormValue("name")
// 请求新建项目页面
if name == "" || req.Method != "POST" || vars["json"] == "" {
project := model.NewOpenProject()
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/projects/new.html")
filter.SetData(req, map[string]interface{}{"project": project, "activeProjects": "active"})
return
}
user, _ := filter.CurrentUser(req)
err := service.PublishProject(user, req.PostForm)
if err != nil {
fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误!"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
示例11: FindProjects
// 获取开源项目列表(分页)
func FindProjects(lastId, limit string) []*model.OpenProject {
project := model.NewOpenProject()
query := "status IN(?,?)"
args := []interface{}{model.StatusNew, model.StatusOnline}
if lastId != "0" {
query += " AND id<?"
args = append(args, lastId)
}
projectList, err := project.Where(query, args...).Order("id DESC").Limit(limit).
FindAll()
if err != nil {
logger.Errorln("project service FindProjects Error:", err)
return nil
}
return projectList
}
示例12: FindProject
// 获取单个项目
func FindProject(uniq string) *model.OpenProject {
field := "id"
_, err := strconv.Atoi(uniq)
if err != nil {
field = "uri"
}
project := model.NewOpenProject()
err = project.Where(field+"=? AND status IN(?,?)", uniq, model.StatusNew, model.StatusOnline).Find()
if err != nil {
logger.Errorln("project service FindProject error:", err)
return nil
}
if project.Id == 0 {
return nil
}
return project
}
示例13: FindProjectByPage
// 获取开源项目列表(分页,后台用)
func FindProjectByPage(conds map[string]string, curPage, limit int) ([]*model.OpenProject, int) {
conditions := make([]string, 0, len(conds))
for k, v := range conds {
conditions = append(conditions, k+"="+v)
}
project := model.NewOpenProject()
limitStr := strconv.Itoa((curPage-1)*limit) + "," + strconv.Itoa(limit)
projectList, err := project.Where(strings.Join(conditions, " AND ")).Order("id DESC").Limit(limitStr).
FindAll()
if err != nil {
logger.Errorln("project service FindProjectByPage Error:", err)
return nil, 0
}
total, err := project.Count()
if err != nil {
logger.Errorln("project service FindProjectByPage COUNT Error:", err)
return nil, 0
}
return projectList, total
}
示例14: GenSitemap
//.........这里部分代码省略.........
little = 1
large = little + step
// 资源
resource := model.NewResource()
for {
sitemapFile := "sitemap_resource_" + strconv.Itoa(large) + ".xml"
resources, err := resource.Where("id BETWEEN ? AND ?", little, large).FindAll("id", "mtime")
little, large = large+1, little+step
if err != nil {
continue
}
if len(resources) == 0 {
break
}
data := map[string]interface{}{
"home": home,
"resources": resources,
}
if err = output(sitemapFile, data); err == nil {
sitemapFiles = append(sitemapFiles, sitemapFile)
}
}
little = 1
large = little + step
// 项目
project := model.NewOpenProject()
for {
sitemapFile := "sitemap_project_" + strconv.Itoa(large) + ".xml"
projects, err := project.Where("id BETWEEN ? AND ? AND status=?", little, large, model.StatusOnline).FindAll("id", "uri", "mtime")
little, large = large+1, little+step
if err != nil {
continue
}
if len(projects) == 0 {
break
}
data := map[string]interface{}{
"home": home,
"projects": projects,
}
if err = output(sitemapFile, data); err == nil {
sitemapFiles = append(sitemapFiles, sitemapFile)
}
}
little = 1
large = little + step
// wiki
wiki := model.NewWiki()
for {
sitemapFile := "sitemap_wiki_" + strconv.Itoa(large) + ".xml"
示例15: PublishProject
func PublishProject(user map[string]interface{}, form url.Values) (err error) {
id := form.Get("id")
isModify := id != ""
if !isModify && ProjectUriExists(form.Get("uri")) {
err = errors.New("uri存在")
return
}
username := user["username"].(string)
project := model.NewOpenProject()
if isModify {
err = project.Where("id=?", id).Find()
if err != nil {
logger.Errorln("Publish Project find error:", err)
return
}
isAdmin := false
if _, ok := user["isadmin"]; ok {
isAdmin = user["isadmin"].(bool)
}
if project.Username != username && !isAdmin {
err = NotModifyAuthorityErr
return
}
util.ConvertAssign(project, form)
} else {
util.ConvertAssign(project, form)
project.Username = username
project.Ctime = util.TimeNow()
}
project.Uri = strings.ToLower(project.Uri)
github := "github.com"
pos := strings.Index(project.Src, github)
if pos != -1 {
project.Repo = project.Src[pos+len(github)+1:]
}
if !isModify {
_, err = project.Insert()
} else {
err = project.Persist(project)
}
if err != nil {
logger.Errorln("Publish Project error:", err)
}
// 发布項目,活跃度+10
if uid, ok := user["uid"].(int); ok {
weight := 10
if isModify {
weight = 2
}
go IncUserWeight("uid="+strconv.Itoa(uid), weight)
}
return
}