Beispiel #1
0
 /**
  * Adds new copies of books
  * Needs the given bookIds, it does not re-check if everything is correct
  * @param  array  $barcodeContainers
  */
 protected function inventoryWithBooksAdd($barcodeContainers)
 {
     $barcodes = [];
     foreach ($barcodeContainers as $container) {
         if (!isset($container['bookId']) || !isset($container['barcode'])) {
             dieHttp('Inkorrekte Daten wurden übergeben.', 400);
         }
         $bookId = $container['bookId'];
         $barcodeStr = $container['barcode'];
         $barcode = new \Babesk\Schbas\Barcode();
         if ($barcode->initByBarcodeString($barcodeStr)) {
             $barcodes[] = $barcode;
         } else {
             dieHttp("Der Barcode '{$barcodeStr}' ist nicht korrekt", 400);
         }
         $book = $this->_em->getReference('DM:SchbasBook', $bookId);
         $inventory = new \Babesk\ORM\SchbasInventory();
         $inventory->setBook($book);
         $inventory->setYearOfPurchase($barcode->getPurchaseYear());
         $inventory->setExemplar($barcode->getExemplar());
         $this->_em->persist($inventory);
     }
     try {
         $this->_em->flush();
     } catch (\Doctrine\DBAL\DBALException $e) {
         if ($e->getPrevious()->getCode() === '23000') {
             dieHttp('Ein oder mehrere angegebene Barcodes gibt es schon!', 400);
         } else {
             throw $e;
         }
     }
     die('Die Buch-Exemplare wurden erfolgreich hinzugefügt.');
 }
Beispiel #2
0
 protected function barcodesDelete($barcodeStrings)
 {
     foreach ($barcodeStrings as $barcodeStr) {
         $barcode = new \Babesk\Schbas\Barcode();
         if (!$barcode->initByBarcodeString($barcodeStr)) {
             dieHttp("Der Barcode '{$barcodeStr}' ist nicht korrekt", 400);
         }
         $bookCopy = $barcode->getMatchingBookExemplar($this->_em);
         if ($bookCopy) {
             foreach ($bookCopy->getLending() as $lending) {
                 $this->_em->remove($lending);
             }
             $this->_em->remove($bookCopy);
         } else {
             echo "<p>Kein Buchexemplar zu Barcode {$barcodeStr} gefunden. " . "</p>";
         }
     }
     $this->_em->flush();
     die('Die Exemplare wurden erfolgreich gelöscht');
 }
Beispiel #3
0
 protected function sendIndexCreateAnswerData($result, $rowCount, $entriesPerPage)
 {
     $data = [];
     foreach ($result as $row) {
         $rowData = [];
         $rowData['id'] = $row->getId();
         if ($row->getLending() && count($row->getLending()) > 0) {
             if (count($row->getLending()) > 1) {
                 $this->_logger->log('Inventory is lend multiple times!', 'warning');
             }
             $user = $row->getLending()->first()->getUser();
             $rowData['lentUser'] = ['id' => $user->getId(), 'username' => $user->getUsername()];
             $rowData['lentUserId'] = $user->getId();
             $rowData['lentUserUsername'] = $user->getUsername();
         }
         if ($row->getBook()) {
             if ($row->getBook()->getSubject()) {
                 $barcode = Babesk\Schbas\Barcode::createByInventory($row);
                 $rowData['barcode'] = $barcode ? $barcode->getAsString() : '???';
                 $rowData['subjectName'] = $row->getBook()->getSubject()->getName();
             } else {
                 $this->_logger->logO('Subject for inventory not found', ['sev' => 'error', 'moreJson' => ['invId' => $row->getId()]]);
                 $rowData['barcode'] = 'Fach nicht gefunden!';
             }
             $rowData['bookTitle'] = $row->getBook()->getTitle();
             $rowData['bookIsbn'] = $row->getBook()->getIsbn();
             $rowData['bookAuthor'] = $row->getBook()->getAuthor();
         } else {
             $this->_logger->logO('Book for inventory not found', ['sev' => 'error', 'moreJson' => ['invId' => $row->getId()]]);
             $rowData['barcode'] = 'Buch nicht gefunden!';
         }
         $data['data'][] = $rowData;
     }
     $data['pageCount'] = ceil($rowCount / $entriesPerPage);
     return $data;
 }