/** * Edit a author * @param $args array * @param $request PKPRequest * @return JSONMessage JSON object */ function updateAuthor($args, $request) { // Identify the author to be updated $authorId = $request->getUserVar('authorId'); $submission = $this->getSubmission(); $authorDao = DAORegistry::getDAO('AuthorDAO'); $author = $authorDao->getById($authorId, $submission->getId()); // Form handling import('lib.pkp.controllers.grid.users.author.form.AuthorForm'); $authorForm = new AuthorForm($submission, $author, 'submissionId'); $authorForm->readInputData(); if ($authorForm->validate()) { $authorId = $authorForm->execute(); if (!isset($author)) { // This is a new contributor $author = $authorDao->getById($authorId, $submission->getId()); // New added author action notification content. $notificationContent = __('notification.addedAuthor'); } else { // Author edition action notification content. $notificationContent = __('notification.editedAuthor'); } // Create trivial notification. $currentUser = $request->getUser(); $notificationMgr = new NotificationManager(); $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent)); // Prepare the grid row data $row = $this->getRowInstance(); $row->setGridId($this->getId()); $row->setId($authorId); $row->setData($author); $row->initialize($request); // Render the row into a JSON response if ($author->getPrimaryContact()) { // If this is the primary contact, redraw the whole grid // so that it takes the checkbox off other rows. return DAO::getDataChangedEvent(); } else { return DAO::getDataChangedEvent($authorId); } } else { return new JSONMessage(true, $authorForm->fetch($request)); } }