Class: SakaiInfo::PublishedQuiz

Inherits:
Quiz show all
Defined in:
lib/sakai-info/quiz.rb

Constant Summary

Constants inherited from Quiz

Quiz::ACTIVE, Quiz::DELETED, Quiz::INACTIVE, Quiz::RETRACTED_FOR_EDITING

Instance Attribute Summary

Attributes inherited from Quiz

#dbrow, #site, #title

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Quiz

#access_control, #access_control_summary_serialization, #authorizations, #authorizations_serialization, #auths_serialization, #default_serialization, #initialize, #item_count, #items, #items_serialization, #metadata, #metadata_serialization, #section_count, #sections, #sections_serialization, #site_summary_serialization, #status, #summary_serialization

Methods included from ModProps

included

Methods inherited from SakaiObject

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

Constructor Details

This class inherits a constructor from SakaiInfo::Quiz

Class Method Details

.all_serializationsObject



381
382
383
384
385
386
387
388
# File 'lib/sakai-info/quiz.rb', line 381

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

.clear_cacheObject



298
299
300
# File 'lib/sakai-info/quiz.rb', line 298

def self.clear_cache
  @@cache = {}
end

.count_by_site_id(site_id) ⇒ Object



331
332
333
# File 'lib/sakai-info/quiz.rb', line 331

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

.find(id) ⇒ Object



303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/sakai-info/quiz.rb', line 303

def self.find(id)
  id = id.to_s
  if @@cache[id].nil?
    row = DB.connect[:sam_publishedassessment_t].filter(:id => id.to_i).first
    if row.nil?
      raise ObjectNotFoundException.new(PublishedQuiz, id)
    end

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

.find_by_site_id(site_id) ⇒ Object



325
326
327
328
329
# File 'lib/sakai-info/quiz.rb', line 325

def self.find_by_site_id(site_id)
  PublishedQuiz.query_by_site_id(site_id).all.collect do |row|
    @@cache[row[:id]] = PublishedQuiz.new(row, site_id)
  end
end

.find_ids_by_site_id(site_id) ⇒ Object



335
336
337
# File 'lib/sakai-info/quiz.rb', line 335

def self.find_ids_by_site_id(site_id)
  PublishedQuiz.query_by_site_id(site_id).select(:id).all.collect { |row| row[:id] }
end

.query_by_site_id(site_id) ⇒ Object



316
317
318
319
320
321
322
323
# File 'lib/sakai-info/quiz.rb', line 316

def self.query_by_site_id(site_id)
  db = DB.connect
  db[:sam_publishedassessment_t].
    where(:id =>
          db[:sam_authzdata_t].select(:qualifierid).
          where(:agentid => site_id,
                :functionid => "OWN_PUBLISHED_ASSESSMENT"))
end

Instance Method Details

#access_control_classObject



355
356
357
# File 'lib/sakai-info/quiz.rb', line 355

def access_control_class
  PublishedQuizAccessControl
end

#attempt_countObject



367
368
369
# File 'lib/sakai-info/quiz.rb', line 367

def attempt_count
  @attempt_count ||= QuizAttempt.count_by_quiz_id(self.id)
end

#attemptsObject



371
372
373
# File 'lib/sakai-info/quiz.rb', line 371

def attempts
  @attempts ||= QuizAttempt.find_by_quiz_id(self.id)
end

#attempts_serializationObject



375
376
377
378
379
# File 'lib/sakai-info/quiz.rb', line 375

def attempts_serialization
  {
    "attempts" => self.attempts.collect { |a| a.serialize(:quiz_summary) }
  }
end

#authorization_classObject



363
364
365
# File 'lib/sakai-info/quiz.rb', line 363

def authorization_class
  PublishedQuizAuthorization
end

#item_classObject



351
352
353
# File 'lib/sakai-info/quiz.rb', line 351

def item_class
  PublishedQuizItem
end

#metadata_classObject



359
360
361
# File 'lib/sakai-info/quiz.rb', line 359

def 
  PublishedQuizMetadata
end

#quiz_typeObject



343
344
345
# File 'lib/sakai-info/quiz.rb', line 343

def quiz_type
  "published"
end

#section_classObject



347
348
349
# File 'lib/sakai-info/quiz.rb', line 347

def section_class
  PublishedQuizSection
end

#user_attempts(user_id) ⇒ Object



339
340
341
# File 'lib/sakai-info/quiz.rb', line 339

def user_attempts(user_id)
  QuizAttempt.find_by_user_id_and_quiz_id(user_id, self.id)
end