class SakaiInfo::Page

Attributes

dbrow[R]
layout[R]
order[R]
site_id[R]
title[R]

Public Class Methods

clear_cache() click to toggle source
# File lib/sakai-info/page.rb, line 16
def self.clear_cache
  @@cache = {}
end
count_by_site_id(site_id) click to toggle source
# File lib/sakai-info/page.rb, line 37
def self.count_by_site_id(site_id)
  Page.query_by_site_id(site_id).count
end
find(id) click to toggle source
# File lib/sakai-info/page.rb, line 21
def self.find(id)
  if @@cache[id].nil?
    row = DB.connect[:sakai_site_page].where(:page_id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(Page, id)
    end

    @@cache[id] = Page.new(row)
  end
  @@cache[id]
end
find_by_site_id(site_id) click to toggle source
# File lib/sakai-info/page.rb, line 41
def self.find_by_site_id(site_id)
  Page.query_by_site_id(site_id).order(:site_order).all.
    collect { |row| @@cache[row[:page_id]] = Page.new(row) }
end
new(dbrow) click to toggle source
# File lib/sakai-info/page.rb, line 46
def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:page_id]
  @title = dbrow[:title]
  @order = dbrow[:site_order].to_i
  @layout = dbrow[:layout]
  @site_id = dbrow[:site_id]
end
query_by_site_id(site_id) click to toggle source
# File lib/sakai-info/page.rb, line 33
def self.query_by_site_id(site_id)
  DB.connect[:sakai_site_page].where(:site_id => site_id)
end

Public Instance Methods

default_serialization() click to toggle source
# File lib/sakai-info/page.rb, line 88
def default_serialization
  result = site_summary_serialization
  result["site"] = self.site.serialize(:summary)
  result
end
properties() click to toggle source
# File lib/sakai-info/page.rb, line 60
def properties
  @properties ||= PageProperty.find_by_page_id(@id)
end
site() click to toggle source
# File lib/sakai-info/page.rb, line 56
def site
  @site ||= Site.find(@site_id)
end
site_summary_serialization() click to toggle source
# File lib/sakai-info/page.rb, line 77
def site_summary_serialization
  result = summary_serialization
  result.delete("site_id")
  result["order"] = self.order
  result["tools"] = self.tools.collect { |tool| tool.serialize(:summary) }
  if not self.properties.nil? and self.properties != {}
    result["properties"] = self.properties
  end
  result
end
summary_serialization() click to toggle source

serialization

# File lib/sakai-info/page.rb, line 69
def summary_serialization
  {
    "id" => self.id,
    "title" => self.title,
    "site_id" => self.site_id
  }
end
tools() click to toggle source
# File lib/sakai-info/page.rb, line 64
def tools
  @tools ||= Tool.find_by_page_id(@id)
end