Skip to content

Commit ea0addb

Browse files
Merge branch 'firstVersionReport340-878' into 'main'
Cria primeira versão do relatório DEIA - 3.4.0 See merge request softwares-pkp/plugins_ojs/deiaSurvey!42
2 parents ae90cda + 806c1ee commit ea0addb

19 files changed

Lines changed: 803 additions & 27 deletions

DeiaSurveyPlugin.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
use PKP\linkAction\LinkAction;
1414
use PKP\linkAction\request\AjaxModal;
1515
use PKP\core\JSONMessage;
16-
use PKP\security\Role;
16+
use PKP\security\Validation;
17+
use PKP\plugins\PluginRegistry;
1718
use APP\plugins\generic\deiaSurvey\classes\DataEncryption;
1819
use APP\plugins\generic\deiaSurvey\classes\migrations\SchemaMigration;
1920
use APP\plugins\generic\deiaSurvey\classes\DefaultQuestionsCreator;
2021
use APP\plugins\generic\deiaSurvey\classes\DemographicDataDAO;
2122
use APP\plugins\generic\deiaSurvey\classes\observers\listeners\MigrateResponsesOnRegistration;
2223
use APP\plugins\generic\deiaSurvey\classes\OrcidClient;
23-
use APP\plugins\generic\deiaSurvey\classes\DataCollectionEmailSender;
2424
use APP\plugins\generic\deiaSurvey\classes\DemographicDataService;
2525
use APP\plugins\generic\deiaSurvey\DeiaSurveySettingsForm;
26-
use APP\plugins\generic\deiaSurvey\classes\facades\Repo;
26+
use APP\plugins\generic\deiaSurvey\report\DeiaSurveyReportPlugin;
2727

2828
class DeiaSurveyPlugin extends GenericPlugin
2929
{
@@ -45,6 +45,7 @@ public function register($category, $path, $mainContextId = null): bool
4545
$context = Application::get()->getRequest()->getContext();
4646
if (!is_null($context)) {
4747
$this->loadDispatcherClasses();
48+
$this->registerReportPlugin();
4849
}
4950
}
5051
return $success;
@@ -60,6 +61,14 @@ public function getDescription()
6061
return __('plugins.generic.deiaSurvey.description');
6162
}
6263

64+
public function registerReportPlugin()
65+
{
66+
if (Validation::isSiteAdmin()) {
67+
$reportPlugin = new DeiaSurveyReportPlugin();
68+
PluginRegistry::register('reports', $reportPlugin, $this->getPluginPath());
69+
}
70+
}
71+
6372
private function registerHooksForCustomSchemas()
6473
{
6574
Hook::add('Schema::get::demographicQuestion', [$this, 'addCustomSchema']);
@@ -89,7 +98,6 @@ public function setEnabled($enabled)
8998
$notificationMessage = 'plugins.generic.deiaSurvey.settings.encryptionSecretNotDefined';
9099
$notificationMgr->createTrivialNotification($currentUser->getId(), Notification::NOTIFICATION_TYPE_WARNING, ['contents' => __($notificationMessage)]);
91100
}
92-
93101
}
94102

95103
parent::setEnabled($enabled);
@@ -159,9 +167,9 @@ private function getJsonSchema(string $schemaName): ?\stdClass
159167
if (!$schema) {
160168
throw new \Exception(
161169
'Schema failed to decode. This usually means it is invalid JSON. Requested: '
162-
. $schemaFile
163-
. '. Last JSON error: '
164-
. json_last_error()
170+
. $schemaFile
171+
. '. Last JSON error: '
172+
. json_last_error()
165173
);
166174
}
167175
}
@@ -170,7 +178,7 @@ private function getJsonSchema(string $schemaName): ?\stdClass
170178

