Modified: branches/event_logging/app/helpers/application_helper.rb (1908 => 1909)
--- branches/event_logging/app/helpers/application_helper.rb 2008-10-30 15:55:30 UTC (rev 1908)
+++ branches/event_logging/app/helpers/application_helper.rb 2008-10-30 18:01:01 UTC (rev 1909)
@@ -1482,7 +1482,7 @@
# (no need to impose order on the DB query, as more queries will be run [for "related_contributors"]
# and subsequent sorting will be required anyway)
events = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND ((activity_loggable_type = ? AND activity_loggable_id = ?) OR (culprit_type = ? AND culprit_id = ?) OR (referenced_type = ? AND referenced_id = ?))", after, before, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id])
- events.concat(events_as_admin) unless events_as_admin.empty?
+ events.concat(events_as_admin)
# if any "related_contributors", get events for each
# (can't use the "limit" parameter just yet, because events for "related_contributors" may be newer
@@ -1490,26 +1490,68 @@
events_for_related_contributor = []
related_contributors.each do |c|
events_for_related_contributor = contributor_news_from_log(c, before, after, true, true, limit, current_viewer)
- events.concat(events_for_related_contributor) unless events_for_related_contributor.empty?
+ events.concat(events_for_related_contributor)
end
return events if return_raw_events
- # NB! only if this is the "home" page, not the profile page
- unless contributor_news_only
- # all recursive calls are finished by this point - now can add site announcements to the event list;
- # (this user with no friends who are site admins AND who is not a member of any groups, where site admins are
- # members too, will still get news entries about site announcements - which is very important
+ # ===========================================================
+ # ALL RECURSIVE CALLS HAVE ALREADY TERMINATED BY THIS POINT
+ # ===========================================================
+
+ # The recursive part of the method is dedicated for building
+ # a people-centered network of events related to the "contributor";
+ # another major part is building the resource centered network
+ # of events - this should include events related to contributables
+ # belonging to the user, favourited by the user, etc
+
+ # NB! only if this is the user's "home" page, not the profile page
+ unless contributor_news_only || contributor.class.to_s != "User"
+ # ==== Announcements ====
+ # add site announcements to the event list; (this user with no friends who are site admins AND
+ # who is not a member of any groups, where site admins are members too, will still get news
+ # entries about site announcements - which is very important
site_announcements = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND activity_loggable_type = ?", after, before, "Announcement"])
events.concat(site_announcements)
+
+
+ # ==== User's Items ====
+ # get hold of all the items belonging to the current user
+ # array initialization statement needed to avoid ActiveRecord::AssociationTypeMismatch exception
+ users_stuff = []
+ users_stuff.concat(contributor.workflows)
+ users_stuff.concat(contributor.blobs)
+ users_stuff.concat(contributor.packs)
+
+ # also, fetch user's favourites
+ contributor.bookmarks.each do |favourite|
+ users_stuff.concat([favourite.bookmarkable])
+ end
+
+ # there might be overlap between user's contributables and favourites
+ # (because it's allowed to favourite own contributables)
+ users_stuff = users_stuff.uniq
+
+ # get events log entries for all the user's items
+ users_stuff.each do |thing|
+ users_stuff_events = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND ((activity_loggable_type = ? AND activity_loggable_id = ?) OR (referenced_type = ? AND referenced_id = ?))", after, before, thing.class.to_s, thing.id, thing.class.to_s, thing.id])
+ events.concat(users_stuff_events)
+ end
+
end
+ # ============================================================
+ # ALL RELEVANT EVENT LOG ENTRIES HAVE BEEN FETCHED UP TO NOW
+ # ============================================================
+
+
# remove any duplicates (which may arise when getting same event log entry from friends' related events),
- # then sort by date descending
+ # then sort by date descending; then delete a single (only possible after "uniq") empty element
events = events.uniq.sort { |a, b|
b.created_at <=> a.created_at
}
+ events.delete([])
# produce news from event list
rtn = []