Class: SakaiInfo::QuizAttemptItem

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

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

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

Returns a new instance of QuizAttemptItem.



937
938
939
940
941
942
943
944
945
946
# File 'lib/sakai-info/quiz.rb', line 937

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:itemgradingid]
  @submitted_at = dbrow[:submitteddate]
  @user_id = dbrow[:agentid]
  @attempt_id = dbrow[:assessmentgradingid]
  @item_id = dbrow[:publisheditemid]
  @answer = dbrow[:answertext]
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



930
931
932
# File 'lib/sakai-info/quiz.rb', line 930

def answer
  @answer
end

#attempt_idObject (readonly)

Returns the value of attribute attempt_id.



930
931
932
# File 'lib/sakai-info/quiz.rb', line 930

def attempt_id
  @attempt_id
end

#dbrowObject (readonly)

Returns the value of attribute dbrow.



930
931
932
# File 'lib/sakai-info/quiz.rb', line 930

def dbrow
  @dbrow
end

#item_idObject (readonly)

Returns the value of attribute item_id.



930
931
932
# File 'lib/sakai-info/quiz.rb', line 930

def item_id
  @item_id
end

#submitted_atObject (readonly)

Returns the value of attribute submitted_at.



930
931
932
# File 'lib/sakai-info/quiz.rb', line 930

def 
  @submitted_at
end

#user_idObject (readonly)

Returns the value of attribute user_id.



930
931
932
# File 'lib/sakai-info/quiz.rb', line 930

def user_id
  @user_id
end

Class Method Details

.all_serializationsObject



1027
1028
1029
# File 'lib/sakai-info/quiz.rb', line 1027

def self.all_serializations
  [:default, :attachments]
end

.clear_cacheObject



932
933
934
# File 'lib/sakai-info/quiz.rb', line 932

def self.clear_cache
  @@cache = {}
end

.count_by_attempt_id(attempt_id) ⇒ Object



977
978
979
# File 'lib/sakai-info/quiz.rb', line 977

def self.count_by_attempt_id(attempt_id)
  QuizAttemptItem.query_by_attempt_id(attempt_id).count
end

.find(id) ⇒ Object



960
961
962
963
964
965
966
967
968
969
970
971
# File 'lib/sakai-info/quiz.rb', line 960

def self.find(id)
  id = id.to_s
  if @@cache[id].nil?
    row = DB.connect[:sam_itemgrading_t].where(:itemgradingid => id).first
    if row.nil?
      raise ObjectNotFoundException.new(QuizAttemptItem, id)
    end

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

.find_by_attempt_id(attempt_id) ⇒ Object



981
982
983
984
# File 'lib/sakai-info/quiz.rb', line 981

def self.find_by_attempt_id(attempt_id)
  QuizAttemptItem.query_by_attempt_id(attempt_id).
    all.collect { |row| QuizAttemptItem.new(row) }
end

.query_by_attempt_id(attempt_id) ⇒ Object



973
974
975
# File 'lib/sakai-info/quiz.rb', line 973

def self.query_by_attempt_id(attempt_id)
  DB.connect[:sam_itemgrading_t].where(:assessmentgradingid => attempt_id)
end

Instance Method Details

#attachmentsObject



986
987
988
989
# File 'lib/sakai-info/quiz.rb', line 986

def attachments
  @attachments ||=
    QuizAttemptItemAttachment.find_by_quiz_attempt_item_id(self.id)
end

#attachments_serializationObject



1021
1022
1023
1024
1025
# File 'lib/sakai-info/quiz.rb', line 1021

def attachments_serialization
  {
    "attachments" => self.attachments.collect{|a|a.serialize(:attempt_item_summary)}
  }
end

#attemptObject



952
953
954
# File 'lib/sakai-info/quiz.rb', line 952

def attempt
  @attempt ||= QuizAttempt.find(@attempt_id)
end

#attempt_summary_serializationObject



1013
1014
1015
1016
1017
1018
1019
# File 'lib/sakai-info/quiz.rb', line 1013

def attempt_summary_serialization
  {
    "id" => self.id,
    "item_id" => self.item_id,
    "submitted_at" => self.,
  }
end

#default_serializationObject



991
992
993
994
995
996
997
998
999
1000
1001
# File 'lib/sakai-info/quiz.rb', line 991

def default_serialization
  {
    "id" => self.id,
    "user" => self.user.serialize(:summary),
    "attempt" => self.attempt.serialize(:summary),
    "item" => self.item.serialize(:summary),
    "answer" => self.answer,
    "attachment_count" => self.attachments.length,
    "submitted_at" => self.,
  }
end

#itemObject



956
957
958
# File 'lib/sakai-info/quiz.rb', line 956

def item
  @item ||= PublishedQuizItem.find(@item_id)
end

#summary_serializationObject



1003
1004
1005
1006
1007
1008
1009
1010
1011
# File 'lib/sakai-info/quiz.rb', line 1003

def summary_serialization
  {
    "id" => self.id,
    "eid" => User.get_eid(self.user_id),
    "attempt_id" => self.attempt_id,
    "item_id" => self.item_id,
    "submitted_at" => self.,
  }
end

#userObject



948
949
950
# File 'lib/sakai-info/quiz.rb', line 948

def user
  @user ||= User.find(@user_id)
end