Class: SakaiInfo::PrivateMessage

Inherits:
GenericMessage show all
Includes:
ModProps
Defined in:
lib/sakai-info/private_message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModProps

included

Methods inherited from GenericMessage

count_by_date_and_message_type, types, valid_message_type?

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

Returns a new instance of PrivateMessage.



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

def initialize(dbrow)
  @dbrow = dbrow

  @dbrow[:body] = dbrow[:body].read
  @dbrow[:recipients_as_text] = dbrow[:recipients_as_text].read

  @id = dbrow[:id].to_i
  @title = dbrow[:title]
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



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

def dbrow
  @dbrow
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.clear_cacheObject



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

def self.clear_cache
  @@cache = {}
end

.count_by_date(d) ⇒ Object



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

def self.count_by_date(d)
  count_by_date_and_message_type(d, "PM")
end

.find(id) ⇒ Object



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

def self.find(id)
  if @@cache[id.to_s].nil?
    row = DB.connect[:mfr_message_t].where(:id => id, :message_dtype => "PM").first
    if row.nil?
      raise ObjectNotFoundException.new(PrivateMessage, id)
    end
    @@cache[id.to_s] = PrivateMessage.new(row)
  end
  @@cache[id.to_s]
end

Instance Method Details

#authorObject



48
49
50
51
52
# File 'lib/sakai-info/private_message.rb', line 48

def author
  # apparently the 'author' field is just a display string?!?
  # as of 2.8, perhaps?
  @author ||= User.find(@dbrow[:created_by])
end

#bodyObject



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

def body
  @dbrow[:body]
end

#default_serializationObject



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

def default_serialization
  {
    "id" => self.id,
    "title" => self.title,
    "author" => self.author.serialize(:summary),
    "body" => self.body,
  }
end

#summary_serializationObject



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

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