// Get the company repository
$repo = EntityManager::getInstance()->getRepository('company');
// For each row we need to insert
foreach ($this->input as $row) {
// Find a company
$company = $repo->findOneBy(['ticker' => $row['Ticker']]);
if ($company == null) {
$warnings[] = $row['Ticker'] . ' could not be found in the database';
continue;
}
// Create a collection of embedded docs
$financials = new Collection();
// For each key -> value we need to insert
foreach ($row as $key => $value) {
// Create new embedded doc
$doc = new DataObject('financials');
$doc->setKey($key);
$doc->setValue($value);
// Set the staff ID to the ID of whoever is
// logged in
$doc->setIdStaff(Auth::user()->id);
// Add the doc to the collection
$financials->add($doc);
}
// Add the collection of financials to the company
$repo->updateEmbeddedCollection($financials, $company);
}