Class: SakaiInfo::Assignment

Inherits:
SakaiXMLEntity show all
Defined in:
lib/sakai-info/assignment.rb

Instance Attribute Summary collapse

Attributes inherited from SakaiXMLEntity

#attributes, #properties, #xml, #xmldoc

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SakaiXMLEntity

all_serializations, #attributes_serialization, #dbrow_serialization, #parse_xml, #properties_serialization, #xml_serialization

Methods included from ModProps

included

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) ⇒ Assignment

raw data constructor



34
35
36
37
38
39
40
41
# File 'lib/sakai-info/assignment.rb', line 34

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:assignment_id]
  @site_id = dbrow[:context]

  parse_xml
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



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

def dbrow
  @dbrow
end

#site_idObject (readonly)

Returns the value of attribute site_id.



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

def site_id
  @site_id
end

Class Method Details

.clear_cacheObject



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

def self.clear_cache
  @@cache = {}
end

.count_by_site_id(site_id) ⇒ Object



53
54
55
# File 'lib/sakai-info/assignment.rb', line 53

def self.count_by_site_id(site_id)
  Assignment.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/assignment.rb', line 21

def self.find(id)
  if @@cache[id].nil?
    xml = ""
    row = DB.connect[:assignment_assignment].where(:assignment_id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(Assignment, id)
    end
    @@cache[id] = Assignment.new(row)
  end
  @@cache[id]
end

.find_by_site_id(site_id) ⇒ Object



48
49
50
51
# File 'lib/sakai-info/assignment.rb', line 48

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

.query_by_site_id(site_id) ⇒ Object

set lookup



44
45
46
# File 'lib/sakai-info/assignment.rb', line 44

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

Instance Method Details

#default_serializationObject

yaml/json serialization



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

def default_serialization
  {
    "id" => self.id,
    "title" => self.title,
    "site" => self.site.serialize(:summary),
    "submission_count" => self.submission_count
  }
end

#siteObject



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

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

#submission_countObject



70
71
72
# File 'lib/sakai-info/assignment.rb', line 70

def submission_count
  @submission_count ||= AssignmentSubmission.count_by_assignment_id(self.id)
end

#submissionsObject



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

def submissions
  @submissions ||= AssignmentSubmission.find_by_assignment_id(self.id)
end

#submissions_serializationObject



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

def submissions_serialization
  {
    "submissions" => self.submissions.collect{|s|s.serialize(:assignment_summary)}
  }
end

#summary_serializationObject



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

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

#titleObject

getters



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

def title
  @attributes["title"]
end