Exemple #1
0
 /**
  * Internal function to return a BookForReview object from a row.
  * @param $row array
  * @return BookForReview
  */
 function &_returnBookForReviewFromRow($row)
 {
     $bfrPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
     $bfrPlugin->import('classes.BookForReview');
     $book = new BookForReview();
     $book->setId($row['book_id']);
     $book->setJournalId($row['journal_id']);
     $book->setStatus($row['status']);
     $book->setUserId($row['user_id']);
     $book->setEditorId($row['editor_id']);
     $book->setAuthorType($row['author_type']);
     $book->setPublisher($row['publisher']);
     $book->setUrl($row['url']);
     $book->setYear($row['year']);
     $book->setLanguage($row['language']);
     $book->setCopy($row['copy']);
     $book->setEdition($row['edition']);
     $book->setPages($row['pages']);
     $book->setISBN($row['isbn']);
     $book->setArticleId($row['submission_id']);
     $book->setNotes($row['notes']);
     $book->setDateCreated($row['date_created']);
     $book->setDateRequested($row['date_requested']);
     $book->setDateAssigned($row['date_assigned']);
     $book->setDateMailed($row['date_mailed']);
     $book->setDateDue($row['date_due']);
     $book->setDateSubmitted($row['date_submitted']);
     $book->setAuthors($this->bookForReviewAuthorDao->getAuthorsByBookForReview($row['book_id']));
     $this->getDataObjectSettings('books_for_review_settings', 'book_id', $row['book_id'], $book);
     HookRegistry::call('BookForReviewDAO::_returnBookForReviewFromRow', array(&$book, &$row));
     return $book;
 }
 /**
  * Save book. 
  */
 function execute()
 {
     $bfrPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
     $bfrPlugin->import('classes.BookForReview');
     $bfrPlugin->import('classes.BookForReviewAuthor');
     $bfrDao =& DAORegistry::getDAO('BookForReviewDAO');
     $journal =& Request::getJournal();
     $journalId = $journal->getId();
     $user =& Request::getUser();
     $editorId = $user->getId();
     if ($this->book == null) {
         $book = new BookForReview();
         $book->setJournalId($journalId);
         $book->setEditorId($editorId);
         $book->setStatus(BFR_STATUS_AVAILABLE);
         $book->setDateCreated(Core::getCurrentDate());
     } else {
         $book =& $this->book;
     }
     $book->setAuthorType($this->getData('authorType'));
     $book->setPublisher($this->getData('publisher'));
     $book->setYear($this->getData('year'));
     $book->setLanguage($this->getData('language'));
     $book->setCopy($this->getData('copy') == null ? 0 : 1);
     $book->setUrl($this->getData('url'));
     $book->setEdition($this->getData('edition') == 0 ? null : $this->getData('edition'));
     $book->setPages($this->getData('pages') == '' ? null : $this->getData('pages'));
     $book->setISBN($this->getData('isbn'));
     $book->setDateDue($this->getData('dateDue'));
     $book->setUserId($this->getData('userId'));
     $book->setArticleId($this->getData('articleId'));
     $book->setNotes($this->getData('notes'));
     $book->setTitle($this->getData('title'), null);
     // Localized
     $book->setDescription($this->getData('description'), null);
     // Localized
     $book->setCoverPageAltText($this->getData('coverPageAltText'), null);
     // Localized
     // Update authors
     $authors = $this->getData('authors');
     for ($i = 0, $count = count($authors); $i < $count; $i++) {
         if ($authors[$i]['authorId'] > 0) {
             // Update an existing author
             $author =& $book->getAuthor($authors[$i]['authorId']);
             $isExistingAuthor = true;
         } else {
             // Create a new author
             // PHP4 Requires explicit instantiation-by-reference
             if (checkPhpVersion('5.0.0')) {
                 $author = new BookForReviewAuthor();
             } else {
                 $author =& new BookForReviewAuthor();
             }
             $isExistingAuthor = false;
         }
         if ($author != null) {
             $author->setFirstName($authors[$i]['firstName']);
             $author->setMiddleName($authors[$i]['middleName']);
             $author->setLastName($authors[$i]['lastName']);
             $author->setSequence($authors[$i]['seq']);
             if ($isExistingAuthor == false) {
                 $book->addAuthor($author);
             }
         }
     }
     // Remove deleted authors
     $deletedAuthors = explode(':', $this->getData('deletedAuthors'));
     for ($i = 0, $count = count($deletedAuthors); $i < $count; $i++) {
         $book->removeAuthor($deletedAuthors[$i]);
     }
     // Insert or update book for review
     if ($book->getId() == null) {
         $bfrDao->insertObject($book);
     } else {
         $bfrDao->updateObject($book);
     }
     // Handle book for review cover image
     import('classes.file.PublicFileManager');
     $publicFileManager = new PublicFileManager();
     $formLocale = $this->getFormLocale();
     if ($publicFileManager->uploadedFileExists(BFR_COVER_PAGE_IMAGE_NAME)) {
         $originalFileName = $publicFileManager->getUploadedFileName(BFR_COVER_PAGE_IMAGE_NAME);
         $type = $publicFileManager->getUploadedFileType(BFR_COVER_PAGE_IMAGE_NAME);
         $newFileName = 'cover_bfr_' . $book->getId() . '_' . $formLocale . $publicFileManager->getImageExtension($type);
         $publicFileManager->uploadJournalFile($journalId, BFR_COVER_PAGE_IMAGE_NAME, $newFileName);
         $book->setOriginalFileName($publicFileManager->truncateFileName($originalFileName, 127), $formLocale);
         $book->setFileName($newFileName, $formLocale);
         // Store the image dimensions
         list($width, $height) = getimagesize($publicFileManager->getJournalFilesPath($journalId) . '/' . $newFileName);
         $book->setWidth($width, $formLocale);
         $book->setHeight($height, $formLocale);
         $bfrDao->updateObject($book);
     }
 }