Class: SakaiInfo::Tool

Inherits:
SakaiObject show all
Defined in:
lib/sakai-info/tool.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) ⇒ Tool

Returns a new instance of Tool.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sakai-info/tool.rb', line 46

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:tool_id]
  @title = dbrow[:title]
  @registration = dbrow[:registration]
  @order = dbrow[:page_order].to_i
  @layout = dbrow[:layout_hints]
  @page_id = dbrow[:page_id]
  @site_id = dbrow[:site_id]
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



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

def dbrow
  @dbrow
end

#layoutObject (readonly)

Returns the value of attribute layout.



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

def layout
  @layout
end

#orderObject (readonly)

Returns the value of attribute order.



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

def order
  @order
end

#page_idObject (readonly)

Returns the value of attribute page_id.



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

def page_id
  @page_id
end

#registrationObject (readonly)

Returns the value of attribute registration.



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

def registration
  @registration
end

#site_idObject (readonly)

Returns the value of attribute site_id.



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

def site_id
  @site_id
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.clear_cacheObject



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

def self.clear_cache
  @@cache = {}
end

.count_by_page_id(page_id) ⇒ Object



37
38
39
# File 'lib/sakai-info/tool.rb', line 37

def self.count_by_page_id(page_id)
  Tool.query_by_page_id(page_id).count
end

.find(id) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sakai-info/tool.rb', line 21

def self.find(id)
  if @@cache[id].nil?
    row = DB.connect[:sakai_site_tool].where(:tool_id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(Tool, id)
    end

    @@cache[id] = Tool.new(row)
  end
  @@cache[id]
end

.find_by_page_id(page_id) ⇒ Object



41
42
43
44
# File 'lib/sakai-info/tool.rb', line 41

def self.find_by_page_id(page_id)
  Tool.query_by_page_id(page_id).order(:page_order).all.
    collect { |row| @@cache[row[:tool_id]] = Tool.new(row) }
end

.query_by_page_id(page_id) ⇒ Object



33
34
35
# File 'lib/sakai-info/tool.rb', line 33

def self.query_by_page_id(page_id)
  DB.connect[:sakai_site_tool].where(:page_id => page_id)
end

Instance Method Details

#default_serializationObject

serialization



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sakai-info/tool.rb', line 71

def default_serialization
  result = {
    "id" => self.id,
    "registration" => self.registration,
    "title" => self.title,
    "site" => self.site.serialize(:summary),
    "page_id" => self.page_id,
    "order" => self.order,
    "layout" => self.layout,
    "properties" => self.properties
  }
  if result["properties"] == {}
    result.delete("properties")
  end
  if result["layout"].nil?
    result.delete("layout")
  end
  result
end

#pageObject



58
59
60
# File 'lib/sakai-info/tool.rb', line 58

def page
  @page ||= Page.find(@page_id)
end

#propertiesObject



66
67
68
# File 'lib/sakai-info/tool.rb', line 66

def properties
  @properties ||= ToolProperty.find_by_tool_id(@id)
end

#siteObject



62
63
64
# File 'lib/sakai-info/tool.rb', line 62

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

#summary_serializationObject



91
92
93
94
95
96
97
# File 'lib/sakai-info/tool.rb', line 91

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