<commit_before>class PersonCourse < ActiveRecord::Base

  belongs_to :person, :dependent => :destroy
  belongs_to :course, :dependent => :destroy
  has_many :events, :as => :eventable, :dependent => :destroy
  has_one :enrolment_event,   :as => :eventable, :class_name => "Event", :conditions => {:transition => :start}
  has_one :application_event, :as => :eventable, :class_name => "Event", :conditions => {:transition => :create}
  has_one :complete_event,    :as => :eventable, :class_name => "Event", :conditions => {:transition => :complete}

  after_save do |person_course|
    if person_course.application_date_changed? and person_course.application_date_was == nil
      person_course.events.create(:event_date => person_course.application_date, :transition => :create)
    end
    if person_course.enrolment_date_changed? and person_course.enrolment_date_was == nil
      person_course.events.create(:event_date => person_course.enrolment_date, :transition => :start)
    end
    if person_course.end_date_changed? and person_course.end_date_was == nil
      person_course.events.create(:event_date => person_course.end_date, :transition => :complete)
    end
  end

  def icon_url
    "events/course.png"
  end

  def title(tr)
    case tr
      when :create   then "Course Application"
      when :start    then "Course Enrolment"
      when :complete then "Course Complete" # TODO: distinguish between complete, w/d, incomplete etc
    end
  end

  def body
    course.name
  end

end<commit_msg>Include courses in XMLised person_courses<commit_after>class PersonCourse < ActiveRecord::Base

  delegate :code, :to => :course

  belongs_to :person, :dependent => :destroy
  belongs_to :course, :dependent => :destroy
  has_many :events, :as => :eventable, :dependent => :destroy
  has_one :enrolment_event,   :as => :eventable, :class_name => "Event", :conditions => {:transition => :start}
  has_one :application_event, :as => :eventable, :class_name => "Event", :conditions => {:transition => :create}
  has_one :complete_event,    :as => :eventable, :class_name => "Event", :conditions => {:transition => :complete}

  after_save do |person_course|
    if person_course.application_date_changed? and person_course.application_date_was == nil
      person_course.events.create(:event_date => person_course.application_date, :transition => :create)
    end
    if person_course.enrolment_date_changed? and person_course.enrolment_date_was == nil
      person_course.events.create(:event_date => person_course.enrolment_date, :transition => :start)
    end
    if person_course.end_date_changed? and person_course.end_date_was == nil
      person_course.events.create(:event_date => person_course.end_date, :transition => :complete)
    end
  end

  def icon_url
    "events/course.png"
  end

  def title(tr)
    case tr
      when :create   then "Course Application"
      when :start    then "Course Enrolment"
      when :complete then "Course Complete" # TODO: distinguish between complete, w/d, incomplete etc
    end
  end

  def body
    course.name
  end

  def to_xml(options = {})
    super({:include => :course}.merge(options))
  end

end
{'fraction_non_alphanumeric': 0.1157495256166983, 'fraction_numerical': 0.0, 'mean_word_length': 4.351945854483925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '4410605', 'n_tokens_mistral': 981, 'n_tokens_neox': 957, 'n_words': 242}