Class: SakaiInfo::AnnouncementChannel

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

Returns a new instance of AnnouncementChannel.



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

def initialize(dbrow)
  @dbrow = dbrow
  @id = dbrow[:channel_id]
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



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

def dbrow
  @dbrow
end

Class Method Details

.all_serializationsObject



98
99
100
101
102
103
104
# File 'lib/sakai-info/announcement.rb', line 98

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

.clear_cacheObject



16
17
18
19
# File 'lib/sakai-info/announcement.rb', line 16

def self.clear_cache
  @@cache = {}
  @@site_cache = {}
end

.find(id) ⇒ Object



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

def self.find(id)
  if @@cache[id].nil?
    xml = ""
    row = DB.connect[:announcement_channel].where(:channel_id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(AnnouncementChannel, id)
    end
    @@cache[id] = AnnouncementChannel.new(row)
    @@site_cache[@@cache[id].site_id] = @@cache[id]
  end
  @@cache[id]
end

.find_by_site_id(site_id) ⇒ Object



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

def self.find_by_site_id(site_id)
  @@site_cache[site_id] ||=
    if site_id == "!site"
      self.find("/announcement/channel/#{site_id}/motd")
    else
      self.find("/announcement/channel/#{site_id}/main")
    end
end

Instance Method Details

#announcement_countObject



54
55
56
# File 'lib/sakai-info/announcement.rb', line 54

def announcement_count
  @announcement_count ||= Announcement.count_by_channel_id(@id)
end

#announcementsObject

lazy properties



50
51
52
# File 'lib/sakai-info/announcement.rb', line 50

def announcements
  @announcements ||= Announcement.find_by_channel_id(@id)
end

#announcements_serializationObject



92
93
94
95
96
# File 'lib/sakai-info/announcement.rb', line 92

def announcements_serialization
  {
    "announcements" => self.announcements.collect { |ann| ann.serialize(:summary) }
  }
end

#default_serializationObject

serialization



71
72
73
74
75
76
77
# File 'lib/sakai-info/announcement.rb', line 71

def default_serialization
  {
    "id" => self.id,
    "site_id" => self.site_id,
    "announcement_count" => self.announcement_count
  }
end

#site_idObject



58
59
60
# File 'lib/sakai-info/announcement.rb', line 58

def site_id
  @site_id ||= @id.split("/")[3]
end

#summary_serializationObject



79
80
81
82
83
84
# File 'lib/sakai-info/announcement.rb', line 79

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

#xmlObject



62
63
64
65
66
67
68
# File 'lib/sakai-info/announcement.rb', line 62

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

#xml_serializationObject



86
87
88
89
90
# File 'lib/sakai-info/announcement.rb', line 86

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