require "active_record" ## # This class is used for getting the comments from the wordpress database # # == Examples: # User.find(1).comments # The above will find the user with id of 1 and retrieve all of the comments they have ever made # Post.find(1).comments # The above will find the post with id of 1 and retrieve all of the comments from that post # Comment.find(1) # The above will find the comment with id of 1 # # == Inherited methods # [find id] Retrieves the comment with the sepcified id # [all] Retrieves all of the comments in the database # # == Database Keys # [comment_ID alias: id] The comments id # [comment_post_ID alias: post.id] # The post id where the comment was posted # Comment.find(1).post # The above returns the Post that the comment belongs to # [comment_author] The name of the auther (could be stored in user.name, User#name) # [comment_author_email] The email of the author (could be stored in user.email, User#email) # [comment_author_url] The url of the author (could be stored in user.url, User#url) # [comment_author_IP] The ip of the author # [comment_date] The date the comment was posted # [comment_date_gmt] The date the comment was posted in gmt/utc time # [comment_content alias: Comment#content] The content of the comment # [comment_karma] The comment karma # [comment_approved] If the comment has been approved or not # [comment_agent] The agent of the comment # [comment_type] The type of comment # [comment_parent] The parent comment id if any # [user_id] # The user id of the author (0 if not registered user) # Comment.find(1).user # The above returns the User that posted the comment if user_id isn't 0 class Comment < ActiveRecord::Base set_table_name :wp_comments set_primary_key :comment_ID belongs_to :page_post belongs_to :user validates_presence_of :comment_post_ID before_create :set_default_values ## # Grab the content of the selected comment def content comment_content end ## # Set the content of the selected comment def content= new_content self.comment_content = new_content end private def set_default_values t = Time.now self.comment_date = t self.comment_date_gmt = t.gmtime end end