本文整理汇总了PHP中JSONMessage::setEvent方法的典型用法代码示例。如果您正苦于以下问题:PHP JSONMessage::setEvent方法的具体用法?PHP JSONMessage::setEvent怎么用?PHP JSONMessage::setEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONMessage
的用法示例。
在下文中一共展示了JSONMessage::setEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetString
/**
* @covers JSONMessage
*/
public function testGetString()
{
// Create a test object.
$testObject = new stdClass();
$testObject->someInt = 5;
$testObject->someFloat = 5.5;
$json = new JSONMessage($status = true, $content = 'test content', $elementId = '0', $additionalAttributes = array('testObj' => $testObject));
$json->setEvent('someEvent', array('eventDataKey' => array('item1', 'item2')));
// Render the JSON message.
$expectedString = '{"status":true,"content":"test content",' . '"elementId":"0","testObj":{"someInt":5,"someFloat":5.5},' . '"event":{"name":"someEvent","data":{"eventDataKey":["item1","item2"]}}}';
self::assertEquals($expectedString, $json->getString());
}
示例2: fetchReportGenerator
/**
* Fetch form to generate custom reports.
* @param $args array
* @param $request Request
* @return JSONMessage JSON object
*/
function fetchReportGenerator($args, $request)
{
$this->setupTemplate($request);
$reportGeneratorForm = $this->_getReportGeneratorForm($request);
$reportGeneratorForm->initData($request);
$formContent = $reportGeneratorForm->fetch($request);
$json = new JSONMessage(true);
if ($request->getUserVar('refreshForm')) {
$json->setEvent('refreshForm', $formContent);
} else {
$json->setContent($formContent);
}
return $json;
}
示例3: deleteCoverImage
/**
* An action to delete an article cover image.
* @param $args array
* @param $request PKPRequest
* @return JSONMessage JSON object
*/
function deleteCoverImage($args, $request)
{
assert(!empty($args['coverImage']) && !empty($args['submissionId']));
$submission = $this->getSubmission();
$submissionDao = Application::getSubmissionDAO();
$file = $args['coverImage'];
// Remove cover image and alt text from article settings
$submission->setCoverImage('');
$submission->setCoverImageAltText('');
$submissionDao->updateObject($submission);
// Remove the file
$publicFileManager = new PublicFileManager();
if ($publicFileManager->removeJournalFile($submission->getJournalId(), $file)) {
$json = new JSONMessage(true);
$json->setEvent('fileDeleted');
return $json;
} else {
return new JSONMessage(false, __('editor.article.removeCoverImageFileNotFound'));
}
}
示例4: saveStep
/**
* Save a submission step.
* @param $args array first parameter is the step being saved
* @param $request Request
*/
function saveStep($args, $request)
{
$step = isset($args[0]) ? (int) $args[0] : 1;
$router = $request->getRouter();
$context = $router->getContext($request);
$submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
$this->setupTemplate($request);
$formClass = "SubmissionSubmitStep{$step}Form";
import("classes.submission.form.{$formClass}");
$submitForm = new $formClass($context, $submission);
$submitForm->readInputData();
if (!HookRegistry::call('SubmissionHandler::saveSubmit', array($step, &$submission, &$submitForm))) {
if ($submitForm->validate()) {
$submissionId = $submitForm->execute($args, $request);
if (!$submission) {
return $request->redirectUrlJson($router->url($request, null, null, 'wizard', $step + 1, array('submissionId' => $submissionId), 'step-2'));
}
$json = new JSONMessage(true);
$json->setEvent('setStep', max($step + 1, $submission->getSubmissionProgress()));
} else {
$json = new JSONMessage(true, $submitForm->fetch($request));
}
return $json->getString();
}
}
示例5: getDataChangedEvent
/**
* Generate a JSON message with an event that can be sent
* to the client to refresh itself according to changes
* in the DB.
*
* @param $elementId string (Optional) To refresh a single element
* give the element ID here. Otherwise all elements will
* be refreshed.
* @param $parentElementId string (Optional) To refresh a single
* element that is associated with another one give the parent
* element ID here.
* @param $content mixed (Optional) Additional content to pass back
* to the handler of the JSON message.
* @return string A rendered JSON message.
*/
static function getDataChangedEvent($elementId = null, $parentElementId = null, $content = '')
{
// Create the event data.
$eventData = null;
if ($elementId) {
$eventData = array($elementId);
if ($parentElementId) {
$eventData['parentElementId'] = $parentElementId;
}
}
// Create and render the JSON message with the
// event to be triggered on the client side.
import('lib.pkp.classes.core.JSONMessage');
$json = new JSONMessage(true, $content);
$json->setEvent('dataChanged', $eventData);
return $json->getString();
}
示例6: unpublishIssue
/**
* Unpublish a previously-published issue
* @param $args array
* @param $request PKPRequest
*/
function unpublishIssue($args, $request)
{
$issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
$journal = $request->getJournal();
if (!$request->checkCSRF()) {
return new JSONMessage(false);
}
$issue->setCurrent(0);
$issue->setPublished(0);
$issue->setDatePublished(null);
$issueDao = DAORegistry::getDAO('IssueDAO');
$issueDao->updateObject($issue);
// insert article tombstones for all articles
import('classes.article.ArticleTombstoneManager');
$articleTombstoneManager = new ArticleTombstoneManager();
$publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
$publishedArticles = $publishedArticleDao->getPublishedArticles($issue->getId());
foreach ($publishedArticles as $article) {
$articleTombstoneManager->insertArticleTombstone($article, $journal);
}
$dispatcher = $request->getDispatcher();
$json = new JSONMessage();
$json->setEvent('containerReloadRequested', array('tabsUrl' => $dispatcher->url($request, ROUTE_PAGE, null, 'manageIssues', 'index')));
return $json;
}
示例7: downloadLocale
/**
* Download a locale from the PKP web site.
* @param $args array
* @param $request object
* @return JSONMessage JSON object
*/
function downloadLocale($args, $request)
{
$this->setupTemplate($request, true);
$locale = $request->getUserVar('locale');
import('classes.i18n.LanguageAction');
$languageAction = new LanguageAction();
if (!$languageAction->isDownloadAvailable() || !preg_match('/^[a-z]{2}_[A-Z]{2}$/', $locale)) {
$request->redirect(null, 'admin', 'settings');
}
$notificationManager = new NotificationManager();
$user = $request->getUser();
$json = new JSONMessage(true);
$errors = array();
if (!$languageAction->downloadLocale($locale, $errors)) {
$notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => $errors));
$json->setEvent('refreshForm', $this->_fetchReviewerForm($args, $request));
} else {
$notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contentLocaleKey' => __('admin.languages.localeInstalled'), 'params' => array('locale' => $locale)));
}
// Refresh form.
$installLanguageForm = new InstallLanguageForm();
$installLanguageForm->initData($request);
$json->setEvent('refreshForm', $installLanguageForm->fetch($request));
return $json;
}
示例8: display
/**
* Display the plugin.
* @param $args array
* @param $request PKPRequest
*/
function display($args, $request)
{
$templateMgr = TemplateManager::getManager($request);
$context = $request->getContext();
parent::display($args, $request);
$templateMgr->assign('plugin', $this);
switch (array_shift($args)) {
case 'index':
case '':
$templateMgr->display($this->getTemplatePath() . 'index.tpl');
break;
case 'uploadImportXML':
$user = $request->getUser();
import('lib.pkp.classes.file.TemporaryFileManager');
$temporaryFileManager = new TemporaryFileManager();
$temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
if ($temporaryFile) {
$json = new JSONMessage(true);
$json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId()));
} else {
$json = new JSONMessage(false, __('common.uploadFailed'));
}
return $json->getString();
case 'importBounce':
$json = new JSONMessage(true);
$json->setEvent('addTab', array('title' => __('plugins.importexport.users.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId')))));
return $json->getString();
case 'import':
$temporaryFileId = $request->getUserVar('temporaryFileId');
$temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO');
$user = $request->getUser();
$temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId());
if (!$temporaryFile) {
$json = new JSONMessage(true, __('plugins.importexport.users.uploadFile'));
return $json->getString();
}
$temporaryFilePath = $temporaryFile->getFilePath();
libxml_use_internal_errors(true);
$users = $this->importUsers(file_get_contents($temporaryFilePath), $context, $user);
$validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;'));
$templateMgr->assign('validationErrors', $validationErrors);
libxml_clear_errors();
$templateMgr->assign('users', $users);
$json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl'));
return $json->getString();
case 'export':
$exportXml = $this->exportUsers((array) $request->getUserVar('selectedUsers'), $request->getContext(), $request->getUser());
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml');
$fileManager->writeFile($exportFileName, $exportXml);
$fileManager->downloadFile($exportFileName);
$fileManager->deleteFile($exportFileName);
break;
case 'exportAllUsers':
$exportXml = $this->exportAllUsers($request->getContext(), $request->getUser());
import('lib.pkp.classes.file.TemporaryFileManager');
$fileManager = new TemporaryFileManager();
$exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml');
$fileManager->writeFile($exportFileName, $exportXml);
$fileManager->downloadFile($exportFileName);
$fileManager->deleteFile($exportFileName);
break;
default:
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
}
}
示例9: redirectUrlJson
/**
* Request an HTTP redirect via JSON to be used from components.
* @param $url string
* @return JSONMessage
*/
function redirectUrlJson($url)
{
import('lib.pkp.classes.core.JSONMessage');
$json = new JSONMessage(true);
$json->setEvent('redirectRequested', $url);
return $json;
}
示例10: reloadReviewerForm
/**
* Load the contents of the reviewer form
* @param $args array
* @param $request Request
* @return JSONMessage JSON object
*/
function reloadReviewerForm($args, $request)
{
$json = new JSONMessage(true);
$json->setEvent('refreshForm', $this->_fetchReviewerForm($args, $request));
return $json;
}
示例11: display
/**
* Display the plugin.
* @param $args array
* @param $request PKPRequest
*/
function display($args, $request)
{
$templateMgr = TemplateManager::getManager($request);
$press = $request->getPress();
parent::display($args, $request);
$templateMgr->assign('plugin', $this);
switch (array_shift($args)) {
case 'index':
case '':
$templateMgr->display($this->getTemplatePath() . 'index.tpl');
break;
case 'uploadImportXML':
$user = $request->getUser();
import('lib.pkp.classes.file.TemporaryFileManager');
$temporaryFileManager = new TemporaryFileManager();
$temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
if ($temporaryFile) {
$json = new JSONMessage(true);
$json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId()));
} else {
$json = new JSONMessage(false, __('common.uploadFailed'));
}
return $json->getString();
case 'importBounce':
$json = new JSONMessage(true);
$json->setEvent('addTab', array('title' => __('plugins.importexport.native.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId')))));
return $json->getString();
case 'import':
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION);
$temporaryFileId = $request->getUserVar('temporaryFileId');
$temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO');
$user = $request->getUser();
$temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId());
if (!$temporaryFile) {
$json = new JSONMessage(true, __('plugins.inportexport.native.uploadFile'));
return $json->getString();
}
$temporaryFilePath = $temporaryFile->getFilePath();
$deployment = new NativeImportExportDeployment($press, $user);
libxml_use_internal_errors(true);
$submissions = $this->importSubmissions(file_get_contents($temporaryFilePath), $deployment);
$templateMgr->assign('submissions', $submissions);
$validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;'));
$templateMgr->assign('validationErrors', $validationErrors);
libxml_clear_errors();
// Are there any submissions import errors
$processedSubmissionsIds = $deployment->getProcessedObjectsIds(ASSOC_TYPE_SUBMISSION);
if (!empty($processedSubmissionsIds)) {
$submissionsErrors = array_filter($processedSubmissionsIds, create_function('$a', 'return !empty($a);'));
if (!empty($submissionsErrors)) {
$templateMgr->assign('submissionsErrors', $processedSubmissionsIds);
}
}
// If there are any submissions or validataion errors
// delete imported submissions.
if (!empty($submissionsErrors) || !empty($validationErrors)) {
// remove all imported sumissions
$deployment->removeImportedObjects(ASSOC_TYPE_SUBMISSION);
}
// Display the results
$json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl'));
return $json->getString();
case 'export':
$exportXml = $this->exportSubmissions((array) $request->getUserVar('selectedSubmissions'), $request->getContext(), $request->getUser());
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$exportFileName = $this->getExportFileName($this->getExportPath(), 'monographs', $press, '.xml');
$fileManager->writeFile($exportFileName, $exportXml);
$fileManager->downloadFile($exportFileName);
$fileManager->deleteFile($exportFileName);
break;
default:
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
}
}
示例12: editCitation
/**
* Edit a citation
* @param $args array
* @param $request PKPRequest
* @return JSONMessage JSON object
*/
function editCitation(&$args, $request)
{
// Identify the citation to be edited
$citation = $this->getCitationFromArgs($request, $args, true);
// Form handling
import('lib.pkp.classes.controllers.grid.citation.form.CitationForm');
$citationForm = new CitationForm($request, $citation, $this->getAssocObject());
if ($citationForm->isLocaleResubmit()) {
$citationForm->readInputData();
} else {
$citationForm->initData();
}
$json = new JSONMessage(true, $data = $citationForm->fetch($request));
$json->setEvent('setCitationPaneData', $data);
return $json;
}
示例13: plugin
/**
* Perform plugin-specific management functions.
* @param $args array
* @param $request object
* @return JSONMessage JSON object
*/
function plugin($args, $request)
{
$verb = (string) $request->getUserVar('verb');
$plugin = $this->getAuthorizedContextObject(ASSOC_TYPE_PLUGIN);
/* @var $plugin Plugin */
$message = $messageParams = $pluginModalContent = null;
if (!is_a($plugin, 'Plugin') || !$plugin->manage($verb, $args, $message, $messageParams, $pluginModalContent)) {
HookRegistry::call('PluginGridHandler::plugin', array($verb, $args, $message, $messageParams, $plugin));
if ($message) {
$notificationManager = new NotificationManager();
$user = $request->getUser();
$notificationManager->createTrivialNotification($user->getId(), $message, $messageParams);
}
}
if ($pluginModalContent) {
$json = new JSONMessage(true, $pluginModalContent);
$json->setEvent('refreshForm', $pluginModalContent);
return $json;
}
return DAO::getDataChangedEvent($request->getUserVar('plugin'), $request->getUserVar($this->getCategoryRowIdParameterName()));
}
示例14: listNotes
/**
* List signoff notes.
* @param $args array
* @param $request PKPRequest
* @return string Serialized JSON object
*/
function listNotes($args, $request)
{
$this->setupTemplate($request);
$templateMgr = TemplateManager::getManager($request);
$noteDao = DAORegistry::getDAO('NoteDAO');
$notesFactory = $noteDao->getByAssoc(ASSOC_TYPE_SIGNOFF, $this->_signoff->getId());
$notes = $notesFactory->toAssociativeArray();
// Get any note files.
$noteFilesDownloadLink = array();
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
/** @var $submissionFileDao SubmissionFileDAO */
import('lib.pkp.controllers.api.file.linkAction.DownloadFileLinkAction');
foreach ($notes as $noteId => $note) {
$file = $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_NOTE, $noteId, $this->_submission->getId(), SUBMISSION_FILE_NOTE);
// We don't expect more than one file per note
$file = current($file);
// Get the download file link action.
if ($file) {
$noteFilesDownloadLink[$noteId] = new DownloadFileLinkAction($request, $file, $this->_stageId);
}
}
$user = $request->getUser();
import('lib.pkp.classes.core.ArrayItemIterator');
$templateMgr->assign('notes', new ArrayItemIterator($notes));
$templateMgr->assign('noteFilesDownloadLink', $noteFilesDownloadLink);
$templateMgr->assign('notesListId', 'notesList');
$templateMgr->assign('currentUserId', $user->getId());
$templateMgr->assign('notesDeletable', false);
$json = new JSONMessage(true, $templateMgr->fetch('controllers/informationCenter/notesList.tpl'));
$json->setEvent('dataChanged');
return $json->getString();
}
示例15: saveStep
/**
* Save a review step.
* @param $args array first parameter is the step being saved
* @param $request PKPRequest
* @return JSONMessage JSON object
*/
function saveStep($args, $request)
{
$step = (int) $request->getUserVar('step');
if ($step < 1 || $step > 3) {
fatalError('Invalid step!');
}
$reviewAssignment = $this->getAuthorizedContextObject(ASSOC_TYPE_REVIEW_ASSIGNMENT);
/* @var $reviewAssignment ReviewAssignment */
if ($reviewAssignment->getDateCompleted()) {
fatalError('Review already completed!');
}
$reviewerSubmissionDao = DAORegistry::getDAO('ReviewerSubmissionDAO');
$reviewerSubmission = $reviewerSubmissionDao->getReviewerSubmission($reviewAssignment->getId());
assert(is_a($reviewerSubmission, 'ReviewerSubmission'));
$formClass = "ReviewerReviewStep{$step}Form";
import("lib.pkp.classes.submission.reviewer.form.{$formClass}");
$reviewerForm = new $formClass($request, $reviewerSubmission, $reviewAssignment);
$reviewerForm->readInputData();
if ($reviewerForm->validate()) {
$reviewerForm->execute($request);
$json = new JSONMessage(true);
$json->setEvent('setStep', $step + 1);
return $json;
} else {
return new JSONMessage(true, $reviewerForm->fetch($request));
}
}