app/models/organizations/organization_quarter.rb
def queue_mid_quarter_emails(action = 'invite', unit = nil)
    send_evals = !placements.filled.empty?
    send_invites = (action == 'invite')
    
    emails = { 'Evaluate only' => [], 'Invite only' => [], 'Invite and Evaluate' => [] }

    # go through each primary contact and add to the two lists
    organization.primary_contacts_for_unit(unit).each do |contact|
      emails['Evaluate only'] << contact if send_evals
      emails['Invite only']   << contact if send_invites
    end
    
    # add all the position supervisors and primary contacts to the eval list
    if send_evals
      emails['Evaluate only'] << placements.filled.collect(&:position).collect(&:supervisor)
      emails['Evaluate only'] << organization.primary_contacts_for_unit(unit)
    end
    
    # flatten the hashes
    emails['Evaluate only'] = emails['Evaluate only'].flatten.uniq.compact
    emails['Invite only']   = emails['Invite only'].flatten.uniq.compact
    
    # clean up to create the evals + invites list
    emails['Evaluate only'].each do |e|
      if emails['Invite only'].include?(e)
        emails['Invite and Evaluate'] << e
        emails['Invite only'].delete(e)
        emails['Evaluate only'].delete(e)
      end
    end

    # Define the command after delivery
    if action == 'invite'
      command_after_delivery = "Organization.find(#{organization.id}).activate_for(Quarter.find(#{quarter.next.id}), true, #{unit.id})"
    else
      command_after_delivery = "Organization.find(#{organization.id}).mark_inactive"
    end

    # send the emails
    emails.each do |type, recipients|
      recipients.each do |r|
        tmail_object = MID_QUARTER_EMAIL_TEMPLATES[type].create_email_to(r)
        EmailQueue.queue(r.person_id, tmail_object, nil, command_after_delivery)
        @emails_sent = true
      end
    end
    
    # Mark inactive if not inviting for next quarter -- this takes care of organizations that don't get any emails (and therefore
    # the command_after_delivery wouldn't be executed)
    organization.mark_inactive if action != 'invite' && !@emails_sent

  end
# Sends mid-quarter e-mails to this organization and activates or deactives for the next quarter. If the paramater is passed as
# 'invite' then the organization will be activated for the next quarter. Otherwise, it will be marked as inactive.
# This creates two potential sets of emails: evaluation emails and 
# invitation emails. Evaluation emails get sent if there are any currently-placed students. Invitation emails get sent
# if this organization is being invited for the next quarter.
Sends mid-quarter e-mails to this organization and activates or deactives for the next quarter. If the paramater is passed as
'invite' then the organization will be activated for the next quarter. Otherwise, it will be marked as inactive.
This creates two potential sets of emails: evaluation emails and
invitation emails. Evaluation emails get sent if there are any currently-placed students. Invitation emails get sent
if this organization is being invited for the next quarter.
Sends mid - quarter e - mails to this organization and activates or deactives for the next quarter . If the paramater is passed as ' invite ' then the organization will be activated for the next quarter . Otherwise it will be marked as inactive . This creates two potential sets of emails : evaluation emails and invitation emails . Evaluation emails get sent if there are any currently - placed students . Invitation emails get sent if this organization is being invited for the next quarter .
def queue_mid_quarter_emails(action = 'invite', unit = nil)
    send_evals = !placements.filled.empty?
    send_invites = (action == 'invite')
    emails = { 'Evaluate only' => [], 'Invite only' => [], 'Invite and Evaluate' => [] }
    organization.primary_contacts_for_unit(unit).each do |contact|
      emails['Evaluate only'] << contact if send_evals
      emails['Invite only']   << contact if send_invites
    end
    if send_evals
      emails['Evaluate only'] << placements.filled.collect(&:position).collect(&:supervisor)
      emails['Evaluate only'] << organization.primary_contacts_for_unit(unit)
    end
    emails['Evaluate only'] = emails['Evaluate only'].flatten.uniq.compact
    emails['Invite only']   = emails['Invite only'].flatten.uniq.compact
    emails['Evaluate only'].each do |e|
      if emails['Invite only'].include?(e)
        emails['Invite and Evaluate'] << e
        emails['Invite only'].delete(e)
        emails['Evaluate only'].delete(e)
      end
    end
    if action == 'invite'
      command_after_delivery = "Organization.find(#{organization.id}).activate_for(Quarter.find(#{quarter.next.id}), true, #{unit.id})"
    else
      command_after_delivery = "Organization.find(#{organization.id}).mark_inactive"
    end
    emails.each do |type, recipients|
      recipients.each do |r|
        tmail_object = MID_QUARTER_EMAIL_TEMPLATES[type].create_email_to(r)
        EmailQueue.queue(r.person_id, tmail_object, nil, command_after_delivery)
        @emails_sent = true
      end
    end
    organization.mark_inactive if action != 'invite' && !@emails_sent
  end
def queue_mid_quarter_emails ( action = 'invite' , unit = nil ) send_evals = ! placements . filled . empty? send_invites = ( action == 'invite' ) emails = { 'Evaluate only' => [ ] , 'Invite only' => [ ] , 'Invite and Evaluate' => [ ] } organization . primary_contacts_for_unit ( unit ) . each do | contact | emails [ 'Evaluate only' ] << contact if send_evals emails [ 'Invite only' ] << contact if send_invites end if send_evals emails [ 'Evaluate only' ] << placements . filled . collect ( & :position ) . collect ( & :supervisor ) emails [ 'Evaluate only' ] << organization . primary_contacts_for_unit ( unit ) end emails [ 'Evaluate only' ] = emails [ 'Evaluate only' ] . flatten . uniq . compact emails [ 'Invite only' ] = emails [ 'Invite only' ] . flatten . uniq . compact emails [ 'Evaluate only' ] . each do | e | if emails [ 'Invite only' ] . include? ( e ) emails [ 'Invite and Evaluate' ] << e emails [ 'Invite only' ] . delete ( e ) emails [ 'Evaluate only' ] . delete ( e ) end end if action == 'invite' command_after_delivery = "Organization.find(#{organization.id}).activate_for(Quarter.find(#{quarter.next.id}), true, #{unit.id})" else command_after_delivery = "Organization.find(#{organization.id}).mark_inactive" end emails . each do | type , recipients | recipients . each do | r | tmail_object = MID_QUARTER_EMAIL_TEMPLATES [ type ] . create_email_to ( r ) EmailQueue . queue ( r . person_id , tmail_object , nil , command_after_delivery ) @emails_sent = true end end organization . mark_inactive if action != 'invite' && ! @emails_sent end
Sends mid-quarter e-mails to this organization and activates or deactives for the next quarter.
Sends mid - quarter e - mails to this organization and activates or deactives for the next quarter .
# go through each primary contact and add to the two lists # add all the position supervisors and primary contacts to the eval list # flatten the hashes # clean up to create the evals + invites list # Define the command after delivery # send the emails # Mark inactive if not inviting for next quarter -- this takes care of organizations that don't get any emails (and therefore # the command_after_delivery wouldn't be executed)
action
unit