private function addDocumentForm($form, $document) { $database = new DBConnection($this->app); if (is_string($document)) { $qb = $document; } elseif (is_numeric($document)) { $qb = $database->findDocumentNameById($document); } else { $qb = $database->findAllDocuments(); } $form->add($this->factory->createNamed('files', 'choice', null, array('empty_value' => 'Empty', 'auto_initialize' => false, 'choices' => ['Files' => $qb]))); /*$form->add($this->factory->createNamed('files', 'choice', null, [ 'choices' => ['Files' => $document], 'label' => 'Files', ]));*/ }
/** * Find books by isbns * * @param array $isbns * * @param Application $app * * @return array */ public function find(array $isbns, Application $app) { if (is_array($isbns)) { $data = []; $database = new DBConnection($app); foreach ($isbns as $isbn) { $q = Constants::GOOGLE_BOOKS_QUERY . $isbn; $result = $this->booksApi->volumes->listVolumes($q, $this->params); $items = $result->getItems(); if (count($items) > 0) { $volumeInfo = $items[0]->getVolumeInfo(); $book = $this->buildBookWithApiInfo($volumeInfo); $database->insertNewBook($book); $data[] = $book; } } return $data; } }
if ($download->isValid()) { $data = $download->getData(); $filename = $documentsArray[$data['files']]; $books = $database->findBooksFromFilename($filename); ExcelWorker::createExcelDocument($books, $filename); return new JsonResponse(Constants::EXCEL_DOWNLOAD_LOCATION . $filename); } else { return new JsonResponse(json_encode(['response' => 'File is invalid!', 'errors' => Util::getFormErrorMessages($download)])); } } catch (Exception $e) { return new JsonResponse($e->getMessage()); } })->bind('download'); $app->post('/refreshCombo', function (Request $request) use($app) { try { $database = new DBConnection($app); $docArray = $database->findAllDocuments(); return new JsonResponse($docArray); } catch (Exception $e) { return new JsonResponse($e->getMessage()); } })->bind('refreshCombo'); /** * Get errors function */ $app->error(function (\Exception $e, Request $request, $code) use($app) { if ($app['debug']) { return; } // 404.html, or 40x.html, or 4xx.html, or error.html $templates = ['errors/' . $code . '.html.twig', 'errors/' . substr($code, 0, 2) . 'x.html.twig', 'errors/' . substr($code, 0, 1) . 'xx.html.twig', 'errors/default.html.twig'];