lib/publish_job.rb
#
# Update the assignments of people from the unpublished item to the published item
#
Update the assignments of people from the unpublished item to the published item
Update the assignments of people from the unpublished item to the published item
def updateAssignments(src, dest)
    if src.programme_item_assignments
      src.programme_item_assignments.each do |srcAssignment|
        if !srcAssignment.destroyed?
          if (dest.people == nil) || (dest.people.index(srcAssignment.person) == nil)
            if (srcAssignment.role != PersonItemRole['Reserved']  && srcAssignment.role != PersonItemRole['Invisible'] )
              assignment = dest.published_programme_item_assignments.new(:person => srcAssignment.person, 
                                      :role => srcAssignment.role, 
                                      :sort_order => srcAssignment.sort_order,
                                      :description => srcAssignment.description,
                                      :person_name => srcAssignment.person.getFullPublicationName)
              assignment.save
            end
          else 
            idx = dest.published_programme_item_assignments.index{ |a| (a.person == srcAssignment.person) && ((a.role != srcAssignment.role) || (a.sort_order != srcAssignment.sort_order))}
            if idx != nil && !dest.published_programme_item_assignments[idx].destroyed?
              if (srcAssignment.role == PersonItemRole['Reserved']) || (srcAssignment.role == PersonItemRole['Invisible'])
                dest.published_programme_item_assignments[idx].destroy
              else  
                dest.published_programme_item_assignments[idx].role = srcAssignment.role
                dest.published_programme_item_assignments[idx].description = srcAssignment.description
                dest.published_programme_item_assignments[idx].sort_order = srcAssignment.sort_order
                dest.published_programme_item_assignments[idx].save
              end
            end
          end
        end
      end
      dest.published_programme_item_assignments.each do |pitem|
        if (src.people.index(pitem.person) == nil)
          pitem.destroy
        end
      end
    else 
      if dest.published_programme_item_assignments
        dest.published_programme_item_assignments.destroy
      end
    end
  end
def updateAssignments ( src , dest ) if src . programme_item_assignments src . programme_item_assignments . each do | srcAssignment | if ! srcAssignment . destroyed? if ( dest . people == nil ) || ( dest . people . index ( srcAssignment . person ) == nil ) if ( srcAssignment . role != PersonItemRole [ 'Reserved' ] && srcAssignment . role != PersonItemRole [ 'Invisible' ] ) assignment = dest . published_programme_item_assignments . new ( :person => srcAssignment . person , :role => srcAssignment . role , :sort_order => srcAssignment . sort_order , :description => srcAssignment . description , :person_name => srcAssignment . person . getFullPublicationName ) assignment . save end else idx = dest . published_programme_item_assignments . index { | a | ( a . person == srcAssignment . person ) && ( ( a . role != srcAssignment . role ) || ( a . sort_order != srcAssignment . sort_order ) ) } if idx != nil && ! dest . published_programme_item_assignments [ idx ] . destroyed? if ( srcAssignment . role == PersonItemRole [ 'Reserved' ] ) || ( srcAssignment . role == PersonItemRole [ 'Invisible' ] ) dest . published_programme_item_assignments [ idx ] . destroy else dest . published_programme_item_assignments [ idx ] . role = srcAssignment . role dest . published_programme_item_assignments [ idx ] . description = srcAssignment . description dest . published_programme_item_assignments [ idx ] . sort_order = srcAssignment . sort_order dest . published_programme_item_assignments [ idx ] . save end end end end end dest . published_programme_item_assignments . each do | pitem | if ( src . people . index ( pitem . person ) == nil ) pitem . destroy end end else if dest . published_programme_item_assignments dest . published_programme_item_assignments . destroy end end end
Update the assignments of people from the unpublished item to the published item
Update the assignments of people from the unpublished item to the published item
# add the person only if the destination does not have that person # check their role for reserved, if reserved then we do not want that person published # the destination has the person, but their role may have changed # TODO - if the person is assigned twice we need to deal with it correctly... i.e. participant and reserved # find the index of the person only if the role and sort order are also different # If the role is changed to reserved or invisible then they should be removed... # if the destination has a person that the source does not then we need to remove that assignment # since there are no source assignments we should then remove all the destination assignments (if there are any)
src
<not_specific>
dest
<not_specific>