Exemplo n.º 1
0
 /**
  * Save metadata.
  * @param $article object
  * @param $request PKPRequest
  */
 function saveMetadata($article, &$request)
 {
     $router =& $request->getRouter();
     if (!HookRegistry::call('Action::saveMetadata', array(&$article))) {
         import('classes.submission.form.MetadataForm');
         $journal =& $request->getJournal();
         $metadataForm = new MetadataForm($article, $journal);
         $metadataForm->readInputData();
         // Check for any special cases before trying to save
         if ($request->getUserVar('addAuthor')) {
             // Add an author
             $editData = true;
             $authors = $metadataForm->getData('authors');
             array_push($authors, array());
             $metadataForm->setData('authors', $authors);
         } else {
             if (($delAuthor = $request->getUserVar('delAuthor')) && count($delAuthor) == 1) {
                 // Delete an author
                 $editData = true;
                 list($delAuthor) = array_keys($delAuthor);
                 $delAuthor = (int) $delAuthor;
                 $authors = $metadataForm->getData('authors');
                 if (isset($authors[$delAuthor]['authorId']) && !empty($authors[$delAuthor]['authorId'])) {
                     $deletedAuthors = explode(':', $metadataForm->getData('deletedAuthors'));
                     array_push($deletedAuthors, $authors[$delAuthor]['authorId']);
                     $metadataForm->setData('deletedAuthors', join(':', $deletedAuthors));
                 }
                 array_splice($authors, $delAuthor, 1);
                 $metadataForm->setData('authors', $authors);
                 if ($metadataForm->getData('primaryContact') == $delAuthor) {
                     $metadataForm->setData('primaryContact', 0);
                 }
             } else {
                 if ($request->getUserVar('moveAuthor')) {
                     // Move an author up/down
                     $editData = true;
                     $moveAuthorDir = $request->getUserVar('moveAuthorDir');
                     $moveAuthorDir = $moveAuthorDir == 'u' ? 'u' : 'd';
                     $moveAuthorIndex = (int) $request->getUserVar('moveAuthorIndex');
                     $authors = $metadataForm->getData('authors');
                     if (!($moveAuthorDir == 'u' && $moveAuthorIndex <= 0 || $moveAuthorDir == 'd' && $moveAuthorIndex >= count($authors) - 1)) {
                         $tmpAuthor = $authors[$moveAuthorIndex];
                         $primaryContact = $metadataForm->getData('primaryContact');
                         if ($moveAuthorDir == 'u') {
                             $authors[$moveAuthorIndex] = $authors[$moveAuthorIndex - 1];
                             $authors[$moveAuthorIndex - 1] = $tmpAuthor;
                             if ($primaryContact == $moveAuthorIndex) {
                                 $metadataForm->setData('primaryContact', $moveAuthorIndex - 1);
                             } else {
                                 if ($primaryContact == $moveAuthorIndex - 1) {
                                     $metadataForm->setData('primaryContact', $moveAuthorIndex);
                                 }
                             }
                         } else {
                             $authors[$moveAuthorIndex] = $authors[$moveAuthorIndex + 1];
                             $authors[$moveAuthorIndex + 1] = $tmpAuthor;
                             if ($primaryContact == $moveAuthorIndex) {
                                 $metadataForm->setData('primaryContact', $moveAuthorIndex + 1);
                             } else {
                                 if ($primaryContact == $moveAuthorIndex + 1) {
                                     $metadataForm->setData('primaryContact', $moveAuthorIndex);
                                 }
                             }
                         }
                     }
                     $metadataForm->setData('authors', $authors);
                 }
             }
         }
         if (isset($editData)) {
             $metadataForm->display();
             return false;
         } else {
             if (!$metadataForm->validate()) {
                 return $metadataForm->display();
             }
             $metadataForm->execute($request);
             // Send a notification to associated users
             import('lib.pkp.classes.notification.NotificationManager');
             $notificationManager = new NotificationManager();
             $notificationUsers = $article->getAssociatedUserIds();
             foreach ($notificationUsers as $userRole) {
                 $url = $router->url($request, null, $userRole['role'], 'submission', $article->getId(), null, 'metadata');
                 $notificationManager->createNotification($userRole['id'], 'notification.type.metadataModified', $article->getProposalId(), $url, 1, NOTIFICATION_TYPE_METADATA_MODIFIED);
             }
             //Added by AIM, Jan 20, 2012
             $notificationUsers = array();
             $roleDao =& DAORegistry::getDAO('RoleDAO');
             $editors = $roleDao->getUsersByRoleId(ROLE_ID_EDITOR);
             while (!$editors->eof()) {
                 $editor =& $editors->next();
                 $notificationUsers[] = array('id' => $editor->getId(), 'role' => $roleDao->getRolePath(ROLE_ID_EDITOR));
                 unset($editor);
             }
             //print_r($notificationUsers); die();
             foreach ($notificationUsers as $userRole) {
                 $url = $router->url($request, null, $userRole['role'], 'submission', $article->getId(), null, 'metadata');
                 $notificationManager->createNotification($userRole['id'], 'notification.type.metadataModified', $article->getProposalId(), $url, 1, NOTIFICATION_TYPE_METADATA_MODIFIED);
             }
             // Add log entry
             $user =& $request->getUser();
             import('classes.article.log.ArticleLog');
             import('classes.article.log.ArticleEventLogEntry');
             ArticleLog::logEvent($article->getId(), ARTICLE_LOG_METADATA_UPDATE, ARTICLE_LOG_TYPE_DEFAULT, 0, 'log.editor.metadataModified', array('editorName' => $user->getFullName()));
             return true;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Save metadata.
  * @param $article object
  * @param $request PKPRequest
  */
 function saveMetadata($article, &$request)
 {
     $router =& $request->getRouter();
     if (!HookRegistry::call('Action::saveMetadata', array(&$article))) {
         import('classes.submission.form.MetadataForm');
         $journal =& $request->getJournal();
         $metadataForm = new MetadataForm($article, $journal);
         $metadataForm->readInputData();
         // Check for any special cases before trying to save
         if ($request->getUserVar('addAuthor')) {
             // Add an author
             $editData = true;
             $authors = $metadataForm->getData('authors');
             array_push($authors, array());
             $metadataForm->setData('authors', $authors);
         } else {
             if (($delAuthor = $request->getUserVar('delAuthor')) && count($delAuthor) == 1) {
                 // Delete an author
                 $editData = true;
                 list($delAuthor) = array_keys($delAuthor);
                 $delAuthor = (int) $delAuthor;
                 $authors = $metadataForm->getData('authors');
                 if (isset($authors[$delAuthor]['authorId']) && !empty($authors[$delAuthor]['authorId'])) {
                     $deletedAuthors = explode(':', $metadataForm->getData('deletedAuthors'));
                     array_push($deletedAuthors, $authors[$delAuthor]['authorId']);
                     $metadataForm->setData('deletedAuthors', join(':', $deletedAuthors));
                 }
                 array_splice($authors, $delAuthor, 1);
                 $metadataForm->setData('authors', $authors);
                 if ($metadataForm->getData('primaryContact') == $delAuthor) {
                     $metadataForm->setData('primaryContact', 0);
                 }
             } else {
                 if ($request->getUserVar('moveAuthor')) {
                     // Move an author up/down
                     $editData = true;
                     $moveAuthorDir = $request->getUserVar('moveAuthorDir');
                     $moveAuthorDir = $moveAuthorDir == 'u' ? 'u' : 'd';
                     $moveAuthorIndex = (int) $request->getUserVar('moveAuthorIndex');
                     $authors = $metadataForm->getData('authors');
                     if (!($moveAuthorDir == 'u' && $moveAuthorIndex <= 0 || $moveAuthorDir == 'd' && $moveAuthorIndex >= count($authors) - 1)) {
                         $tmpAuthor = $authors[$moveAuthorIndex];
                         $primaryContact = $metadataForm->getData('primaryContact');
                         if ($moveAuthorDir == 'u') {
                             $authors[$moveAuthorIndex] = $authors[$moveAuthorIndex - 1];
                             $authors[$moveAuthorIndex - 1] = $tmpAuthor;
                             if ($primaryContact == $moveAuthorIndex) {
                                 $metadataForm->setData('primaryContact', $moveAuthorIndex - 1);
                             } else {
                                 if ($primaryContact == $moveAuthorIndex - 1) {
                                     $metadataForm->setData('primaryContact', $moveAuthorIndex);
                                 }
                             }
                         } else {
                             $authors[$moveAuthorIndex] = $authors[$moveAuthorIndex + 1];
                             $authors[$moveAuthorIndex + 1] = $tmpAuthor;
                             if ($primaryContact == $moveAuthorIndex) {
                                 $metadataForm->setData('primaryContact', $moveAuthorIndex + 1);
                             } else {
                                 if ($primaryContact == $moveAuthorIndex + 1) {
                                     $metadataForm->setData('primaryContact', $moveAuthorIndex);
                                 }
                             }
                         }
                     }
                     $metadataForm->setData('authors', $authors);
                 }
             }
         }
         if (isset($editData)) {
             $metadataForm->display();
             return false;
         } else {
             if (!$metadataForm->validate()) {
                 return $metadataForm->display();
             }
             $metadataForm->execute($request);
             // Send a notification to associated users
             import('classes.notification.NotificationManager');
             $notificationManager = new NotificationManager();
             $notificationUsers = $article->getAssociatedUserIds();
             foreach ($notificationUsers as $userRole) {
                 $notificationManager->createNotification($request, $userRole['id'], NOTIFICATION_TYPE_METADATA_MODIFIED, $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId());
             }
             // Add log entry
             $user =& $request->getUser();
             import('classes.article.log.ArticleLog');
             ArticleLog::logEvent($request, $article, ARTICLE_LOG_METADATA_UPDATE, 'log.editor.metadataModified', array('editorName' => $user->getFullName()));
             return true;
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Save metadata.
  * @param $paper object
  */
 function saveMetadata($paper)
 {
     if (!HookRegistry::call('Action::saveMetadata', array(&$paper))) {
         import('classes.submission.form.MetadataForm');
         $metadataForm = new MetadataForm($paper);
         $metadataForm->readInputData();
         // Check for any special cases before trying to save
         if (Request::getUserVar('addAuthor')) {
             // Add an author
             $editData = true;
             $authors = $metadataForm->getData('authors');
             array_push($authors, array());
             $metadataForm->setData('authors', $authors);
         } else {
             if (($delAuthor = Request::getUserVar('delAuthor')) && count($delAuthor) == 1) {
                 // Delete an author
                 $editData = true;
                 list($delAuthor) = array_keys($delAuthor);
                 $delAuthor = (int) $delAuthor;
                 $authors = $metadataForm->getData('authors');
                 if (isset($authors[$delAuthor]['authorId']) && !empty($authors[$delAuthor]['authorId'])) {
                     $deletedAuthors = explode(':', $metadataForm->getData('deletedAuthors'));
                     array_push($deletedAuthors, $authors[$delAuthor]['authorId']);
                     $metadataForm->setData('deletedAuthors', join(':', $deletedAuthors));
                 }
                 array_splice($authors, $delAuthor, 1);
                 $metadataForm->setData('authors', $authors);
                 if ($metadataForm->getData('primaryContact') == $delAuthor) {
                     $metadataForm->setData('primaryContact', 0);
                 }
             } else {
                 if (Request::getUserVar('moveAuthor')) {
                     // Move an author up/down
                     $editData = true;
                     $moveAuthorDir = Request::getUserVar('moveAuthorDir');
                     $moveAuthorDir = $moveAuthorDir == 'u' ? 'u' : 'd';
                     $moveAuthorIndex = (int) Request::getUserVar('moveAuthorIndex');
                     $authors = $metadataForm->getData('authors');
                     if (!($moveAuthorDir == 'u' && $moveAuthorIndex <= 0 || $moveAuthorDir == 'd' && $moveAuthorIndex >= count($authors) - 1)) {
                         $tmpAuthor = $authors[$moveAuthorIndex];
                         $primaryContact = $metadataForm->getData('primaryContact');
                         if ($moveAuthorDir == 'u') {
                             $authors[$moveAuthorIndex] = $authors[$moveAuthorIndex - 1];
                             $authors[$moveAuthorIndex - 1] = $tmpAuthor;
                             if ($primaryContact == $moveAuthorIndex) {
                                 $metadataForm->setData('primaryContact', $moveAuthorIndex - 1);
                             } else {
                                 if ($primaryContact == $moveAuthorIndex - 1) {
                                     $metadataForm->setData('primaryContact', $moveAuthorIndex);
                                 }
                             }
                         } else {
                             $authors[$moveAuthorIndex] = $authors[$moveAuthorIndex + 1];
                             $authors[$moveAuthorIndex + 1] = $tmpAuthor;
                             if ($primaryContact == $moveAuthorIndex) {
                                 $metadataForm->setData('primaryContact', $moveAuthorIndex + 1);
                             } else {
                                 if ($primaryContact == $moveAuthorIndex + 1) {
                                     $metadataForm->setData('primaryContact', $moveAuthorIndex);
                                 }
                             }
                         }
                     }
                     $metadataForm->setData('authors', $authors);
                 }
             }
         }
         if (isset($editData)) {
             $metadataForm->display();
             return false;
         } else {
             if (!$metadataForm->validate()) {
                 return $metadataForm->display();
             }
             $metadataForm->execute();
             // Send a notification to associated users
             import('lib.pkp.classes.notification.NotificationManager');
             $notificationManager = new NotificationManager();
             $notificationUsers = $paper->getAssociatedUserIds();
             foreach ($notificationUsers as $userRole) {
                 $url = Request::url(null, null, $userRole['role'], 'submission', $paper->getId(), null, 'metadata');
                 $notificationManager->createNotification($userRole['id'], 'notification.type.metadataModified', $paper->getLocalizedTitle(), $url, 1, NOTIFICATION_TYPE_METADATA_MODIFIED);
             }
             // Add log entry
             $user =& Request::getUser();
             import('classes.paper.log.PaperLog');
             import('classes.paper.log.PaperEventLogEntry');
             PaperLog::logEvent($paper->getId(), PAPER_LOG_METADATA_UPDATE, LOG_TYPE_DEFAULT, 0, 'log.director.metadataModified', array('directorName' => $user->getFullName()));
             return true;
         }
     }
 }