Class: SakaiInfo::AssignmentContent

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, #default_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #summary_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(id, owner, xml) ⇒ AssignmentContent

Returns a new instance of AssignmentContent.



220
221
222
223
224
225
# File 'lib/sakai-info/assignment.rb', line 220

def initialize(id, owner, xml)
  @id = id
  @owner = owner
  @xml = xml
  parse_xml
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



213
214
215
# File 'lib/sakai-info/assignment.rb', line 213

def owner
  @owner
end

Class Method Details

.clear_cacheObject



215
216
217
# File 'lib/sakai-info/assignment.rb', line 215

def self.clear_cache
  @@cache = {}
end

.count_by_user_id(user_id) ⇒ Object



252
253
254
# File 'lib/sakai-info/assignment.rb', line 252

def self.count_by_user_id(user_id)
  DB.connect[:assignment_content].where(:context => user_id).count
end

.find(id) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/sakai-info/assignment.rb', line 227

def self.find(id)
  if @@cache[id].nil?
    row = DB.connect[:assignment_content].where(:content_id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(AssignmentContent, id)
    end
    xml = ""
    REXML::Document.new(row[:xml].read).write(xml, 2)
    @@cache[id] = AssignmentContent.new(id, row[:context], xml)
  end
  @@cache[id]
end

.find_by_user_id(user_id) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
# File 'lib/sakai-info/assignment.rb', line 240

def self.find_by_user_id(user_id)
  contents = []
  DB.connect[:assignment_content].where(:context => user_id).all.each do |row|
    id = row[:content_id]
    context = row[:context]
    xml = ""
    REXML::Document.new(row[:xml].read).write(xml, 2)
    contents << AssignmentContent.new(id, context, xml)
  end
  return contents
end

Instance Method Details

#titleObject

getters



257
258
259
# File 'lib/sakai-info/assignment.rb', line 257

def title
  @attributes["title"]
end