2323use \Intern \InternshipFactory ;
2424use \Intern \WorkflowStateFactory ;
2525use \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