/** * Stores a document and its isbns in the database * * @param $filename * @param array $isbns * @return boolean */ public function saveDocumentWithIsbns($filename, array $isbns) { if (!is_null($filename && !is_null($isbns))) { $file = new Document(); $file->setName($filename); $bookArray = []; foreach ($isbns as $isbn) { $bookRepo = $this->_em->getRepository('AppBundle:Book'); $book = $bookRepo->findBy(array('isbn13' => $isbn)); if (!is_null($book) && array_key_exists(0, $book)) { $bookArray[] = $book[0]; //$file->addBook($book[0]); } } $bookArray = $this->deleteRepeatedBooksInArray($bookArray); foreach ($bookArray as $book) { $file->addBook($book); } $this->add($file); return true; } return false; }