app/controllers/collections_controller.rb
# TODO - review these. There are too many and as a result there's some redundancy in, for example, checking whether the user is logged in on unpublished
# collections
review these. There are too many and as a result there's some redundancy in, for example, checking whether the user is logged in on unpublished
collections
review these . There are too many and as a result there ' s some redundancy in for example checking whether the user is logged in on unpublished collections
def copy_items(options)
    collection_items = collection_items_with_scope(options)
    copy_to_collection = options[:to]
    new_collection_items = []
    old_collection_items = []
    count = 0
    @duplicates = false
    collection_items = CollectionItem.find_all_by_id(collection_items)
    CollectionItem.preload_associations(collection_items, [ :collected_item, :collection ])
    collection_items.each do |collection_item|
      if copy_to_collection.has_item?(collection_item.collected_item)
        @duplicates = true
      else
        old_collection_items << collection_item
        copiable = options[:from].editable_by?(current_user) ?
                     { annotation: collection_item.annotation,
                       sort_field: collection_item.sort_field } : {}
        new_collection_items << { collected_item_id: collection_item.collected_item.id,
                                  collected_item_type: collection_item.collected_item_type,
                                  added_by_user_id: current_user.id }.merge!(copiable)
        count += 1
        log_activity(collection: options[:to], activity: Activity.collect, collection_item: collection_item)
      end
    end
    if new_collection_items.empty?
      @no_items_to_collections ||= []
      @no_items_to_collections << link_to_name(options[:to])
      return([])
    end
    options[:to].collection_items_attributes = new_collection_items
    if options[:to].save
      options[:to].set_relevance
      return old_collection_items
    else
      [flash[:error], I18n.t(:unable_to_copy_items_to_collection_error,
                             name: link_to_name(options[:to]))].compact.join(" ")
    end
  end
def copy_items ( options ) collection_items = collection_items_with_scope ( options ) copy_to_collection = options [ :to ] new_collection_items = [ ] old_collection_items = [ ] count = 0 @duplicates = false collection_items = CollectionItem . find_all_by_id ( collection_items ) CollectionItem . preload_associations ( collection_items , [ :collected_item , :collection ] ) collection_items . each do | collection_item | if copy_to_collection . has_item? ( collection_item . collected_item ) @duplicates = true else old_collection_items << collection_item copiable = options [ :from ] . editable_by? ( current_user ) ? { annotation : collection_item . annotation , sort_field : collection_item . sort_field } : { } new_collection_items << { collected_item_id : collection_item . collected_item . id , collected_item_type : collection_item . collected_item_type , added_by_user_id : current_user . id } . merge! ( copiable ) count += 1 log_activity ( collection : options [ :to ] , activity : Activity . collect , collection_item : collection_item ) end end if new_collection_items . empty? @no_items_to_collections ||= [ ] @no_items_to_collections << link_to_name ( options [ :to ] ) return ( [ ] ) end options [ :to ] . collection_items_attributes = new_collection_items if options [ :to ] . save options [ :to ] . set_relevance return old_collection_items else [ flash [ :error ] , I18n . t ( :unable_to_copy_items_to_collection_error , name : link_to_name ( options [ :to ] ) ) ] . compact . join ( " " ) end end
TODO - review these.
TODO - review these .
# Some data may only be copied when the user has a right to edit them. This avoids some IP problems. # TODO: Add references to copiable items # TODO - gak.  This points to the wrong collection item and needs to be moved to AFTER the save:
options
<not_specific>