Class: SakaiInfo::QuizSection

Inherits:
SakaiObject show all
Includes:
ModProps
Defined in:
lib/sakai-info/quiz.rb

Direct Known Subclasses

PendingQuizSection, PublishedQuizSection

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModProps

included

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

Returns a new instance of QuizSection.



405
406
407
408
409
410
411
412
413
414
415
# File 'lib/sakai-info/quiz.rb', line 405

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:sectionid]
  @quiz = Quiz.find(dbrow[:assessmentid])
  @sequence = dbrow[:sequence]
  @title = dbrow[:title]
  @description = dbrow[:description]
  @typeid = dbrow[:typeid]
  @status = dbrow[:status]
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



392
393
394
# File 'lib/sakai-info/quiz.rb', line 392

def dbrow
  @dbrow
end

#descriptionObject (readonly)

Returns the value of attribute description.



392
393
394
# File 'lib/sakai-info/quiz.rb', line 392

def description
  @description
end

#quizObject (readonly)

Returns the value of attribute quiz.



392
393
394
# File 'lib/sakai-info/quiz.rb', line 392

def quiz
  @quiz
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



392
393
394
# File 'lib/sakai-info/quiz.rb', line 392

def sequence
  @sequence
end

#statusObject (readonly)

Returns the value of attribute status.



392
393
394
# File 'lib/sakai-info/quiz.rb', line 392

def status
  @status
end

#titleObject (readonly)

Returns the value of attribute title.



392
393
394
# File 'lib/sakai-info/quiz.rb', line 392

def title
  @title
end

#typeidObject (readonly)

Returns the value of attribute typeid.



392
393
394
# File 'lib/sakai-info/quiz.rb', line 392

def typeid
  @typeid
end

Class Method Details

.all_serializationsObject



500
501
502
# File 'lib/sakai-info/quiz.rb', line 500

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

.clear_cacheObject



400
401
402
# File 'lib/sakai-info/quiz.rb', line 400

def self.clear_cache
  @@cache = {}
end

.count_by_quiz_id(quiz_id) ⇒ Object



449
450
451
# File 'lib/sakai-info/quiz.rb', line 449

def self.count_by_quiz_id(quiz_id)
  QuizSection.query_by_quiz_id(quiz_id).count
end

.find(id) ⇒ Object



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/sakai-info/quiz.rb', line 417

def self.find(id)
  id = id.to_s
  if @@cache[id].nil?
    begin
      @@cache[id] = PendingQuizSection.find(id)
    rescue ObjectNotFoundException
      begin
        @@cache[id] = PublishedQuizSection.find(id)
      rescue ObjectNotFoundException
        raise ObjectNotFoundException.new(QuizSection, id)
      end
    end
  end
  @@cache[id]
end

.find_by_quiz_id(quiz_id) ⇒ Object



442
443
444
445
446
447
# File 'lib/sakai-info/quiz.rb', line 442

def self.find_by_quiz_id(quiz_id)
  section_class = Quiz.find(quiz_id).section_class
  QuizSection.query_by_quiz_id(quiz_id).all.collect do |row|
    section_class.new(row)
  end
end

.query_by_quiz_id(quiz_id) ⇒ Object



433
434
435
436
437
438
439
440
# File 'lib/sakai-info/quiz.rb', line 433

def self.query_by_quiz_id(quiz_id)
  table = if Quiz.find(quiz_id).quiz_type == "pending"
            :sam_section_t
          else
            :sam_publishedsection_t
          end
  DB.connect[table].where(:assessmentid => quiz_id).order(:sequence)
end

Instance Method Details

#default_serializationObject



465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/sakai-info/quiz.rb', line 465

def default_serialization
  {
    "id" => self.id,
    "title" => self.title,
    "quiz" => self.quiz.serialize(:summary),
    "sequence" => self.sequence,
    "item_count" => self.item_count,
    "description" => self.description,
    "type" => self.section_type,
    "typeid" => self.typeid,
    "status" => self.status
  }
end

#item_countObject



457
458
459
# File 'lib/sakai-info/quiz.rb', line 457

def item_count
  @item_count ||= QuizItem.count_by_section_id(self.id)
end

#itemsObject



461
462
463
# File 'lib/sakai-info/quiz.rb', line 461

def items
  @items ||= QuizItem.find_by_section_id(self.id)
end

#items_serializationObject



494
495
496
497
498
# File 'lib/sakai-info/quiz.rb', line 494

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

#quiz_summary_serializationObject



488
489
490
491
492
# File 'lib/sakai-info/quiz.rb', line 488

def quiz_summary_serialization
  result = summary_serialization
  result.delete("quiz_id")
  result
end

#section_typeObject



453
454
455
# File 'lib/sakai-info/quiz.rb', line 453

def section_type
  nil
end

#summary_serializationObject



479
480
481
482
483
484
485
486
# File 'lib/sakai-info/quiz.rb', line 479

def summary_serialization
  {
    "id" => self.id,
    "title" => self.title,
    "quiz_id" => self.quiz.id,
    "sequence" => self.sequence
  }
end