-
-
Save lorenzo/8ccab7499f3390574a04fef0cb92dfb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!empty($this->request->data('applications.companies_ids'))) { | |
// Recupero gli ids delle aziende a cui l'agente si è candidato | |
$companiesIds = array_diff( | |
$this->request->data('applications.companies_ids'), | |
(new Collection($agent->applications))->extract('company_id')->toArray() | |
); | |
if (!empty($companiesIds)) { | |
$newCompanies = $this->Companies->find() | |
->contain(['Sectors']) | |
->where(['Companies.id IN' => $companiesIds]) | |
->all(); | |
foreach ($newCompanies as $company) { | |
$application = $this->Applications->newEntity([ | |
'agent_id' => $agent->get('id') | |
], ['associated' => ['Companies.Sectors']]); | |
$application->company = $company; | |
$agent->applications[] = $application; | |
} | |
} | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment