Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
full plugin:get the information from PREreview
Browse files Browse the repository at this point in the history
  • Loading branch information
elena-herrera committed Feb 2, 2022
1 parent a7d0830 commit 82812f1
Show file tree
Hide file tree
Showing 20 changed files with 1,636 additions and 0 deletions.
435 changes: 435 additions & 0 deletions PrereviewPlugin.inc.php

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions PrereviewPluginDAO.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/**
* @file plugins/generic/prereview/PrereviewPluginDAO.inc.php
*
* @class PrereviewPluginDAO
* @ingroup plugins.generic.prereview
*
* @brief Operations to add save settings for each item.
*/


class PrereviewPluginDAO extends DAO {

/** @var $_result ADORecordSet */
var $_result;

/** @var $_loadId string */
var $_loadId;

/**
* Constructor
*/
function __construct() {
parent::__construct();

$this->_result = false;
$this->_loadId = null;
}
function insert($id, $name, $value) {
$this->update(
'INSERT INTO prereview_settings
(publication_id, setting_name, setting_value)
VALUES
(?, ?, ?)',
array(
$id,
$name,
$value,
)
);
return true;
}
function updateObject($id, $name, $value) {

$this->update(
'UPDATE prereview_settings
SET setting_value = ?
WHERE publication_id = ? AND setting_name = ?',
array(
$value,
$id,
$name,
)
);
return true;
}

function _getPrereviewData($id, $name) {
$result = $this->retrieve(
'SELECT setting_value
FROM prereview_settings WHERE publication_id = ? AND setting_name = ?
GROUP BY setting_value',
array((int) $id, $name)
);
$returner = $result->fields[0];
$result->Close();
return $returner;
}

function getDataPrereview($id) {
$result = $this->retrieve(
'SELECT setting_value
FROM prereview_settings WHERE publication_id = ?',
array((int) $id)
);
$returner = $result->current();
return $returner;
}


}

28 changes: 28 additions & 0 deletions PrereviewSchemaMigration.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php



use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Builder;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Capsule\Manager as Capsule;

class PrereviewSchemaMigration extends Migration {
/**
* Run the migrations.
* @return void
*/
public function up() {


// prereview_settings
Capsule::schema()->create('prereview_settings', function (Blueprint $table) {
$table->bigInteger('publication_id');
$table->string('setting_name', 255);
$table->longText('setting_value')->nullable();
$table->longText('status')->nullable();
$table->longText('views')->nullable();
});

}
}
89 changes: 89 additions & 0 deletions PrereviewSettingsForm.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

/**
* @file PrereviewSettingsForm.inc.php
*
* @class PrereviewSettingsForm
* @ingroup plugins.generic.prereview
*
* @brief Form for adding/editing the settings for the PREreview plugin
*/

import('lib.pkp.classes.form.Form');

class PrereviewSettingsForm extends Form {
/** @var PrereviewSettingsForm */
public $plugin;

public function __construct($plugin) {

// Define the settings template and store a copy of the plugin object
parent::__construct($plugin->getTemplateResource('settings.tpl'));
$this->plugin = $plugin;

// Always add POST and CSRF validation to secure your form.
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}

/**
* Load the settings already saved in the database
*
* The settings are stored together with the general settings of the plugin.
* can have different settings.
*/
public function initData() {
$contextId = Application::get()->getRequest()->getContext()->getId();
$this->setData('prereviewApp', $this->plugin->getSetting($contextId, 'prereviewApp'));
$this->setData('prereviewkey', $this->plugin->getSetting($contextId, 'prereviewkey'));
$this->setData('showRevisions', $this->plugin->getSetting($contextId, 'showRevisions'));
parent::initData();
}

/**
* Load data that was submitted with the form
*/
public function readInputData() {
$this->readUserVars(['prereviewApp']);
$this->readUserVars(['prereviewkey']);
$this->readUserVars(['showRevisions']);
parent::readInputData();
}

/**
* Fetch any additional data needed for your form.
*
* Data assigned to the form using $this->setData() during the
* initData() or readInputData() methods will be passed to the
* template.
*/
public function fetch($request, $template = null, $display = false) {

// Pass the plugin name to the template so that it can be
// used in the URL that the form is submitted to
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->plugin->getName());

return parent::fetch($request, $template, $display);
}
/**
* Save the settings
*/
public function execute(...$functionArgs) {
$contextId = Application::get()->getRequest()->getContext()->getId();
$this->plugin->updateSetting($contextId, 'prereviewApp', $this->getData('prereviewApp'));
$this->plugin->updateSetting($contextId, 'prereviewkey', $this->getData('prereviewkey'));
$this->plugin->updateSetting($contextId, 'showRevisions', $this->getData('showRevisions'));
// Tell the user that the save was successful.
import('classes.notification.NotificationManager');
$notificationMgr = new NotificationManager();
$notificationMgr->createTrivialNotification(
Application::get()->getRequest()->getUser()->getId(),
NOTIFICATION_TYPE_SUCCESS,
['contents' => __('common.changesSaved')]
);
return parent::execute(...$functionArgs);
}

}