171179
public function setupTabHandler($hookName, $params)
172180
{
173-
$component = & $params[0];
181+
$component = &$params[0];
174182
if ($component == 'plugins.generic.deiaSurvey.classes.controllers.TabHandler') {
175183
return true;
176184
}
@@ -196,7 +204,7 @@ public function redirectUserAfterLogin(string $hookName, array $params)
196204

197205
$request = Application::get()->getRequest();
198206
if ($this->userShouldBeRedirected($request)) {
199-
$url = $request->getDispatcher()->url($request, ROUTE_PAGE, null, 'user', 'profile');
207+
$url = $request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, 'user', 'profile');
200208
}
201209
}
202210

@@ -212,17 +220,7 @@ public function userShouldBeRedirected($request)
212220
$demographicDataDao = new DemographicDataDAO();
213221
$userHasConsent = $demographicDataDao->userHasDemographicConsent($user->getId());
214222

215-
return !$userHasConsent && $this->userHasMandatoryFilling($user, $context);
216-
}
217-
218-
private function userHasMandatoryFilling($user, $context)
219-
{
220-
$userRoles = $user->getRoles(Application::CONTEXT_SITE);
221-
$userRoles = array_map(function ($role) {
222-
return $role->getRoleId();
223-
}, $userRoles);
224-
225-
return !in_array(Role::ROLE_ID_SITE_ADMIN, $userRoles);
223+
return !$userHasConsent && !Validation::isSiteAdmin();
226224
}
227225

228226
public function getInstallMigration(): Migration

classes/DefaultQuestionsCreator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function createDefaultQuestions($contextId)
3333
}
3434
}
3535

