Class: SakaiInfo::Announcement
- Inherits:
-
SakaiXMLEntity
- Object
- SakaiObject
- SakaiXMLEntity
- SakaiInfo::Announcement
- Defined in:
- lib/sakai-info/announcement.rb
Constant Summary collapse
- @@cache =
{}
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#draft ⇒ Object
readonly
Returns the value of attribute draft.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#pubview ⇒ Object
readonly
Returns the value of attribute pubview.
Attributes inherited from SakaiXMLEntity
#attributes, #properties, #xml, #xmldoc
Attributes inherited from SakaiObject
Class Method Summary collapse
Instance Method Summary collapse
-
#default_serialization ⇒ Object
serialization.
-
#initialize(id, channel, draft, pubview, owner, date, xml) ⇒ Announcement
constructor
raw data constructor.
- #summary_serialization ⇒ Object
Methods inherited from SakaiXMLEntity
all_serializations, #attributes_serialization, #dbrow_serialization, #format_entity_date, #parse_xml, #properties_serialization, #xml_serialization
Methods included from ModProps
Methods inherited from SakaiObject
all_serializations, #dbrow_only_serialization, #dbrow_serialization, #object_type_serialization, #serialize, #to_json, #to_yaml
Constructor Details
#initialize(id, channel, draft, pubview, owner, date, xml) ⇒ Announcement
raw data constructor
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/sakai-info/announcement.rb', line 112 def initialize(id, channel, draft, pubview, owner, date, xml) @id = id @channel = channel @draft = draft @pubview = pubview @owner = owner @date = date @xml = xml parse_xml end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
85 86 87 |
# File 'lib/sakai-info/announcement.rb', line 85 def channel @channel end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
85 86 87 |
# File 'lib/sakai-info/announcement.rb', line 85 def date @date end |
#draft ⇒ Object (readonly)
Returns the value of attribute draft.
86 87 88 |
# File 'lib/sakai-info/announcement.rb', line 86 def draft @draft end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
85 86 87 |
# File 'lib/sakai-info/announcement.rb', line 85 def owner @owner end |
#pubview ⇒ Object (readonly)
Returns the value of attribute pubview.
86 87 88 |
# File 'lib/sakai-info/announcement.rb', line 86 def pubview @pubview end |
Class Method Details
.find(id) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/sakai-info/announcement.rb', line 89 def self.find(id) if @@cache[id].nil? xml = "" row = DB.connect.fetch("select channel_id, draft, pubview, owner, xml, " + "to_char(message_date,'YYYY-MM-DD HH24:MI:SS') as message_date " + "from announcement_message " + "where message_id = ?", id).first if row.nil? raise ObjectNotFoundException.new(Announcement, id) end channel = AnnouncementChannel.find(row[:channel_id]) draft = row[:draft] pubview = row[:pubview] owner = User.find(row[:owner]) date = row[:message_date] REXML::Document.new(row[:xml].read).write(xml, 2) @@cache[id] = Announcement.new(id, channel, draft, pubview, owner, date, xml) end @@cache[id] end |
.find_by_channel_id(channel_id) ⇒ Object
helpers
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/sakai-info/announcement.rb', line 124 def self.find_by_channel_id(channel_id) announcements = [] channel = AnnouncementChannel.find(channel_id) DB.connect.fetch("select message_id, draft, pubview, owner, xml, " + "to_char(message_date,'YYYY-MM-DD HH24:MI:SS') as message_date " + "from announcement_message " + "where channel_id = ?", channel_id) do |row| xml = "" id = row[:message_id] draft = row[:draft] pubview = row[:pubview] owner = User.find(row[:owner]) REXML::Document.new(row[:xml].read).write(xml, 2) date = row[:message_date] @@cache[id] = Announcement.new(id, channel, draft, pubview, owner, date, xml) announcements << @@cache[id] end announcements end |
Instance Method Details
#default_serialization ⇒ Object
serialization
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/sakai-info/announcement.rb', line 147 def default_serialization { "id" => self.id, "date" => self.date, "owner" => self.owner.serialize(:summary), "draft" => self.draft, "pubview" => self.pubview, "channel" => self.channel.serialize(:summary) } end |
#summary_serialization ⇒ Object
158 159 160 161 162 163 |
# File 'lib/sakai-info/announcement.rb', line 158 def summary_serialization { "id" => self.id, "date" => self.date } end |