class Content < ActiveRecord::Base has_many :content_assignments has_many :asset_assignments has_many :assets, :through => :asset_assignments def self.find_entire_tree(builder=nil) # add something here to get the content, not the assignment to_fxml(:builder => builder, :skip_instruct => true) do |fxml| ContentAssignment.roots(:first, :conditions => {:content_id => self.id}).children.each do |child| child.content.to_fxml_content_tree(fxml) end end end def to_fxml_content_tree(builder=nil) # add something here to get the content, not the assignment to_fxml(:builder => builder, :skip_instruct => true) do |fxml| ContentAssignment.find(:first, :conditions => {:content_id => self.id}).children.each do |child| child.content.to_fxml_content_tree(fxml) end end end def desc @content_assignments = [] @procs = [] ContentAssignment.find(:first, :conditions => {:target_id => self.id}).descendants.each do |child| proc = Proc.new do |opts| opts[:builder].tag!('parent_id', child.parent.target_id) end @content_assignments.push(child) @procs.push(proc) end to_fxml(:child_proc => @procs) end def descendants(builder=nil) @children = [] @parent_ids = [] @contents = [] ContentAssignment.find(:first, :conditions => {:target_id => self.id}).self_and_descendants.each do |child| proc = Proc.new do |opts| opts[:builder].tag!('parent_id', child.source_id) end # CAN'T JUST PUSH THEM IN, THE ID's GET ALL SCREWED UP @children.push(child) @parent_ids.push(proc) end @contents = self.class.find(@children).to_fxml(:child_proc => @parent_ids) end def descendants2(builder=nil) @children = [] @parent_ids = [] @contents = [] @nodes = {} @tmp = [] ContentAssignment.find(:first, :conditions => {:target_id => self.id}).self_and_descendants.each do |child| proc = Proc.new do |opts| opts[:builder].tag!('parent_id', child.source_id) end # CAN'T JUST PUSH THEM IN, THE ID's GET ALL SCREWED UP @parent_ids.push(proc) if !@nodes[child.source_id] @nodes[child.source_id] = true @children.push(child) end end @contents = self.class.find(@children) @parent_ids.each do |node| if node end to_fxml(:child_proc => @parent_ids) end def to_xml_content_tree(builder=nil) # add something here to get the content, not the assignment to_xml(:builder => builder, :skip_instruct => true) do |xml| ContentAssignment.find(:first, :conditions => {:content_id => self.id}).children.each do |child| child.content.to_xml_content_tree(xml) end end end def parent @parent = ContentAssignment.find(:first, :conditions => {:content_id => self.id}).parent.content end end