Class: SakaiInfo::Assignment
- Inherits:
-
SakaiXMLEntity
- Object
- SakaiObject
- SakaiXMLEntity
- SakaiInfo::Assignment
- Defined in:
- lib/sakai-info/assignment.rb
Instance Attribute Summary collapse
-
#dbrow ⇒ Object
readonly
Returns the value of attribute dbrow.
-
#site_id ⇒ Object
readonly
Returns the value of attribute site_id.
Attributes inherited from SakaiXMLEntity
#attributes, #properties, #xml, #xmldoc
Attributes inherited from SakaiObject
Class Method Summary collapse
- .clear_cache ⇒ Object
- .count_by_site_id(site_id) ⇒ Object
- .find(id) ⇒ Object
- .find_by_site_id(site_id) ⇒ Object
-
.query_by_site_id(site_id) ⇒ Object
set lookup.
Instance Method Summary collapse
-
#default_serialization ⇒ Object
yaml/json serialization.
-
#initialize(dbrow) ⇒ Assignment
constructor
raw data constructor.
- #site ⇒ Object
- #submission_count ⇒ Object
- #submissions ⇒ Object
- #submissions_serialization ⇒ Object
- #summary_serialization ⇒ Object
-
#title ⇒ Object
getters.
Methods inherited from SakaiXMLEntity
all_serializations, #attributes_serialization, #dbrow_serialization, #parse_xml, #properties_serialization, #xml_serialization
Methods included from ModProps
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
#dbrow ⇒ Object (readonly)
Returns the value of attribute dbrow.
14 15 16 |
# File 'lib/sakai-info/assignment.rb', line 14 def dbrow @dbrow end |
#site_id ⇒ Object (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_cache ⇒ Object
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 |
Instance Method Details
#default_serialization ⇒ Object
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 |
#site ⇒ Object
62 63 64 |
# File 'lib/sakai-info/assignment.rb', line 62 def site @site ||= Site.find(self.site_id) end |
#submission_count ⇒ Object
70 71 72 |
# File 'lib/sakai-info/assignment.rb', line 70 def submission_count @submission_count ||= AssignmentSubmission.count_by_assignment_id(self.id) end |
#submissions ⇒ Object
66 67 68 |
# File 'lib/sakai-info/assignment.rb', line 66 def submissions @submissions ||= AssignmentSubmission.find_by_assignment_id(self.id) end |
#submissions_serialization ⇒ Object
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_serialization ⇒ Object
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 |
#title ⇒ Object
getters
58 59 60 |
# File 'lib/sakai-info/assignment.rb', line 58 def title @attributes["title"] end |