| Class | BlogService |
| In: |
vendor/plugins/services/lib/blog_service.rb
|
| Parent: | BaseService |
This service requires DataService to work. It provides blogging functions that simplify accessing blog data.
Creates a new blog. This should be done when a user registers. NOTE! This method should NOT be used to create blog posts! This is for creating actual blogs.
# File vendor/plugins/services/lib/blog_service.rb, line 52
52: def self.createBlog(title, description, creator, owner)
53: DataService.createDataGroup(DGROUP_BLOG, nil, title, description, nil, creator, owner, nil)
54: end
Creates a new comment on a blog post
FIXME: This function’s signature needs to be changed to be more sane.
# File vendor/plugins/services/lib/blog_service.rb, line 104
104: def self.createBlogComment(postID, creator, username, commentContent)
105: commentsGrouping = DataService.findDataGrouping(DGROUP_COMMENTS, :parent, postID, :first)
106: post_meta = DataService.getDataGroupMetadata(commentsGrouping.groupingid)
107: owner = post_meta[:owner]
108: if creator == ANONYMOUS
109: commentid = DataService.createData(DTYPE_COMMENT, :string, commentContent, { :creatorapp => @serviceUUID, :grouping => commentsGrouping.groupingid, :creator => creator, :owner => owner })
110: # add the extra meta stuff
111: DataService.modifyDataItem(commentid, :object, { :username => username, :user => nil, :loggedin => false })
112: else
113: DataService.createData(DTYPE_COMMENT, :string, commentContent, { :creatorapp => @serviceUUID, :grouping => commentsGrouping.groupingid, :creator => creator, :owner => owner })
114: end
115: end
Creates a new blog post within the blog specified. Blogs are specified by their GroupingID.
FIXME: Make this method’s signature more sane.
# File vendor/plugins/services/lib/blog_service.rb, line 60
60: def self.createBlogPost(blogID, creator, postTitle, postDescription, postContent, readPermissions, writePermissions)
61: # The owner is retrieved from the blog itself.
62: blog_meta = DataService.getDataGroupMetadata(blogID)
63: owner = blog_meta[:owner]
64: postID = DataService.createData(DTYPE_POST, :string, postContent, { :creatorapp => @serviceUUID, :creator => creator, :grouping => blogID, :owner => owner, :title => postTitle, :description => postDescription })
65: # now create comments group
66: commentsID = DataService.createDataGroup(DGROUP_COMMENTS, nil, postTitle, postDescription, nil, creator, owner, postID)
67: read_perms = DataService.getPermissions(postID, :read)
68: write_perms = DataService.getPermissions(postID, :write)
69: DataService.setDefaultPermissions(commentsID, :read, read_perms)
70: DataService.setDefaultPermissions(commentsID, :write, write_perms)
71: end
Deletes a blog post by its dataID
# File vendor/plugins/services/lib/blog_service.rb, line 95
95: def self.deleteBlogPost(postID)
96: DataService.deleteDataItem(postID)
97: comments = DataService.findDataGrouping(DGROUP_COMMENTS, :parent, postID, :first)
98: DataService.deleteDataGroup(comments.groupingid)
99: end
Edits a post based on its postID.
# File vendor/plugins/services/lib/blog_service.rb, line 74
74: def self.editBlogPost(postID, postTitle, postDescription, postContent, readPermissions, writePermissions)
75: if DataService.doesDataItemExist?(postID)
76: DataService.modifyDataItem(postID, :string, postContent)
77: DataService.modifyDataItemMetadata(postID, :title, postTitle)
78: DataService.modifyDataItemMetadata(postID, :description, postDescription)
79: # modify the comments grouping
80: comments = DataService.findDataGrouping(DGROUP_COMMENTS, :parent, postID, :first)
81: DataService.modifyDataGroupMetadata(comments.groupingid, :title, postTitle)
82: DataService.modifyDataGroupMetadata(comments.groupingid, :description, postDescription)
83: return true
84: else
85: return false
86: end
87: end
Returns all of the comments for blog post specified in postID. The postID is retrieved from a particular post’s dataid. Returns a hash that looks like this:
{ :content => "Comment Content", :user => "UUID", :username => "Username if anonymous", :loggedin => true }
# File vendor/plugins/services/lib/blog_service.rb, line 33
33: def self.getBlogComments(postID)
34: post = DataService.findDataGrouping(DGROUP_COMMENTS, :parent, postID, :first)
35: cgroups = DataService.getDataGroupItems(post.groupingid, DTYPE_COMMENT, :asc)
36: comments = Array.new
37: cgroups.each do |cgroup|
38: if cgroup.objectdata != nil
39: cxtrameta = YAML::load(cgroup.objectdata)
40: comment = { :content => cgroup.stringdata, :user => ANONYMOUS, :username => cxtrameta[:username], :loggedin => false }
41: else
42: comment = { :content => cgroup.stringdata, :user => cgroup.creator, :loggedin => true }
43: end
44: comments << comment
45: end
46: return comments
47: end
Returns a hash of the blog’s metadata; see DataService.getGroupMetadata. blogID is the groupingID of the blog
# File vendor/plugins/services/lib/blog_service.rb, line 119
119: def self.getBlogMetadata(blogID)
120: return DataService.getDataGroupMetadata(blogID)
121: end
Returns a blog post by its dataID
# File vendor/plugins/services/lib/blog_service.rb, line 90
90: def self.getBlogPost(postID)
91: return DataService.getData(postID, :string)
92: end
Returns all of the blog posts for user/group specified in owner. The concept of ownership is as follows. Generally, MacroDeck would be the creator of every blog, but we could in theory have one made by an administrator. But, the user who uses the blog will always own it. Previously, this function looked for it by the creator, which would be incorrect.
# File vendor/plugins/services/lib/blog_service.rb, line 21
21: def self.getBlogPosts(owner)
22: blog = DataService.findDataGrouping(DGROUP_BLOG, :owner, owner, :first)
23: blogposts = DataService.getDataGroupItems(blog.groupingid, DTYPE_POST)
24: return blogposts
25: end
Returns the UUID of the blog of a user/group. If for some reason a user has more than one blog, it’ll return the first blog in the database. This should not happen, and therefore we don’t care.
# File vendor/plugins/services/lib/blog_service.rb, line 131
131: def self.getBlogUUID(userOrGroupUUID)
132: blog = DataService.findDataGrouping(DGROUP_BLOG, :owner, userOrGroupUUID, :first)
133: if blog != nil
134: return blog.groupingid
135: else
136: return nil
137: end
138: end
# File vendor/plugins/services/lib/blog_service.rb, line 140
140: def self.getCommentsUUID(postID)
141: post = DataService.findDataGrouping(DGROUP_COMMENTS, :parent, postID, :first)
142: return post.groupingid
143: end