Skip to content

Commit 5cd6c13

Browse files
tylercraig9332caldwellc1
authored andcommitted
Fixed a bug where emergency contacts were not being copied over to the next term. (#389)
Allow for emergency contacts to be carried over when an internship is carried over to the next term.
1 parent 1b775bf commit 5cd6c13

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

class/Command/CopyInternshipToNextTerm.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
use \Intern\InternshipFactory;
2424
use \Intern\WorkflowStateFactory;
2525
use \Intern\TermFactory;
26+
use \Intern\EmergencyContactFactory;
27+
use \Intern\EmergencyContact;
28+
use \Intern\DatabaseStorage;
2629

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

49+
// Load the emergency contacts from the old internship
50+
$contacts = EmergencyContactFactory::getContactsForInternship($internship);
51+
4652
// Clear the ID so that insert a new internship into the database the
4753
// next time we call save()
4854
$internship->setId(null);
@@ -67,6 +73,19 @@ public function execute()
6773
// Save the new internship
6874
$copyId = $internship->save();
6975

76+
// Copy over the emergency contacts
77+
foreach ($contacts as &$contact) {
78+
79+
$name = $contact->getName($copyId);
80+
$relation = $contact->getRelation($copyId);
81+
$phone = $contact->getPhone($copyId);
82+
$email = $contact->getEmail($copyId);
83+
84+
$newContact = new EmergencyContact($internship, $name, $relation, $phone, $email);
85+
DatabaseStorage::save($newContact);
86+
}
87+
88+
7089
// Show message if user edited internship
7190
\NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, 'Continued internship for ' . $internship->getFullName() . ' to ' . $newTerm->getDescription() . '.');
7291
\NQ::close();

0 commit comments

Comments
 (0)