/**
  * Builds a Book class from the data retrieved from the API
  *
  * @param $volumeInfo
  *
  * @return Book
  */
 public function buildBookWithApiInfo($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;
 }
Exemple #2
0
 protected function model()
 {
     $result = Book::all();
     Debug::show($result);
 }
 /**
  * Saves file and its books in database
  *
  * @param $filename
  * @param $isbns
  *
  * @return bool
  */
 public function saveFile($filename, $isbns)
 {
     if (!is_null($filename && !is_null($isbns))) {
         if ($this->insertDocument($filename)) {
             $docId = $this->findDocumentID($filename);
             $book = new Book();
             foreach ($isbns as $isbn) {
                 if ($this->bookExistsByISBN13($isbn)) {
                     $book->setIsbn13($isbn);
                     $bookId = $this->findBookIdByISBN13($book);
                     if (!$this->relationshipBookDocExists($bookId, $docId)) {
                         $this->insertBookDoc($bookId, $docId);
                     }
                 }
             }
             return true;
         }
     }
     return false;
 }