Class: SakaiInfo::Gradebook

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

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SakaiObject

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

Constructor Details

#initialize(dbrow) ⇒ Gradebook

Returns a new instance of Gradebook.



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

def initialize(dbrow)
  @dbrow = dbrow

  @id = @dbrow[:id].to_i
  @version = @dbrow[:version].to_i
  @site_id = @dbrow[:gradebook_uid]
  @name = @dbrow[:name]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#site_idObject (readonly)

Returns the value of attribute site_id.



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

def site_id
  @site_id
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.all_serializationsObject



97
98
99
100
101
102
# File 'lib/sakai-info/gradebook.rb', line 97

def self.all_serializations
  [
   :default,
   :items
  ]
end

.clear_cacheObject



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

def self.clear_cache
  @@cache = {}
end

.count_by_site_id(site_id) ⇒ Object



50
51
52
# File 'lib/sakai-info/gradebook.rb', line 50

def self.count_by_site_id(site_id)
  Gradebook.query_by_site_id(site_id).count
end

.find(id) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sakai-info/gradebook.rb', line 30

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

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

.find_by_site_id(site_id) ⇒ Object



54
55
56
# File 'lib/sakai-info/gradebook.rb', line 54

def self.find_by_site_id(site_id)
  Gradebook.query_by_site_id(site_id).all.collect { |row| Gradebook.new(row) }
end

.query_by_site_id(site_id) ⇒ Object



46
47
48
# File 'lib/sakai-info/gradebook.rb', line 46

def self.query_by_site_id(site_id)
  DB.connect[:gb_gradebook_t].where(:gradebook_uid => site_id)
end

Instance Method Details

#default_serializationObject



66
67
68
69
70
71
72
73
74
# File 'lib/sakai-info/gradebook.rb', line 66

def default_serialization
  {
    "id" => self.id,
    "name" => self.name,
    "site" => self.site.serialize(:summary),
    "version" => self.version,
    "item_count" => self.item_count,
  }
end

#item_countObject



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

def item_count
  @item_count ||= GradebookItem.count_by_gradebook_id(self.id)
end

#itemsObject



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

def items
  @items ||= GradebookItem.find_by_gradebook_id(self.id)
end

#items_serializationObject



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

def items_serialization
  {
    "items" => self.items.collect { |item| item.serialize(:summary) }
  }
end

#siteObject



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

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

#site_summary_serializationObject



85
86
87
88
89
# File 'lib/sakai-info/gradebook.rb', line 85

def site_summary_serialization
  {
    "id" => self.id,
  }
end

#summary_serializationObject



76
77
78
79
80
81
82
83
# File 'lib/sakai-info/gradebook.rb', line 76

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