/** * @param Affiliation $affiliation * * @return array */ public function findContactsInAffiliation(Affiliation $affiliation) { $contacts = []; $contactRole = []; /* * Add the technical contact */ $contacts[$affiliation->getContact()->getId()] = $affiliation->getContact(); $contactRole[$affiliation->getContact()->getId()][] = 'Technical Contact'; /* * Add the financial contact */ if (!is_null($affiliation->getFinancial())) { $contacts[$affiliation->getFinancial()->getContact()->getId()] = $affiliation->getFinancial()->getContact(); $contactRole[$affiliation->getFinancial()->getContact()->getId()][] = 'Financial Contact'; } /* * Add the associates */ foreach ($affiliation->getAssociate() as $associate) { /* * Add the associates */ $contacts[$associate->getId()] = $associate; $contactRole[$associate->getId()][] = 'Associate'; } /* * Add the workpackage leaders */ foreach ($affiliation->getProject()->getWorkpackage() as $workpackage) { /* * Add the work package leaders */ if (!is_null($workpackage->getContact()->getContactOrganisation()) && $workpackage->getContact()->getContactOrganisation()->getOrganisation()->getId() === $affiliation->getOrganisation()->getId()) { $contacts[$workpackage->getContact()->getId()] = $workpackage->getContact(); $contactRole[$workpackage->getContact()->getId()][] = 'Workpackage leader'; } } $contactRole = array_map('array_unique', $contactRole); //Store the values local for the use of the toArray function $this->contacts = $contacts; return ['contacts' => $contacts, 'contactRole' => $contactRole]; }