Class: SakaiInfo::QuestionPool

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

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

all_serializations, #dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(dbrow) ⇒ QuestionPool

Returns a new instance of QuestionPool.



27
28
29
30
31
32
33
34
35
36
# File 'lib/sakai-info/question_pool.rb', line 27

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:questionpoolid]
  @title = dbrow[:title]
  @description = dbrow[:description]
  @owner = User.find(dbrow[:ownerid])
  @parent_pool_id = dbrow[:parentpoolid]
  @parent_pool_id = nil if @parent_pool_id == 0
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



14
15
16
# File 'lib/sakai-info/question_pool.rb', line 14

def dbrow
  @dbrow
end

#descriptionObject (readonly)

Returns the value of attribute description.



14
15
16
# File 'lib/sakai-info/question_pool.rb', line 14

def description
  @description
end

#ownerObject (readonly)

Returns the value of attribute owner.



14
15
16
# File 'lib/sakai-info/question_pool.rb', line 14

def owner
  @owner
end

#parent_pool_idObject (readonly)

Returns the value of attribute parent_pool_id.



14
15
16
# File 'lib/sakai-info/question_pool.rb', line 14

def parent_pool_id
  @parent_pool_id
end

#titleObject (readonly)

Returns the value of attribute title.



14
15
16
# File 'lib/sakai-info/question_pool.rb', line 14

def title
  @title
end

Class Method Details

.clear_cacheObject



22
23
24
# File 'lib/sakai-info/question_pool.rb', line 22

def self.clear_cache
  @@cache = {}
end

.count_by_user_id(user_id) ⇒ Object



59
60
61
# File 'lib/sakai-info/question_pool.rb', line 59

def self.count_by_user_id(user_id)
  DB.connect[:sam_questionpool_t].filter(:ownerid => user_id).count
end

.find(id) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/sakai-info/question_pool.rb', line 38

def self.find(id)
  if @@cache[id].nil?
    row = DB.connect[:sam_questionpool_t].filter(:questionpoolid => id).first
    if row.nil?
      raise ObjectNotFoundException.new(QuestionPool, id)
    end
    @@cache[id] = QuestionPool.new(row)
  end
  @@cache[id]
end

.find_by_user_id(user_id) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/sakai-info/question_pool.rb', line 49

def self.find_by_user_id(user_id)
  results = []
  DB.connect[:sam_questionpool_t].filter(:ownerid => user_id).all.each do |row|
    id = row[:questionpoolid]
    @@cache[id] = QuestionPool.new(row)
    results << @@cache[id]
  end
  results
end

Instance Method Details

#default_serializationObject

serialization



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sakai-info/question_pool.rb', line 75

def default_serialization
  result = {
    "id" => self.id,
    "title" => self.title,
    "owner" => self.owner.serialize(:summary),
    "parent" => nil,
    "item_count" => self.item_count
  }
  if not self.parent.nil?
    result["parent"] = self.parent.serialize(:summary)
  else
    result.delete("parent")
  end
  result
end

#item_countObject



63
64
65
66
# File 'lib/sakai-info/question_pool.rb', line 63

def item_count
  @item_count ||=
    DB.connect[:sam_questionpoolitem_t].filter(:questionpoolid => @id).count
end

#parentObject



68
69
70
71
72
# File 'lib/sakai-info/question_pool.rb', line 68

def parent
  if not @parent_pool_id.nil?
    @parent ||= QuestionPool.find(@parent_pool_id)
  end
end

#summary_serializationObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/sakai-info/question_pool.rb', line 91

def summary_serialization
  result = {
    "id" => self.id,
    "title" => self.title,
    "owner_eid" => self.owner.eid,
    "parent_pool_id" => self.parent_pool_id,
    "item_count" => self.item_count
  }
  if result["parent_pool_id"].nil?
    result.delete("parent_pool_id")
  end
  result
end

#user_summary_serializationObject



105
106
107
108
109
110
111
# File 'lib/sakai-info/question_pool.rb', line 105

def user_summary_serialization
  {
    "id" => self.id,
    "title" => self.title,
    "item_count" => self.item_count
  }
end