Class: SakaiInfo::QuestionPool
- Inherits:
-
SakaiObject
- Object
- SakaiObject
- SakaiInfo::QuestionPool
- Includes:
- ModProps
- Defined in:
- lib/sakai-info/question_pool.rb
Instance Attribute Summary collapse
-
#dbrow ⇒ Object
readonly
Returns the value of attribute dbrow.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#parent_pool_id ⇒ Object
readonly
Returns the value of attribute parent_pool_id.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Attributes inherited from SakaiObject
Class Method Summary collapse
- .clear_cache ⇒ Object
- .count_by_user_id(user_id) ⇒ Object
- .find(id) ⇒ Object
- .find_by_user_id(user_id) ⇒ Object
Instance Method Summary collapse
-
#default_serialization ⇒ Object
serialization.
-
#initialize(dbrow) ⇒ QuestionPool
constructor
A new instance of QuestionPool.
- #item_count ⇒ Object
- #parent ⇒ Object
- #summary_serialization ⇒ Object
- #user_summary_serialization ⇒ Object
Methods included from ModProps
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
#dbrow ⇒ Object (readonly)
Returns the value of attribute dbrow.
14 15 16 |
# File 'lib/sakai-info/question_pool.rb', line 14 def dbrow @dbrow end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
14 15 16 |
# File 'lib/sakai-info/question_pool.rb', line 14 def description @description end |
#owner ⇒ Object (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_id ⇒ Object (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 |
#title ⇒ Object (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_cache ⇒ Object
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_serialization ⇒ Object
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_count ⇒ Object
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 |
#parent ⇒ Object
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_serialization ⇒ Object
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_serialization ⇒ Object
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 |