Skip to content

Instantly share code, notes, and snippets.

@lorenzo
Forked from anonymous/test.php
Created July 5, 2016 14:09
Show Gist options
  • Save lorenzo/8ccab7499f3390574a04fef0cb92dfb0 to your computer and use it in GitHub Desktop.
Save lorenzo/8ccab7499f3390574a04fef0cb92dfb0 to your computer and use it in GitHub Desktop.
<?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