Skip to content

Instantly share code, notes, and snippets.

Created July 5, 2016 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/02b46cc41578fd3cb7142231d921c8e8 to your computer and use it in GitHub Desktop.
Save anonymous/02b46cc41578fd3cb7142231d921c8e8 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) {
$agent->applications[] = $this->Applications->newEntity([
'company' => $company,
'agent_id' => $agent->get('id')
], ['associated' => ['Companies', 'Companies.Sectors']]);
}
}
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment