Skip to content

Commit

Permalink
Fixed a bug where emergency contacts were not being copied over to th…
Browse files Browse the repository at this point in the history
…e next term. (#389)

Allow for emergency contacts to be carried over when an internship is carried over to the next term.
  • Loading branch information
tylercraig9332 authored and caldwellc1 committed Sep 14, 2018
1 parent 1b775bf commit 5cd6c13
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions class/Command/CopyInternshipToNextTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
use \Intern\InternshipFactory;
use \Intern\WorkflowStateFactory;
use \Intern\TermFactory;
use \Intern\EmergencyContactFactory;
use \Intern\EmergencyContact;
use \Intern\DatabaseStorage;

/**
* Controller class to save a copy of an Internship for the next term
Expand All @@ -43,6 +46,9 @@ public function execute()
// Load the existing internship using its ID
$internship = InternshipFactory::getInternshipById($_REQUEST['internshipId']);

// Load the emergency contacts from the old internship
$contacts = EmergencyContactFactory::getContactsForInternship($internship);

// Clear the ID so that insert a new internship into the database the
// next time we call save()
$internship->setId(null);
Expand All @@ -67,6 +73,19 @@ public function execute()
// Save the new internship
$copyId = $internship->save();

// Copy over the emergency contacts
foreach ($contacts as &$contact) {

$name = $contact->getName($copyId);
$relation = $contact->getRelation($copyId);
$phone = $contact->getPhone($copyId);
$email = $contact->getEmail($copyId);

$newContact = new EmergencyContact($internship, $name, $relation, $phone, $email);
DatabaseStorage::save($newContact);
}


// Show message if user edited internship
\NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, 'Continued internship for ' . $internship->getFullName() . ' to ' . $newTerm->getDescription() . '.');
\NQ::close();
Expand Down

0 comments on commit 5cd6c13

Please sign in to comment.