app/models/programme_item.rb
#
# Update the item assignments for the given role
#
Update the item assignments for the given role
Update the item assignments for the given role
def update_assignments(updates)
    update_ids = updates.collect{|u| u.id }.compact
    del_candidates = programme_item_assignments.
                          where(["role_id in (?)",[PersonItemRole['Invisible'].id, PersonItemRole['Participant'].id,PersonItemRole['OtherParticipant'].id,PersonItemRole['Moderator'].id,PersonItemRole['Reserved'].id]]).
                          to_a.
                          keep_if{|c| !update_ids.include?(c.id)}
    create_candidates = updates.map{|u| u.id == nil ? u : nil }.compact
    update_candidates = updates.map{|u| u.id != nil ? u : nil }.compact
    if del_candidates
      self.touch if !self.new_record?
      self.save
    end
    del_candidates.each do |c|
      c.destroy
    end
    create_candidates.each do |c|
      assignment = programme_item_assignments.create({role_id: c.role_id, person_id: c.person_id})
      assignment.sort_order_position = c.sort_order_position if c.sort_order_position
      assignment.save
    end
    update_candidates.each do |u|
      assignment = u
      assignment.save
    end
  end
def update_assignments ( updates ) update_ids = updates . collect { | u | u . id } . compact del_candidates = programme_item_assignments . where ( [ "role_id in (?)" , [ PersonItemRole [ 'Invisible' ] . id , PersonItemRole [ 'Participant' ] . id , PersonItemRole [ 'OtherParticipant' ] . id , PersonItemRole [ 'Moderator' ] . id , PersonItemRole [ 'Reserved' ] . id ] ] ) . to_a . keep_if { | c | ! update_ids . include? ( c . id ) } create_candidates = updates . map { | u | u . id == nil ? u : nil } . compact update_candidates = updates . map { | u | u . id != nil ? u : nil } . compact if del_candidates self . touch if ! self . new_record? self . save end del_candidates . each do | c | c . destroy end create_candidates . each do | c | assignment = programme_item_assignments . create ( { role_id : c . role_id , person_id : c . person_id } ) assignment . sort_order_position = c . sort_order_position if c . sort_order_position assignment . save end update_candidates . each do | u | assignment = u assignment . save end end
Update the item assignments for the given role
Update the item assignments for the given role
# find the assignments to remove # find the assignments to create & update # We may not want to delete since the item may be moved to another role ....
updates
<not_specific>