require 'page' class Web < ActiveRecord::Base has_many :pages, :conditions => "usage = '#{Page::WIKI}'", :dependent => true has_many :entries, :conditions => "usage = '#{Page::BLIKI}'", :class_name => 'Page', :dependent => true has_many :templates, :class_name => 'Page', :conditions => "usage = '#{Page::TEMPLATE}'", :dependent => true has_many :revisions has_many :current_revisions, :class_name => 'Revision', :conditions => ['current = ?', true] has_many :chunks has_many :current_chunks, :class_name => 'Chunk', :conditions => ['current = ?', true] has_many :tags has_many :tasks, :dependent => true has_many :wiki_files, :dependent => true has_one :menu_content, :class_name => 'Page', :conditions => "usage = '#{Page::SYSTEM}' and name = 'WEB-#{name}-MENU-CONTENT'" validates_uniqueness_of :name validates_uniqueness_of :address def markup_engine case markup when MarkupEngine::TEXTILE then TextileEngine when MarkupEngine::MARKDOWN then MarkDownEngine when MarkupEngine::RDOC then RdocEngine when MarkupEngine::MIXED then MixedEngine else TextileEngine # using textile by default end end def glossary defns = GlossaryDefinition.current_for self usages = GlossaryUsage.current_for self gdict = defns.flatten.inject(GlossaryDict.new) {|gdict, defn| gdict[defn.acronym].definitions[defn.definition] << defn.page; gdict} usages.flatten.inject(gdict) {|gdict, usage| gdict[usage.acronym].usages << usage.page if gdict.acronyms.include?(usage.acronym); gdict } gdict end def author_names ActiveRecord::Base.connection.select_values "SELECT DISTINCT author FROM revisions WHERE web_id = #{id}" end def authors_to_pages author_names.inject({}) do |authors_map, author| authors_map[author] = Page.find_by_sql "SELECT * FROM pages WHERE id IN (SELECT DISTINCT page_id FROM revisions WHERE web_id = #{id} AND author = '#{author}')" authors_map end end ## Returns both the active and inactive todo items in this web arranged in quadrants. # The data are arranged in a quadrant view, expanded to a 3x3 matrix. These are # roughly items of high, mid and low relevancy. The Y axis (rows / first accessor) # are the items based on importance, while the X axis (columns / second accessor) # are the items based on urgency. The top-left corner ([0][0]) is the most # important urgent; the top right corner ([0][2]) is the most important but not # urgent; the bottom left ([2][0]) are the least important but urgent; and the # bottom right ([2][2]) are the least important and least urgent items. def todo_items completed_items, pending_items = TodoChunk.current_for(self).partition{|item| item.done?} active_items = Array.new(3){Array.new(3){[]}} pending_items.each do |todo| active_items[ todo.importance > 3 ? 0 : todo.importance < 3 ? 2 : 1 ][ todo.due_date.to_date < 1.week.from_now.to_date ? 0 : todo.due_date.to_date > 1.month.from_now.to_date ? 2 : 1 ] << todo active_items end [active_items, completed_items] end ## Returns both the active and inactive todo items in this web arranged in a priority list. # Acceptable values for the list_order are: # * :best (default) - sort based on a mix of importance and priority # * :importance - sorts based on importance only # * :due_date - sorts based on due date only def todo_items_as_list list_order=:best a, completed_items = todo_items active_items = case list_order when 'importance' a.flatten.sort_by{|t| [-t.importance, t.due_date]} when 'due_date' a.flatten.sort_by{|t| [t.due_date, -t.importance]} else # when :best [ a[0][0], a[0][1], a[1][0], a[0][2], a[1][1], a[2][0], a[1][2], a[2][1], a[2][2] ].flatten end [active_items, completed_items] end end