Class: SakaiInfo::Announcement

Inherits:
SakaiObject show all
Defined in:
lib/sakai-info/announcement.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) ⇒ Announcement

Returns a new instance of Announcement.



115
116
117
118
119
120
121
122
123
124
# File 'lib/sakai-info/announcement.rb', line 115

def initialize(dbrow)
  @dbrow = dbrow

  @id = @dbrow[:message_id]
  @channel_id = @dbrow[:channel_id]
  @draft = @dbrow[:draft]
  @pubview = @dbrow[:pubview]
  @owner = User.find(@dbrow[:owner])
  @date = @dbrow[:message_date]
end

Instance Attribute Details

#channel_idObject (readonly)

Returns the value of attribute channel_id.



108
109
110
# File 'lib/sakai-info/announcement.rb', line 108

def channel_id
  @channel_id
end

#dateObject (readonly)

Returns the value of attribute date.



108
109
110
# File 'lib/sakai-info/announcement.rb', line 108

def date
  @date
end

#dbrowObject (readonly)

Returns the value of attribute dbrow.



108
109
110
# File 'lib/sakai-info/announcement.rb', line 108

def dbrow
  @dbrow
end

#draftObject (readonly)

Returns the value of attribute draft.



108
109
110
# File 'lib/sakai-info/announcement.rb', line 108

def draft
  @draft
end

#ownerObject (readonly)

Returns the value of attribute owner.



108
109
110
# File 'lib/sakai-info/announcement.rb', line 108

def owner
  @owner
end

#pubviewObject (readonly)

Returns the value of attribute pubview.



108
109
110
# File 'lib/sakai-info/announcement.rb', line 108

def pubview
  @pubview
end

Class Method Details

.all_serializationsObject



189
190
191
192
193
194
# File 'lib/sakai-info/announcement.rb', line 189

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

.clear_cacheObject



110
111
112
# File 'lib/sakai-info/announcement.rb', line 110

def self.clear_cache
  @@cache = {}
end

.count_by_channel_id(channel_id) ⇒ Object



141
142
143
# File 'lib/sakai-info/announcement.rb', line 141

def self.count_by_channel_id(channel_id)
  Announcement.query_by_channel_id(channel_id).count
end

.find(id) ⇒ Object



126
127
128
129
130
131
132
133
134
135
# File 'lib/sakai-info/announcement.rb', line 126

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

.find_by_channel_id(channel_id) ⇒ Object



145
146
147
148
149
# File 'lib/sakai-info/announcement.rb', line 145

def self.find_by_channel_id(channel_id)
  Announcement.query_by_channel_id(channel_id).all.collect do |row|
    @@cache[row[:message_id]] = Announcement.new(row)
  end
end

.query_by_channel_id(channel_id) ⇒ Object



137
138
139
# File 'lib/sakai-info/announcement.rb', line 137

def self.query_by_channel_id(channel_id)
  DB.connect[:announcement_message].where(:channel_id => channel_id)
end

Instance Method Details

#channelObject

lazy properties



152
153
154
# File 'lib/sakai-info/announcement.rb', line 152

def channel
  @channel ||= AnnouncementChannel.find(self.channel_id)
end

#default_serializationObject

serialization



165
166
167
168
169
170
171
172
173
174
# File 'lib/sakai-info/announcement.rb', line 165

def default_serialization
  {
    "id" => self.id,
    "date" => self.date,
    "owner" => self.owner.serialize(:summary),
    "draft" => self.draft,
    "pubview" => self.pubview,
    "channel" => self.channel_id,
  }
end

#summary_serializationObject



176
177
178
179
180
181
# File 'lib/sakai-info/announcement.rb', line 176

def summary_serialization
  {
    "id" => self.id,
    "date" => self.date
  }
end

#xmlObject



156
157
158
159
160
161
162
# File 'lib/sakai-info/announcement.rb', line 156

def xml
  if @xml.nil?
    @xml = ""
    REXML::Document.new(@dbrow[:xml].read).write(@xml, 2)
  end
  @xml
end

#xml_serializationObject



183
184
185
186
187
# File 'lib/sakai-info/announcement.rb', line 183

def xml_serialization
  {
    "xml" => self.xml
  }
end