/** * @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]; }
/** * @param Affiliation $affiliation * * @return bool */ public function canCreateInvoice(Affiliation $affiliation) { $errors = []; switch (true) { case $affiliation->getOrganisation()->getType()->getInvoice() === Type::NO_INVOICE && !($affiliation->getProject()->getCall()->getProgram()->getId() === 3 && $affiliation->getOrganisation()->getType()->getId() === Type::TYPE_UNIVERSITY): $errors[] = sprintf('No invoice is needed for %s', $affiliation->getOrganisation()->getType()->getDescription()); break; case is_null($affiliation->getFinancial()): $errors[] = 'No financial organisation (affiliation financial) set for this partner'; break; case !is_null($affiliation->getDateEnd()): $errors[] = 'Partner is de-activated'; break; case is_null($affiliation->getFinancial()->getOrganisation()->getFinancial()): $errors[] = 'No financial information set for this organisation'; break; case is_null($affiliation->getFinancial()->getContact()): $errors[] = 'No financial contact set for this organisation'; break; } return $errors; }