Modified: branches/event_logging/app/helpers/application_helper.rb (1879 => 1880)
--- branches/event_logging/app/helpers/application_helper.rb 2008-10-21 17:23:48 UTC (rev 1879)
+++ branches/event_logging/app/helpers/application_helper.rb 2008-10-22 13:49:43 UTC (rev 1880)
@@ -574,41 +574,23 @@
return "#{issn[0..3]}-#{issn[4..7]}"
end
+
+ # A generic caller method / interpreter of results of a true news generation method;
+ #
+ # Parameters:
+ # (default parameters defined in environment_private.rb)
+ # 1) contributor - instance of a User or Network, for which the news are generated
+ # 2) restrict_contributor - when set to "true" will generate news only for the current contributor;
+ # when set to "false" will pick up also all related contributors;
+ # 3-4) before, after - Time objects; the news will be generated in a time slice [after..before]
+ # 5) limit - number of news entries to generate
def news(contributor, restrict_contributor=true, before=Time.now, after=Time.now-1.week, limit=30)
hash = {}
- #contributor_news(contributor, before, after, 0, (restrict_contributor ? contributor : nil)).sort! { |a, b|
- aa = contributor_news_from_log(contributor, before, after, restrict_contributor, false)
+ # news_array = contributor_news(contributor, before, after, 0, (restrict_contributor ? contributor : nil)).sort! { |a, b|
+ news_array = contributor_news_from_log(contributor, before, after, restrict_contributor, false)
- # DEBUG
- #puts "values received:"
- #cnt = 0
- #aa.each do |val|
- # cnt += 1
- # print cnt
- # print " length: "
- # print val.length
- # print "; -> "
- # puts val
- #end
- #puts aa.length
- #puts aa
- #puts "first aa element"
- #puts aa[0].length
- #puts aa[0]
- # DEBUG
- aa.sort! { |a, b|
- # DEBUG
- # puts "\nsort iteration"
- # puts "a"
- # puts a.length
- # puts a
- # puts a[0]
- # puts "b"
- # puts b.length
- # puts b
- # puts b[0]
- # DEBUG
+ news_array.sort! { |a, b|
b[0] <=> a[0]
}[0..limit].each do |news_item|
nearest_day = news_item[0] - (news_item[0].hour.hours + news_item[0].min.minutes + news_item[0].sec.seconds)
@@ -1395,27 +1377,37 @@
protected
-
+ # Produces an array of news items in a form of [timestamp, description string] from ActivityLog table.
+ #
+ # Parameters:
+ # 1) contributor - instance of a User or Network for which the news are generated;
+ # 2) before - Time object, indicating the time before which the events to be displayed (by default called with Time.now)
+ # 3) after - Time object, indicating the time after which the events to be displayed (like a week ago and onwards)
+ # 4) contributor_news_only - set to "true" to get events relevant for the current user only;
+ # OR "false" to get events for friends and group members where contributor is a member of, too
+ # 5) return_raw_events - used for recursive calls; when set to "true" a set of events from ActivityLog table is returned;
+ # "false" will cause the events to be interpreted and returned as news items.
def contributor_news_from_log(contributor, before, after, contributor_news_only, return_raw_events)
- puts "=================================="
- puts "> start news generation from log <"
- puts "> " + contributor.class.to_s + ", ID = " + contributor.id.to_s
- puts "> " + (contributor.class.to_s == "Network" ? contributor.title : contributor.name)
- puts "=================================="
+ # DEBUG
+ # puts "=================================="
+ # puts "> start news generation from log <"
+ # puts "> " + contributor.class.to_s + ", ID = " + contributor.id.to_s
+ # puts "> " + (contributor.class.to_s == "Network" ? contributor.title : contributor.name)
+ # puts "=================================="
+ # END OF DEBUG
- # 1) in the activity log any contributions made / updated / removed by the contributor
- # are marked with their ID in "culprit" field - and so will be picked up by news digest;
- # 2) groups created by the current user would be marked with their ID in "culprit" field;
- # 3) friendships / memberships for the contributor (class=USER) will be picked up, as their
- # ID would be indicated by culprit / referenced field in every record that is relevant for
- # the current contributor;
- # 4) profile picture selections marked with contributor's ID in the "culprit" field;
+ # the news will include:
+ # - any created / updated contributables (files, packs, workflows);
+ # - any groups created by contributor;
+ # - any taggings, ratings, reviews, citations, comments, creditations, attributions made by contributor;
+ # - any permissions given to other users or groups;
- # + news on contributions +
- # + news for friends +
- # + news for members of networks, where current user is member of +
+ # also, the news will include the same set of news for (if "contributor_news_only" parameter set to "false")
+ # - friends;
+ # - members of networks, where current user is member of;
+ # - members of networks, where current user is admin of;
events = []
related_contributors = []
@@ -1423,11 +1415,18 @@
case contributor.class.to_s.downcase
when "user"
unless contributor_news_only
+ # ..add friends
related_contributors.concat(contributor.friends)
+
+ # ..add members of networks, where contributor is admin AND where contributor is member of
contributor.networks.concat(contributor.networks_owned).each do |network|
related_contributors.concat(network.members)
end
+
+ # keep the set of related contributors unique (some users maybe members of multiple related groups)
related_contributors = related_contributors.uniq
+
+ # remove the contributor from the list of related contributors to avoid double processing
related_contributors.delete(contributor)
end
when "network"
@@ -1458,7 +1457,7 @@
# produce news from event list
rtn = []
- news_item = nil # contributo_news_from_log!() will return NIL if event is not to be added to the feed for the current user
+ news_item = nil # contributor_news_from_log!() will return NIL if event is not to be added to the feed for the current user
events.each do |e|
news_item = contributor_news_from_log!(e)
rtn << news_item unless news_item.nil?
@@ -1468,6 +1467,8 @@
end
+ # helper method that interprets event log entries from ActivityLog table into a news entry in a format of
+ # [timestamp, news_entry_string]
def contributor_news_from_log!(log_entry)
rtn = [] # despite this, NIL will be returned on errors / when news entry not to be shown for current user
action = ""
@@ -1864,6 +1865,7 @@
end
+
def evaluate_object_instance_and_path(model_name, id)
# evaluates the instance object and link to the page of it in the UI
instance = eval("#{model_name}.find(#{id})")