Class: SakaiInfo::QuizItem
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) ⇒ QuizItem
Returns a new instance of QuizItem.
567
568
569
570
571
572
573
574
575
|
# File 'lib/sakai-info/quiz.rb', line 567
def initialize(dbrow)
@dbrow = dbrow
@id = dbrow[:itemid]
@section = QuizSection.find(dbrow[:sectionid])
@quiz = @section.quiz
@sequence = dbrow[:sequence]
@typeid = dbrow[:typeid]
end
|
Instance Attribute Details
#dbrow ⇒ Object
Returns the value of attribute dbrow.
554
555
556
|
# File 'lib/sakai-info/quiz.rb', line 554
def dbrow
@dbrow
end
|
#quiz ⇒ Object
Returns the value of attribute quiz.
554
555
556
|
# File 'lib/sakai-info/quiz.rb', line 554
def quiz
@quiz
end
|
#section ⇒ Object
Returns the value of attribute section.
554
555
556
|
# File 'lib/sakai-info/quiz.rb', line 554
def section
@section
end
|
#sequence ⇒ Object
Returns the value of attribute sequence.
554
555
556
|
# File 'lib/sakai-info/quiz.rb', line 554
def sequence
@sequence
end
|
#typeid ⇒ Object
Returns the value of attribute typeid.
554
555
556
|
# File 'lib/sakai-info/quiz.rb', line 554
def typeid
@typeid
end
|
Class Method Details
.all_serializations ⇒ Object
706
707
708
709
710
711
712
|
# File 'lib/sakai-info/quiz.rb', line 706
def self.all_serializations
[
:default,
:mod,
:texts
]
end
|
.class_for_type(type) ⇒ Object
601
602
603
604
605
606
607
|
# File 'lib/sakai-info/quiz.rb', line 601
def self.class_for_type(type)
if type == "pending"
PendingQuizItem
else
PublishedQuizItem
end
end
|
.clear_cache ⇒ Object
562
563
564
|
# File 'lib/sakai-info/quiz.rb', line 562
def self.clear_cache
@@cache = {}
end
|
.count_by_quiz_id(quiz_id) ⇒ Object
631
632
633
|
# File 'lib/sakai-info/quiz.rb', line 631
def self.count_by_quiz_id(quiz_id)
QuizItem.query_by_quiz_id(quiz_id).count
end
|
.count_by_section_id(section_id) ⇒ Object
614
615
616
|
# File 'lib/sakai-info/quiz.rb', line 614
def self.count_by_section_id(section_id)
QuizItem.query_by_section_id(section_id).count
end
|
.find_by_quiz_id(quiz_id) ⇒ Object
635
636
637
638
639
640
641
642
643
644
|
# File 'lib/sakai-info/quiz.rb', line 635
def self.find_by_quiz_id(quiz_id)
item_class = QuizItem.class_for_type(Quiz.find(quiz_id).quiz_type)
QuizItem.query_by_quiz_id(quiz_id).order(:sequence).all.collect do |row|
item_class.new(row)
end.sort { |a,b| if a.section.sequence == b.section.sequence
a.sequence <=> b.sequence
else
a.section.sequence <=> b.section.sequence
end }
end
|
.find_by_section_id(section_id) ⇒ Object
.query_by_quiz_id(quiz_id) ⇒ Object
.query_by_section_id(section_id) ⇒ Object
.table_name_for_type(type) ⇒ Object
593
594
595
596
597
598
599
|
# File 'lib/sakai-info/quiz.rb', line 593
def self.table_name_for_type(type)
if type == "pending"
:sam_item_t
else
:sam_publisheditem_t
end
end
|
Instance Method Details
#default_serialization ⇒ Object
666
667
668
669
670
671
672
673
674
675
|
# File 'lib/sakai-info/quiz.rb', line 666
def default_serialization
{
"id" => self.id,
"quiz" => self.quiz.serialize(:summary),
"section" => self.section.serialize(:summary),
"sequence" => self.sequence,
"type" => self.item_type,
"typeid" => self.typeid
}
end
|
#item_type ⇒ Object
646
647
648
|
# File 'lib/sakai-info/quiz.rb', line 646
def item_type
nil
end
|
#itemtext_table ⇒ Object
650
651
652
|
# File 'lib/sakai-info/quiz.rb', line 650
def itemtext_table
nil
end
|
#quiz_summary_serialization ⇒ Object
685
686
687
688
689
690
691
|
# File 'lib/sakai-info/quiz.rb', line 685
def quiz_summary_serialization
{
"id" => self.id,
"section" => self.section.sequence,
"sequence" => self.sequence,
}
end
|
#section_summary_serialization ⇒ Object
693
694
695
696
697
698
|
# File 'lib/sakai-info/quiz.rb', line 693
def section_summary_serialization
{
"id" => self.id,
"sequence" => self.sequence,
}
end
|
#summary_serialization ⇒ Object
677
678
679
680
681
682
683
|
# File 'lib/sakai-info/quiz.rb', line 677
def summary_serialization
{
"id" => self.id,
"quiz_id" => self.quiz.id,
"section_id" => self.section.id
}
end
|
#texts ⇒ Object
654
655
656
657
658
659
660
661
662
663
664
|
# File 'lib/sakai-info/quiz.rb', line 654
def texts
if self.itemtext_table.nil?
return []
end
DB.connect[self.itemtext_table].
select(:text).
where(:itemid => self.id).
order(:sequence).all.
collect { |row| row[:text].read }
end
|
#texts_serialization ⇒ Object
700
701
702
703
704
|
# File 'lib/sakai-info/quiz.rb', line 700
def texts_serialization
{
"texts" => self.texts
}
end
|