/** * Update a format * @param $args array * @param $request PKPRequest * @return JSONMessage JSON object */ function updateFormat($args, $request) { $submission = $this->getSubmission(); $representationDao = Application::getRepresentationDAO(); $representation = $representationDao->getById($request->getUserVar('representationId'), $submission->getId()); import('controllers.grid.catalogEntry.form.PublicationFormatForm'); $publicationFormatForm = new PublicationFormatForm($submission, $representation); $publicationFormatForm->readInputData(); if ($publicationFormatForm->validate()) { $publicationFormatForm->execute($request); return DAO::getDataChangedEvent(); } return new JSONMessage(true, $publicationFormatForm->fetch($request)); }
/** * Update a format * @param $args array * @param $request PKPRequest * @return JSONMessage JSON object */ function updateFormat($args, $request) { // Identify the format to be updated $representationId = (int) $request->getUserVar('representationId'); $submission = $this->getSubmission(); $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO'); $publicationFormat = $publicationFormatDao->getById($representationId); // Form handling import('controllers.grid.catalogEntry.form.PublicationFormatForm'); $publicationFormatForm = new PublicationFormatForm($submission, $publicationFormat); $publicationFormatForm->readInputData(); if ($publicationFormatForm->validate()) { $representationId = $publicationFormatForm->execute($request); if (!isset($publicationFormat)) { // This is a new format $publicationFormat = $publicationFormatDao->getById($representationId); // New added format action notification content. $notificationContent = __('notification.addedPublicationFormat'); } else { // Format edit action notification content. $notificationContent = __('notification.editedPublicationFormat'); } // 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($representationId); $row->setData($publicationFormat); $row->initialize($request); // Render the row into a JSON response return DAO::getDataChangedEvent(); } else { return new JSONMessage(true, $publicationFormatForm->fetch($request)); } }