Module: Cms::Behaviors::Connecting::InstanceMethods

Defined in:
lib/cms/behaviors/connecting.rb

Instance Method Summary collapse

Instance Method Details

#connect_to_pageObject



59
60
61
62
63
64
65
66
67
# File 'lib/cms/behaviors/connecting.rb', line 59

def connect_to_page
  unless connect_to_page_id.blank? || connect_to_container.blank?
    #Note that we are setting connected_page so that page can look at that 
    #to determine if the page should be published            
    self.connected_page = Page.find(connect_to_page_id)
    connected_page.create_connector(self, connect_to_container)
  end
  true
end

#connected_page_countObject



43
44
45
# File 'lib/cms/behaviors/connecting.rb', line 43

def connected_page_count
  Page.connected_to(self).count
end

#connected_pagesObject



39
40
41
# File 'lib/cms/behaviors/connecting.rb', line 39

def connected_pages
  Page.connected_to(self)
end

#content_block_typeObject



47
48
49
# File 'lib/cms/behaviors/connecting.rb', line 47

def content_block_type
  self.class.content_block_type
end

#display_nameObject



51
52
53
# File 'lib/cms/behaviors/connecting.rb', line 51

def display_name
  self.class.display_name
end

#display_name_pluralObject



55
56
57
# File 'lib/cms/behaviors/connecting.rb', line 55

def display_name_plural
  self.class.display_name_plural
end

#update_connected_pagesObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cms/behaviors/connecting.rb', line 69

def update_connected_pages
  # If this is versioned, then we need make new versions of all the pages this is connected to
  #logger.info "updating connected pages -> #{self.inspect}"
  if self.class.versioned?

    #Get all the pages the previous version of this connectable was connected to
    Page.connected_to(:connectable => self, :version => (version - 1)).all.each do |p|
      unless p == published_by_page
        #This just creates a new version of the page
        action = deleted? ? "Deleted" : "Edited"
        p.update_attributes(:publish_on_save => (published? && p.published?), :version_comment => "#{self.class.name} ##{id} was #{action}")

        #The previous step will copy over a connector pointing to the previous version of this connectable
        #We need to change that to point at the new version of this connectable
        p.connectors.for_page_version(p.version).for_connectable(self).each do |con|
          con.update_attribute(:connectable_version, version)
        end                  
      end
    end
  end
  true
end