/** * Internal function to return a BookForReviewAuthor object from a row. * @param $row array * @return BookForReviewAuthor */ function &_returnAuthorFromRow(&$row) { $bfrPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName); $bfrPlugin->import('classes.BookForReviewAuthor'); $author = new BookForReviewAuthor(); $author->setId($row['author_id']); $author->setBookId($row['book_id']); $author->setFirstName($row['first_name']); $author->setMiddleName($row['middle_name']); $author->setLastName($row['last_name']); $author->setSequence($row['seq']); HookRegistry::call('BookForReviewAuthorDAO::_returnAuthorFromRow', array(&$author, &$row)); return $author; }
/** * 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); } }