Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryMentorList | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Api; |
4 | |
5 | use ApiQuery; |
6 | use ApiQueryBase; |
7 | use GrowthExperiments\Mentorship\Provider\MentorProvider; |
8 | use GrowthExperiments\Mentorship\Provider\StructuredMentorWriter; |
9 | use MediaWiki\User\UserIdentityLookup; |
10 | |
11 | class ApiQueryMentorList extends ApiQueryBase { |
12 | |
13 | private UserIdentityLookup $userIdentityLookup; |
14 | private MentorProvider $mentorProvider; |
15 | |
16 | /** |
17 | * @param ApiQuery $queryModule |
18 | * @param string $moduleName |
19 | * @param UserIdentityLookup $userIdentityLookup |
20 | * @param MentorProvider $mentorProvider |
21 | */ |
22 | public function __construct( |
23 | ApiQuery $queryModule, |
24 | $moduleName, |
25 | UserIdentityLookup $userIdentityLookup, |
26 | MentorProvider $mentorProvider |
27 | ) { |
28 | parent::__construct( $queryModule, $moduleName ); |
29 | $this->userIdentityLookup = $userIdentityLookup; |
30 | $this->mentorProvider = $mentorProvider; |
31 | } |
32 | |
33 | /** |
34 | * @inheritDoc |
35 | */ |
36 | public function execute() { |
37 | $result = []; |
38 | $mentorNames = $this->mentorProvider->getMentorsSafe(); |
39 | foreach ( $mentorNames as $mentorName ) { |
40 | $mentorUser = $this->userIdentityLookup->getUserIdentityByName( $mentorName ); |
41 | if ( !$mentorUser ) { |
42 | continue; |
43 | } |
44 | $mentor = $this->mentorProvider->newMentorFromUserIdentity( $mentorUser ); |
45 | $result[$mentorUser->getId()] = StructuredMentorWriter::serializeMentor( $mentor ); |
46 | |
47 | // for convenience of the consumers |
48 | $result[$mentorUser->getId()]['username'] = $mentorUser->getName(); |
49 | } |
50 | |
51 | // NOTE: Continuation support is not implemented, because all mentors are always |
52 | // stored in MediaWiki:GrowthMentors.json, which (being a regular wiki page) has no |
53 | // continuation support either. |
54 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
55 | } |
56 | } |