Class: SakaiInfo::AssignmentSubmission

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

Constructor Details

#initialize(dbrow) ⇒ AssignmentSubmission

Returns a new instance of AssignmentSubmission.



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/sakai-info/assignment.rb', line 107

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:submission_id]
  @assignment_id = dbrow[:context]
  @submitter_id = dbrow[:submitter_id]
  @is_submitted = (dbrow[:submitted] == "true")
  @is_graded = (dbrow[:graded] == "true")

  parse_xml
end

Instance Attribute Details

#assignment_idObject (readonly)

Returns the value of attribute assignment_id.



100
101
102
# File 'lib/sakai-info/assignment.rb', line 100

def assignment_id
  @assignment_id
end

#dbrowObject (readonly)

Returns the value of attribute dbrow.



100
101
102
# File 'lib/sakai-info/assignment.rb', line 100

def dbrow
  @dbrow
end

#submitter_idObject (readonly)

Returns the value of attribute submitter_id.



100
101
102
# File 'lib/sakai-info/assignment.rb', line 100

def submitter_id
  @submitter_id
end

Class Method Details

.clear_cacheObject



102
103
104
# File 'lib/sakai-info/assignment.rb', line 102

def self.clear_cache
  @@cache = {}
end

.count_by_assignment_id(assignment_id) ⇒ Object



160
161
162
# File 'lib/sakai-info/assignment.rb', line 160

def self.count_by_assignment_id(assignment_id)
  AssignmentSubmission.query_by_assignment_id(assignment_id).count
end

.count_by_user_id(user_id) ⇒ Object



173
174
175
# File 'lib/sakai-info/assignment.rb', line 173

def self.count_by_user_id(user_id)
  AssignmentSubmission.query_by_user_id(user_id).count
end

.find(id) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/sakai-info/assignment.rb', line 119

def self.find(id)
  if @@cache[id].nil?
    row = DB.connect[:assignment_submission].where(:submission_id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(AssignmentSubmission, id)
    end

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

.find_by_assignment_id(assignment_id) ⇒ Object



155
156
157
158
# File 'lib/sakai-info/assignment.rb', line 155

def self.find_by_assignment_id(assignment_id)
  AssignmentSubmission.query_by_assignment_id(assignment_id).
    all.collect { |row| AssignmentSubmission.new(row) }
end

.find_by_user_id(user_id) ⇒ Object



168
169
170
171
# File 'lib/sakai-info/assignment.rb', line 168

def self.find_by_user_id(user_id)
  AssignmentSubmission.query_by_user_id(user_id).
    all.collect { |row| AssignmentSubmission.new(row) }
end

.query_by_assignment_id(assignment_id) ⇒ Object



151
152
153
# File 'lib/sakai-info/assignment.rb', line 151

def self.query_by_assignment_id(assignment_id)
  DB.connect[:assignment_submission].where(:context => assignment_id)
end

.query_by_user_id(user_id) ⇒ Object



164
165
166
# File 'lib/sakai-info/assignment.rb', line 164

def self.query_by_user_id(user_id)
  DB.connect[:assignment_submission].where(:submitter_id => user_id)
end

Instance Method Details

#assignmentObject



135
136
137
# File 'lib/sakai-info/assignment.rb', line 135

def assignment
  @assignment ||= Assignment.find(self.assignment_id)
end

#assignment_summary_serializationObject



203
204
205
206
207
208
209
# File 'lib/sakai-info/assignment.rb', line 203

def assignment_summary_serialization
  {
    "id" => self.id,
    "submitter" => User.get_eid(self.submitter_id),
    "is_submitted" => self.
  }
end

#default_serializationObject

yaml/json serialization



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/sakai-info/assignment.rb', line 178

def default_serialization
  result = {
    "id" => self.id,
    "assignment" => self.assignment.serialize(:summary),
    "submitter" => self.submitter.serialize(:summary),
    "is_submitted" => self.,
    "submitted_at" => self.,
    "is_graded" => self.graded?,
  }
  if not self.
    result.delete("submitted_at")
    result.delete("is_graded")
  end
  result
end

#graded?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/sakai-info/assignment.rb', line 143

def graded?
  @is_graded || false
end

#submitted?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/sakai-info/assignment.rb', line 139

def 
  ( self.created_by_id == self.submitter_id && @is_submitted ) || false
end

#submitted_atObject



147
148
149
# File 'lib/sakai-info/assignment.rb', line 147

def 
  @submitted_at ||= Util.format_entity_date(@attributes["datesubmitted"])
end

#submitterObject



131
132
133
# File 'lib/sakai-info/assignment.rb', line 131

def submitter
  @submitter ||= User.find(self.submitter_id)
end

#summary_serializationObject



194
195
196
197
198
199
200
201
# File 'lib/sakai-info/assignment.rb', line 194

def summary_serialization
  {
    "id" => self.id,
    "assignment_id" => self.assignment_id,
    "submitter" => User.get_eid(self.submitter_id),
    "is_submitted" => self.
  }
end