-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'checksTranslatorSubmitter-726' into 'main'
Adiciona verificações sobre tradutor e submissor See merge request softwares-pkp/plugins_ojs/scieloTranslationsFields!4
- Loading branch information
Showing
13 changed files
with
581 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace APP\plugins\generic\scieloTranslationsFields\classes; | ||
|
||
use PKP\userGroup\UserGroup; | ||
use APP\submission\Submission; | ||
use APP\author\Author; | ||
use PKP\user\User; | ||
use APP\facades\Repo; | ||
use APP\plugins\generic\scieloTranslationsFields\classes\TranslationsFieldsDAO; | ||
|
||
class FieldsValidator | ||
{ | ||
public function validateDoi(string $doi): bool | ||
{ | ||
return (preg_match('/^10\.\d{4,9}\/[-._;()\/:A-Z0-9]+$/i', $doi) === 1); | ||
} | ||
|
||
public function getTranslatorsUserGroup(int $contextId): ?UserGroup | ||
{ | ||
$contextUserGroups = Repo::userGroup()->getCollector() | ||
->filterByContextIds([$contextId]) | ||
->getMany(); | ||
|
||
foreach ($contextUserGroups as $userGroup) { | ||
$userGroupAbbrev = strtolower($userGroup->getData('abbrev', 'en')); | ||
|
||
if ($userGroupAbbrev === 'tr') { | ||
return $userGroup; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function submissionHasTranslator(Submission $submission, int $translatorsUserGroupId): bool | ||
{ | ||
$publication = $submission->getCurrentPublication(); | ||
$authors = $publication->getData('authors'); | ||
|
||
foreach ($authors as $author) { | ||
$authorUserGroupId = $author->getData('userGroupId'); | ||
|
||
if ($authorUserGroupId == $translatorsUserGroupId) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function translatorsHaveOrcid(Submission $submission, int $translatorsUserGroupId): bool | ||
{ | ||
$publication = $submission->getCurrentPublication(); | ||
$authors = $publication->getData('authors'); | ||
|
||
foreach ($authors as $author) { | ||
$authorUserGroupId = $author->getData('userGroupId'); | ||
|
||
if ($authorUserGroupId == $translatorsUserGroupId) { | ||
$authorOrcid = $author->getData('orcid'); | ||
|
||
if (empty($authorOrcid)) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function getSubmitterUser(int $submissionId): ?User | ||
{ | ||
$translationsFieldsDao = new TranslationsFieldsDAO(); | ||
$submitterId = $translationsFieldsDao->getSubmitterId($submissionId); | ||
|
||
if (is_null($submitterId)) { | ||
return null; | ||
} | ||
|
||
return Repo::user()->get($submitterId); | ||
} | ||
|
||
public function getContributorForUser(Submission $submission, User $user): ?Author | ||
{ | ||
$publication = $submission->getCurrentPublication(); | ||
$userEmail = $user->getData('email'); | ||
|
||
foreach ($publication->getData('authors') as $author) { | ||
if ($author->getData('email') == $userEmail) { | ||
return $author; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace APP\plugins\generic\scieloTranslationsFields\classes; | ||
|
||
use PKP\db\DAO; | ||
use Illuminate\Support\Facades\DB; | ||
use PKP\security\Role; | ||
|
||
class TranslationsFieldsDAO extends DAO | ||
{ | ||
public function getSubmitterId($submissionId) | ||
{ | ||
$result = DB::table('stage_assignments AS sa') | ||
->leftJoin('user_groups AS ug', 'sa.user_group_id', '=', 'ug.user_group_id') | ||
->where('sa.submission_id', $submissionId) | ||
->where('ug.role_id', Role::ROLE_ID_AUTHOR) | ||
->select('sa.user_id') | ||
->first(); | ||
|
||
if (!$result) { | ||
return null; | ||
} | ||
|
||
return get_object_vars($result)['user_id']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.