Пример #1
0
 /**
  * Gets all the books given a documents name
  *
  * @param $docName
  *
  * @return array
  *
  * @throws DocumentNotFoundException
  */
 public function getBooksFromDocument($docName)
 {
     if (!is_null($docName) && $this->findBy(array('name' => $docName))) {
         $sql = "SELECT lb.*, auth.auth_name\n                    FROM linio_books AS lb," . "author AS auth, " . "lb_author AS lba, " . "documents AS doc, " . "lb_doc AS lbd " . "WHERE doc.doc_name =? AND " . "doc.doc_id = lbd.doc_id_fk AND " . "lb.lb_id = lbd.lb_id_fk AND " . "lba.lb_id_fk = lb.lb_id AND " . "lba.auth_id_fk = auth.auth_id";
         $booksDBArray = $this->_em->getConnection()->fetchAll($sql, array($docName));
         $booksArray = [];
         foreach ($booksDBArray as $bookDB) {
             $book = Book::buildComplete($bookDB[Constants::BOOK_ISBN10], $bookDB[Constants::BOOK_ISBN13], $bookDB[Constants::BOOK_TITLE], $bookDB[Constants::AUTHOR_NAME], $bookDB[Constants::BOOK_PUBLISHER], $bookDB[Constants::BOOK_DESCRIPTION], $bookDB[Constants::BOOK_NUMPAGES], $bookDB[Constants::BOOK_IMAGELINK]);
             $booksArray[] = $book;
         }
         return $booksArray;
     }
     throw new DocumentNotFoundException('Document not found in database');
 }
Пример #2
0
 /**
  * Builds a Book entity from the data retrieved from the API
  *
  * @param $volumeInfo
  *
  * @return Book
  */
 public static function buildBookWithGoogleApiInfo($volumeInfo)
 {
     $numIsbn13 = 0;
     $numIsbn10 = 1;
     if (strlen($volumeInfo[Constants::GOOGLE_BOOKS_LABEL_INDUSTRY][0][Constants::GOOGLE_BOOKS_LABEL_IDENTIFIER]) != 13) {
         $numIsbn10 = 0;
         $numIsbn13 = 1;
     }
     if (isset($volumeInfo[Constants::GOOGLE_BOOKS_LABEL_INDUSTRY][$numIsbn13])) {
         $isbn13 = $volumeInfo[Constants::GOOGLE_BOOKS_LABEL_INDUSTRY][$numIsbn13][Constants::GOOGLE_BOOKS_LABEL_IDENTIFIER];
     } else {
         $isbn13 = "N/A";
     }
     if (isset($volumeInfo[Constants::GOOGLE_BOOKS_LABEL_INDUSTRY][$numIsbn10])) {
         $isbn10 = $volumeInfo[Constants::GOOGLE_BOOKS_LABEL_INDUSTRY][$numIsbn10][Constants::GOOGLE_BOOKS_LABEL_IDENTIFIER];
     } else {
         $isbn10 = "N/A";
     }
     $author = is_array($volumeInfo[Constants::GOOGLE_BOOKS_LABEL_AUTHORS]) ? implode(', ', $volumeInfo[Constants::GOOGLE_BOOKS_LABEL_AUTHORS]) : $volumeInfo[Constants::GOOGLE_BOOKS_LABEL_AUTHORS];
     $imageLink = !empty($volumeInfo[Constants::GOOGLE_BOOKS_LABEL_IMAGELINKS][Constants::GOOGLE_BOOKS_LABEL_THUMBNAIL]) ? $volumeInfo[Constants::GOOGLE_BOOKS_LABEL_IMAGELINKS][Constants::GOOGLE_BOOKS_LABEL_THUMBNAIL] : '';
     $book = Book::buildComplete($isbn10, $isbn13, $volumeInfo[Constants::GOOGLE_BOOKS_LABEL_TITLE], $author, $volumeInfo[Constants::GOOGLE_BOOKS_LABEL_PUBLISHER], $volumeInfo[Constants::GOOGLE_BOOKS_LABEL_DESCRIPTION], $volumeInfo[Constants::GOOGLE_BOOKS_LABEL_PAGECOUNT], $imageLink);
     return $book;
 }