Class: SakaiInfo::Page

Inherits:
SakaiObject show all
Defined in:
lib/sakai-info/page.rb

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SakaiObject

all_serializations, #dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(dbrow) ⇒ Page

Returns a new instance of Page.



46
47
48
49
50
51
52
53
54
# 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

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



14
15
16
# File 'lib/sakai-info/page.rb', line 14

def dbrow
  @dbrow
end

#layoutObject (readonly)

Returns the value of attribute layout.



14
15
16
# File 'lib/sakai-info/page.rb', line 14

def layout
  @layout
end

#orderObject (readonly)

Returns the value of attribute order.



14
15
16
# File 'lib/sakai-info/page.rb', line 14

def order
  @order
end

#site_idObject (readonly)

Returns the value of attribute site_id.



14
15
16
# File 'lib/sakai-info/page.rb', line 14

def site_id
  @site_id
end

#titleObject (readonly)

Returns the value of attribute title.



14
15
16
# File 'lib/sakai-info/page.rb', line 14

def title
  @title
end

Class Method Details

.clear_cacheObject



16
17
18
# File 'lib/sakai-info/page.rb', line 16

def self.clear_cache
  @@cache = {}
end

.count_by_site_id(site_id) ⇒ Object



37
38
39
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Object



41
42
43
44
# 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

.query_by_site_id(site_id) ⇒ Object



33
34
35
# 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

Instance Method Details

#default_serializationObject



88
89
90
91
92
# File 'lib/sakai-info/page.rb', line 88

def default_serialization
  result = site_summary_serialization
  result["site"] = self.site.serialize(:summary)
  result
end

#propertiesObject



60
61
62
# File 'lib/sakai-info/page.rb', line 60

def properties
  @properties ||= PageProperty.find_by_page_id(@id)
end

#siteObject



56
57
58
# File 'lib/sakai-info/page.rb', line 56

def site
  @site ||= Site.find(@site_id)
end

#site_summary_serializationObject



77
78
79
80
81
82
83
84
85
86
# 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_serializationObject

serialization



69
70
71
72
73
74
75
# File 'lib/sakai-info/page.rb', line 69

def summary_serialization
  {
    "id" => self.id,
    "title" => self.title,
    "site_id" => self.site_id
  }
end

#toolsObject



64
65
66
# File 'lib/sakai-info/page.rb', line 64

def tools
  @tools ||= Tool.find_by_page_id(@id)
end