128 changes: 128 additions & 0 deletions controllers/grid/PrereviewGridHandler.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

/**
* @file plugins/generic/prereviewPlugin/controllers/grid/PrereviewGridHandler.inc.php
*/

import('lib.pkp.classes.controllers.grid.GridHandler');

class PrereviewGridHandler extends GridHandler {
static $plugin;

/** @var boolean */
var $_readOnly;

/**
* Constructor
*/
function __construct() {
parent::__construct();
$this->addRoleAssignment(
array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT, ROLE_ID_AUTHOR),
array('updateRequest')
);
}


/**
* Set the plugin.
* @param $plugin
*/
static function setPlugin($plugin) {
self::$plugin = $plugin;
}

/**
* Get the submission associated with this grid.
* @return Submission
*/
function getSubmission() {
return $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
}

/**
* Get whether or not this grid should be 'read only'
* @return boolean
*/
function getReadOnly() {
return $this->_readOnly;
}

/**
* Set the boolean for 'read only' status
* @param boolean
*/
function setReadOnly($readOnly) {
$this->_readOnly = $readOnly;
}

/**
* @copydoc PKPHandler::authorize()
*/
function authorize($request, &$args, $roleAssignments) {
import('lib.pkp.classes.security.authorization.SubmissionAccessPolicy');
$this->addPolicy(new SubmissionAccessPolicy($request, $args, $roleAssignments));
return parent::authorize($request, $args, $roleAssignments);
}




/**
* @copydoc GridHandler::getJSHandler()
*/
public function getJSHandler() {
return '$.pkp.plugins.generic.prereviewPlugin.PrereviewGridHandler';
}


/**
* Update a request
* @param $args array
* @param $request PKPRequest
* @return string Serialized JSON object
*/
function updateRequest($args, $request) {
$result = $request->getUserVar('prereview:authorization');
$context = $request->getContext();
$submission = $this->getSubmission();
$submissionId = $submission->getId();
$latestRequest=$this->getPrereviewSetting($submission->getId())->setting_value;
$this->setupTemplate($request);
// Create and populate the form
import('plugins.generic.prereviewPlugin.controllers.grid.form.RequestForm');
$prereviewForm = new RequestForm(self::$plugin, $context->getId(), $submissionId, $result, $latestRequest);
$prereviewForm->readInputData();
$save = $prereviewForm->execute();
import('classes.notification.NotificationManager');
$notificationMgr = new NotificationManager();

if($save==true)
{
$notificationMgr->createTrivialNotification(
Application::get()->getRequest()->getUser()->getId(),
NOTIFICATION_TYPE_SUCCESS,
['contents' => __('common.changesSaved')]
);

}else{
$notificationMgr->createTrivialNotification(
Application::get()->getRequest()->getUser()->getId(),
NOTIFICATION_TYPE_ERROR,
['contents' => __('common.error')]);
}
$path = getenv('HTTP_REFERER').'#publication/prereviewTab';
header('Location: '.$path);

}


function getPrereviewSetting($id) {
import('plugins.generic.prereviewPlugin.PrereviewPluginDAO');
$prereview = new PrereviewPluginDAO();
DAORegistry::registerDAO('PrereviewPluginDAO', $prereview);
$preDao = DAORegistry::getDAO('PrereviewPluginDAO');
$result= $preDao->getDataPrereview($id);
return $result;
}
}
Loading

0 comments on commit 82812f1

Please sign in to comment.