Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
TranslatorService | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
isTranslator | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace ContentTranslation\Service; |
6 | |
7 | use ContentTranslation\Store\TranslationStore; |
8 | use MediaWiki\User\User; |
9 | |
10 | class TranslatorService { |
11 | |
12 | private UserService $userService; |
13 | private TranslationStore $translationStore; |
14 | |
15 | public function __construct( UserService $userService, TranslationStore $translationStore ) { |
16 | $this->userService = $userService; |
17 | $this->translationStore = $translationStore; |
18 | } |
19 | |
20 | /** |
21 | * Check whether the user has started at least one translation. |
22 | * No need to publish. Translation in any status is fine. |
23 | * |
24 | * @param User $user |
25 | * @return bool |
26 | */ |
27 | public function isTranslator( User $user ): bool { |
28 | try { |
29 | $translatorId = $this->userService->getGlobalUserId( $user ); |
30 | } catch ( \Exception $e ) { |
31 | // Not a global user and not a translator |
32 | return false; |
33 | } |
34 | $translations = $this->translationStore->getAllTranslationsByUserId( $translatorId, 1 ); |
35 | return count( $translations ) > 0; |
36 | } |
37 | |
38 | } |