2011-07-27 20:34:30 +02:00
|
|
|
class Message < ActiveRecord::Base
|
2011-08-02 23:12:17 +02:00
|
|
|
belongs_to :user
|
2011-08-16 20:05:58 +02:00
|
|
|
belongs_to :folder
|
2011-08-02 23:12:17 +02:00
|
|
|
|
2011-08-24 19:20:13 +02:00
|
|
|
attr_accessor :body
|
|
|
|
|
2011-08-16 20:05:58 +02:00
|
|
|
def self.getPageForUser(user,folder,page,sort_field,sort_dir)
|
2011-08-02 23:12:17 +02:00
|
|
|
|
2011-08-16 20:05:58 +02:00
|
|
|
order = 'date desc'
|
|
|
|
if sort_field
|
|
|
|
if Message.attribute_method?(sort_field) == true
|
|
|
|
order = sort_field
|
|
|
|
sort_dir == 'desc' ? order += ' desc' : sort_dir
|
|
|
|
end
|
|
|
|
end
|
2011-08-02 23:12:17 +02:00
|
|
|
|
2011-08-16 20:05:58 +02:00
|
|
|
Message.paginate :page => page , :per_page => user.prefs.msgs_per_page.to_i, :conditions=> ['user_id = ? and folder_id = ?', user.id,folder.id],:order => order
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.createForUser(user,folder,mess)
|
|
|
|
create(
|
|
|
|
:user_id => user.id,
|
|
|
|
:folder_id => folder.id,
|
|
|
|
:msg_id => mess.message_id,
|
|
|
|
:uid => mess.uid,
|
|
|
|
:from_addr => mess.from_to_db,
|
2011-08-24 19:20:13 +02:00
|
|
|
:to_addr => mess.to_to_db,
|
2011-08-16 20:05:58 +02:00
|
|
|
:subject => mess.subject,
|
|
|
|
:content_type => mess.content_type,
|
|
|
|
:date => mess.date,
|
|
|
|
:unseen => mess.unseen,
|
|
|
|
:size => mess.size)
|
|
|
|
end
|
|
|
|
|
|
|
|
def change_folder(folder)
|
|
|
|
update_attributes(:folder_id => folder.id)
|
2011-08-02 23:12:17 +02:00
|
|
|
end
|
|
|
|
|
2011-07-27 20:34:30 +02:00
|
|
|
end
|