<commit_before>#Node type for Courses

#Author: ajbudlon
#Date: 7/18/2008

class CourseNode < Node 
  belongs_to :course, :class_name => "Course", :foreign_key => "node_object_id"
  
  # Returns the table in which to locate Courses
  def self.table
    "courses"
  end

  # parameters:
  #   sortvar: valid strings - name, created_at, updated_at, directory_path
  #   sortorder: valid strings - asc, desc
  #   user_id: instructor id for Course
  #   parent_id: not used for this type of object
  
  # returns: list of CourseNodes based on query
  # the get method will return all courses meeting the criteria, but the method name is necessary due to polymorphism
  def self.get(sortvar = 'name',sortorder ='ASC',user_id = nil,show = nil, parent_id = nil)
    find(:all, :include => :course, :conditions => [getCourseQueryConditions(show, user_id), getCoursesManagedByUser(user_id)], :order => "courses.#{sortvar} #{sortorder}")
  end

  #get the query conditions for a public course
  def self.getCourseQueryConditions(show = nil, user_id = nil)
    this_user = User.find(user_id)

    if show
      if this_user.is_teaching_assistant? == false
        conditions = 'courses.instructor_id = ?'
      else
        conditions = 'courses.id in (?)'
      end
    else
      if this_user.is_teaching_assistant? == false
        conditions = '(courses.private = 0 or courses.instructor_id = ?)'
      else
        conditions = '(courses.private = 0 or courses.id in (?))'
      end
    end

    return conditions
  end

  #get the courses managed by the user
  def self.getCoursesManagedByUser(user_id = nil)
    this_user = User.find(user_id)

    if this_user.is_teaching_assistant? == false<commit_msg>add course_node_test.rb with renamed methods<commit_after>#Node type for Courses

#Author: ajbudlon
#Date: 7/18/2008

class CourseNode < Node 
  belongs_to :course, :class_name => "Course", :foreign_key => "node_object_id"
  
  # Returns the table in which to locate Courses
  def self.table
    "courses"
  end

  # parameters:
  #   sortvar: valid strings - name, created_at, updated_at, directory_path
  #   sortorder: valid strings - asc, desc
  #   user_id: instructor id for Course
  #   parent_id: not used for this type of object
  
  # returns: list of CourseNodes based on query
  # the get method will return all courses meeting the criteria, but the method name is necessary due to polymorphism
  def self.get(sortvar = 'name',sortorder ='ASC',user_id = nil,show = nil, parent_id = nil)
    find(:all, :include => :course, :conditions => [get_course_query_conditions(show, user_id), get_courses_managed_by_user(user_id)], :order => "courses.#{sortvar} #{sortorder}")
  end

  #get the query conditions for a public course
  def self.get_course_query_conditions(show = nil, user_id = nil)
    this_user = User.find(user_id)

    if show
      if this_user.is_teaching_assistant? == false
        conditions = 'courses.instructor_id = ?'
      else
        conditions = 'courses.id in (?)'
      end
    else
      if this_user.is_teaching_assistant? == false
        conditions = '(courses.private = 0 or courses.instructor_id = ?)'
      else
        conditions = '(courses.private = 0 or courses.id in (?))'
      end
    end

    return conditions
  end

  #get the courses managed by the user
  def self.get_courses_managed_by_user(user_id = nil)
    this_user = User.find(user_id)

    if this_user.is_teaching_assistant? == false
{'fraction_non_alphanumeric': 0.09486510008703221, 'fraction_numerical': 0.005221932114882507, 'mean_word_length': 3.443298969072165, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6168066', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1090, 'n_words': 329}