app/models/harvest_event.rb
# TODO: THIS IS HORRIBLE! AUGH! NOTE: it is only called from
# FeedController#partner_curation, which is also horrible. We might not need
# this anymore... if we do, it should probably be re-written _entirely_. :\
THIS IS HORRIBLE. AUGH. NOTE: it is only called from
FeedController#partner_curation, which is also horrible. We might not need
this anymore... if we do, it should probably be re-written _entirely_.
THIS IS HORRIBLE . AUGH . NOTE : it is only called from FeedController#partner_curation which is also horrible . We might not need this anymore ... if we do it should probably be re - written _entirely_ .
def curated_data_objects(params = {})
    year = params[:year] || nil
    month = params[:month] || nil
    unless year || month
      year = Time.now.year if year.nil?
      month = Time.now.month if month.nil?
    end
    year = Time.now.year if year.nil?
    month = 0 if month.nil?
    lower_date_range = "#{year}-#{month}-00"
    if month.to_i == 0
      upper_date = Time.local(year, 1) + 1.year
      upper_date_range = "#{upper_date.year}-#{upper_date.month}-00"
    else
      upper_date = Time.local(year, month) + 1.month
      upper_date_range = "#{upper_date.year}-#{upper_date.month}-00"
    end
    date_condition = ""
    if lower_date_range
      date_condition = "AND curator_activity_logs.updated_at BETWEEN '#{lower_date_range}' AND '#{upper_date_range}'"
    end
    curator_activity_logs = CuratorActivityLog.find(:all,
      joins: "JOIN #{DataObjectsHarvestEvent.full_table_name} dohe ON (curator_activity_logs.data_object_guid=dohe.guid)",
      conditions: "curator_activity_logs.activity_id IN (#{Activity.trusted.id}, #{Activity.untrusted.id}, #{Activity.hide.id}, #{Activity.show.id}) AND curator_activity_logs.changeable_object_type_id IN (#{ChangeableObjectType.data_object_scope.join(',')}) AND dohe.harvest_event_id = #{id} #{date_condition}",
      select: 'id')
    curator_activity_logs = CuratorActivityLog.find_all_by_id(curator_activity_logs.collect{ |ah| ah.id },
      include: [ :user, :comment, :activity, :changeable_object_type, :data_object  ],
      select: {
        users: [ :id, :given_name, :family_name ],
        comments: [ :id, :user_id, :body ],
        data_objects: [ :id, :object_cache_url, :source_url, :data_type_id, :published, :created_at ] })
    data_objects = curator_activity_logs.collect(&:data_object)
    DataObject.replace_with_latest_versions!(data_objects, check_only_published: true, language_id: Language.english.id)
    includes = [ { data_objects_hierarchy_entries: [ { hierarchy_entry: [ :name, :hierarchy, :taxon_concept ] }, :vetted, :visibility ] } ]
    includes << { all_curated_data_objects_hierarchy_entries: [ { hierarchy_entry: [ :name, :hierarchy, :taxon_concept ] }, :vetted, :visibility, :user ] }
    DataObject.preload_associations(data_objects, includes)
    DataObject.preload_associations(data_objects, :users_data_object)
    curator_activity_logs.each do |cal|
      if d = data_objects.detect { |o| cal.data_object.guid == o.guid }
        cal.data_object = d
      end
    end
    curator_activity_logs.sort_by { |ah| Invert(ah.id) }
  end
def curated_data_objects ( params = { } ) year = params [ :year ] || nil month = params [ :month ] || nil unless year || month year = Time . now . year if year . nil? month = Time . now . month if month . nil? end year = Time . now . year if year . nil? month = 0 if month . nil? lower_date_range = "#{year}-#{month}-00" if month . to_i == 0 upper_date = Time . local ( year , 1 ) + 1 . year upper_date_range = "#{upper_date.year}-#{upper_date.month}-00" else upper_date = Time . local ( year , month ) + 1 . month upper_date_range = "#{upper_date.year}-#{upper_date.month}-00" end date_condition = "" if lower_date_range date_condition = "AND curator_activity_logs.updated_at BETWEEN '#{lower_date_range}' AND '#{upper_date_range}'" end curator_activity_logs = CuratorActivityLog . find ( :all , joins : "JOIN #{DataObjectsHarvestEvent.full_table_name} dohe ON (curator_activity_logs.data_object_guid=dohe.guid)" , conditions : "curator_activity_logs.activity_id IN (#{Activity.trusted.id}, #{Activity.untrusted.id}, #{Activity.hide.id}, #{Activity.show.id}) AND curator_activity_logs.changeable_object_type_id IN (#{ChangeableObjectType.data_object_scope.join(',')}) AND dohe.harvest_event_id = #{id} #{date_condition}" , select : 'id' ) curator_activity_logs = CuratorActivityLog . find_all_by_id ( curator_activity_logs . collect { | ah | ah . id } , include : [ :user , :comment , :activity , :changeable_object_type , :data_object ] , select : { users : [ :id , :given_name , :family_name ] , comments : [ :id , :user_id , :body ] , data_objects : [ :id , :object_cache_url , :source_url , :data_type_id , :published , :created_at ] } ) data_objects = curator_activity_logs . collect ( & :data_object ) DataObject . replace_with_latest_versions! ( data_objects , check_only_published : true , language_id : Language . english . id ) includes = [ { data_objects_hierarchy_entries : [ { hierarchy_entry : [ :name , :hierarchy , :taxon_concept ] } , :vetted , :visibility ] } ] includes << { all_curated_data_objects_hierarchy_entries : [ { hierarchy_entry : [ :name , :hierarchy , :taxon_concept ] } , :vetted , :visibility , :user ] } DataObject . preload_associations ( data_objects , includes ) DataObject . preload_associations ( data_objects , :users_data_object ) curator_activity_logs . each do | cal | if d = data_objects . detect { | o | cal . data_object . guid == o . guid } cal . data_object = d end end curator_activity_logs . sort_by { | ah | Invert ( ah . id ) } end
TODO: THIS IS HORRIBLE!
TODO : THIS IS HORRIBLE!
params
<not_specific>