36-
public function getDefaultQuestionsData(int $contextId): array
36+
public static function getDefaultQuestionsData(int $contextId): array
3737
{
3838
return [
3939
'gender' => [

classes/DemographicDataDAO.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,40 @@ public function thereIsUserWithSetting(string $value, string $type): bool
102102

103103
return $countUsers > 0;
104104
}
105+
106+
public function getConsentStatsByContext(int $contextId): array
107+
{
108+
$results = DB::table('user_settings')
109+
->where('setting_name', '=', 'demographicDataConsent')
110+
->get();
111+
112+
$consentCount = 0;
113+
$noConsentCount = 0;
114+
115+
foreach ($results as $result) {
116+
$setting = get_object_vars($result);
117+
$settingValue = json_decode($setting['setting_value'], true);
118+
119+
// Handles wrong data structure used in previous versions
120+
if (array_key_exists('contextId', $settingValue)) {
121+
$settingValue = [$settingValue];
122+
}
123+
124+
foreach ($settingValue as $contextConsent) {
125+
if ($contextConsent['contextId'] == $contextId) {
126+
if ($contextConsent['consentOption']) {
127+
$consentCount++;
128+
} else {
129+
$noConsentCount++;
130+
}
131+
break;
132+
}
133+
}
134+
}
135+
136+
return [
137+
'consentCount' => $consentCount,
138+
'noConsentCount' => $noConsentCount
139+
];
140+
}
105141
}

classes/migrations/LocalizeQuestionsTextsMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LocalizeQuestionsTextsMigration extends Migration
1515
public function up(): void
1616
{
1717
$allQuestions = Repo::demographicQuestion()->getCollector()->getMany();
18-
$defaultQuestionsData = (new DefaultQuestionsCreator())->getDefaultQuestionsData(0);
18+
$defaultQuestionsData = DefaultQuestionsCreator::getDefaultQuestionsData(0);
1919

2020
foreach ($allQuestions as $question) {
2121
$isPreviousStandardQuestion = $this->isPreviousStandardQuestion($question);

cypress/tests/Test4_report.cy.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
describe('DEIA Survey - Report feature', function () {
2+
it('Report should be visible only for admin user', function () {
3+
cy.login('admin', 'admin', 'publicknowledge');
4+
cy.contains('.app__navItem', 'Reports').click();
5+
cy.contains('a', 'DEIA Survey Report');
6+
cy.logout();
7+
8+
cy.login('dbarnes', null, 'publicknowledge');
9+
cy.contains('.app__navItem', 'Reports').click();
10+
cy.contains('a', 'DEIA Survey Report').should('not.exist');
11+
cy.logout();
12+
});
13+
});

locale/en/locale.po

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,25 @@ msgid "plugins.generic.deiaSurvey.defaultQuestion.ethnicity.responseOption.prefe
249249
msgstr "Prefer not to inform"
250250

251251
msgid "plugins.generic.deiaSurvey.defaultQuestion.ethnicity.responseOption.selfDescribe"
252-
msgstr "Self describe"
252+
msgstr "Self describe"
253+
254+
255+
256+
257+
msgid "plugins.generic.deiaSurvey.report.displayName"
258+
msgstr "DEIA Survey Report"
259+
260+
msgid "plugins.generic.deiaSurvey.report.description"
261+
msgstr "Generates a report of the DEIA data collected for the current context through the DEIA Survey"
262+
263+
msgid "plugins.generic.deiaSurvey.report.contextName.ojs2"
264+
msgstr "Journal Name"
265+
266+
msgid "plugins.generic.deiaSurvey.report.contextName.ops"
267+
msgstr "Preprint Server Name"
268+
269+
msgid "plugins.generic.deiaSurvey.report.usersWhoConsented"
270+
msgstr "Users Who Consented"
271+
272+
msgid "plugins.generic.deiaSurvey.report.usersWhoDidNotConsent"
273+
msgstr "Users Who Did Not Consent"

locale/es/locale.po

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,25 @@ msgid "plugins.generic.deiaSurvey.defaultQuestion.ethnicity.responseOption.prefe
248248
msgstr "Prefiero no informar"
249249

250250
msgid "plugins.generic.deiaSurvey.defaultQuestion.ethnicity.responseOption.selfDescribe"
251-
msgstr "Autodescripción"
251+
msgstr "Autodescripción"
252+
253+
254+
255+
256+
msgid "plugins.generic.deiaSurvey.report.displayName"
257+
msgstr "Informe del Cuestionario DEIA"
258+
259+
msgid "plugins.generic.deiaSurvey.report.description"
260+
msgstr "Genera un informe de los datos DEIA recopilados para el contexto actual a través del Cuestionario DEIA"
261+
262+
msgid "plugins.generic.deiaSurvey.report.contextName.ojs2"
263+
msgstr "Nombre de la Revista"
264+
265+
msgid "plugins.generic.deiaSurvey.report.contextName.ops"
266+
msgstr "Nombre del Servidor de Preprints"
267+
268+
msgid "plugins.generic.deiaSurvey.report.usersWhoConsented"
269+
msgstr "Usuarios que consintieron"
270+
271+
msgid "plugins.generic.deiaSurvey.report.usersWhoDidNotConsent"
272+
msgstr "Usuarios que no consintieron"

locale/pt_BR/locale.po

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,25 @@ msgid "plugins.generic.deiaSurvey.defaultQuestion.ethnicity.responseOption.prefe
248248
msgstr "Prefiro não informar"
249249

250250
msgid "plugins.generic.deiaSurvey.defaultQuestion.ethnicity.responseOption.selfDescribe"
251-
msgstr "Auto-descrição"
251+
msgstr "Auto-descrição"
252+
253+
254+
255+
256+
msgid "plugins.generic.deiaSurvey.report.displayName"
257+
msgstr "Relatório do Questionário DEIA"
258+
259+
msgid "plugins.generic.deiaSurvey.report.description"
260+
msgstr "Gera um relatório dos dados DEIA coletados para o contexto atual por meio do questionário DEIA"
261+
262+
msgid "plugins.generic.deiaSurvey.report.contextName.ojs2"
263+
msgstr "Nome da Revista"
264+
265+
msgid "plugins.generic.deiaSurvey.report.contextName.ops"
266+
msgstr "Nome do Servidor de Preprints"
267+
268+
msgid "plugins.generic.deiaSurvey.report.usersWhoConsented"
269+
msgstr "Usuários que consentiram"
270+
271+
msgid "plugins.generic.deiaSurvey.report.usersWhoDidNotConsent"
272+
msgstr "Usuários que não consentiram"

report/DeiaSurveyReportPlugin.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace APP\plugins\generic\deiaSurvey\report;
4+
5+
use PKP\plugins\ReportPlugin;
6+
use PKP\config\Config;
7+
use APP\plugins\generic\deiaSurvey\report\classes\factories\SiteStatisticsReportFactory;
8+
9+
class DeiaSurveyReportPlugin extends ReportPlugin
10+
{
11+
public function register($category, $path, $mainContextId = null)
12+
{
13+
$success = parent::register($category, $path, $mainContextId);
14+
if ($success && Config::getVar('general', 'installed')) {
15+
$this->addLocaleData();
16+
}
17+
return $success;
18+
}
19+
20+
public function getName()
21+
{
22+
return 'deiaSurveyReportPlugin';
23+
}
24+
25+
public function getDisplayName()
26+
{
27+
return __('plugins.generic.deiaSurvey.report.displayName');
28+
}
29+
30+
public function getDescription()
31+
{
32+
return __('plugins.generic.deiaSurvey.report.description');
33+
}
34+
35+
public function display($args, $request)
36+
{
37+
header('content-type: text/comma-separated-values');
38+
header('content-disposition: attachment; filename=site-deia-report-' . date('Ymd') . '.csv');
39+
40+
$siteStatsReportFactory = new SiteStatisticsReportFactory();
41+
$report = $siteStatsReportFactory->createSiteReport();
42+
$report->writeReport('php://output');
43+
}
44+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace APP\plugins\generic\deiaSurvey\report\classes;
4+
5+
use APP\plugins\generic\deiaSurvey\report\classes\QuestionStatistics;
6+
7+
class ContextStatistics
8+
{
9+
private int $usersConsentCount;
10+
private int $usersNotConsentCount;
11+
private array $questionsStatistics;
12+
13+
public function __construct()
14+
{
15+
$this->usersConsentCount = 0;
16+
$this->usersNotConsentCount = 0;
17+
$this->questionsStatistics = [];
18+
}
19+
20+
public function setUsersConsentCount(int $count): void
21+
{
22+
$this->usersConsentCount = $count;
23+
}
24+
25+
public function getUsersConsentCount(): int
26+
{
27+
return $this->usersConsentCount;
28+
}
29+
30+
public function setUsersNoConsentCount(int $count): void
31+
{
32+
$this->usersNotConsentCount = $count;
33+
}
34+
35+
public function getUsersNoConsentCount(): int
36+
{
37+
return $this->usersNotConsentCount;
38+
}
39+
40+
public function addQuestionStatistics(int $questionId, QuestionStatistics $questionStatistics): void
41+
{
42+
$this->questionsStatistics[$questionId] = $questionStatistics;
43+
}
44+
45+
public function getQuestionStatistics(int $questionId): ?QuestionStatistics
46+
{
47+
return $this->questionsStatistics[$questionId] ?? null;
48+
}
49+
50+
public function printStatistics(array $contextPrintGuide): array
51+
{
52+
$resultStats = [];
53+
54+
foreach ($contextPrintGuide as $questionId => $responseOptionIds) {
55+
$questionStats = $this->getQuestionStatistics($questionId);
56+
57+
if (is_null($questionStats)) {
58+
continue;
59+
}
60+
61+
foreach ($responseOptionIds as $responseOptionId) {
62+
$count = $questionStats->getOptionCount($responseOptionId);
63+
if (!is_null($count)) {
64+
$resultStats[] = $count;
65+
}
66+
}
67+
}
68+
69+
$resultStats[] = $this->getUsersConsentCount();
70+
$resultStats[] = $this->getUsersNoConsentCount();
71+
72+
return $resultStats;
73+
}
74+
}

0 commit comments

Comments
 (0)