3 # This file is part of SMR.
5 # SMR is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
10 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # SMR. If not, see <http://www.gnu.org/licenses/>.
19 # Collection of most recent SmrBlogItem objects of given User.id.
21 # As of now all items from previous 30 days are collected.
23 def initialize(id_user, end_date=Time.now)
24 @collection = Array.new
26 start_date = (end_date - 30.days).to_i
27 end_date = end_date.to_i
29 # load personal commentary
30 Comment.where(:id_user=>id_user)
31 .where({ :date=>(start_date..end_date) }).each do |c|
32 @collection << SmrBlogItem.new(c.time, c.class, c.title, c.comment, false, c.id)
35 # load order commentary
36 Order.where.not(:comment=>'')
37 .where({ :issued=>(start_date..end_date) })
38 .joins('LEFT JOIN position p ON p.id = order.id_position')
39 .joins('LEFT JOIN portfolio po ON po.id = p.id_portfolio')
40 .where('po.id_user=%i' % id_user).each do |o|
41 @collection << SmrBlogItem.new(o.time_issued, o.class, o.to_s ,o.comment)
44 # load quoterecord commentary
45 Quoterecord.where(:id_user=>id_user)
46 .where({ :created=>(start_date..end_date) })
47 .where.not(:comment=>'').each do |qr|
48 @collection << SmrBlogItem.new(qr.time_created, qr.class, qr.to_s, qr.comment)
51 @collection.sort_by!{|i| i.date}.reverse!
56 # loops over SmrBlogItem collection
58 @collection.each(&block)
62 # tell whether there is anything in the collection
70 # Represents a single SmrBlog item for a template to render.
72 # - +url+ is to link to somewhere in the WWW
73 # - +refid+ is some :id of the object that created this SmrBlogItem, its used
74 # to provide a smr_link_back() to that record.
76 def initialize(date, type, title, body, url=false, refid=false)
77 raise 'date must be of type Time' unless date.is_a?(Time)
79 @date=date; @type=type.to_s; @title=title; @body=body; @url=url;