Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
58.33% |
14 / 24 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryMentorMentee | |
58.33% |
14 / 24 |
|
33.33% |
1 / 3 |
3.65 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
getAllowedParams | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Api; |
4 | |
5 | use GrowthExperiments\Mentorship\Store\MentorStore; |
6 | use MediaWiki\Api\ApiQuery; |
7 | use MediaWiki\Api\ApiQueryBase; |
8 | use MediaWiki\ParamValidator\TypeDef\UserDef; |
9 | use MediaWiki\User\UserIdentity; |
10 | use Wikimedia\ParamValidator\ParamValidator; |
11 | |
12 | class ApiQueryMentorMentee extends ApiQueryBase { |
13 | |
14 | private MentorStore $mentorStore; |
15 | |
16 | public function __construct( |
17 | ApiQuery $queryModule, |
18 | string $moduleName, |
19 | MentorStore $mentorStore |
20 | ) { |
21 | parent::__construct( $queryModule, $moduleName ); |
22 | |
23 | $this->mentorStore = $mentorStore; |
24 | } |
25 | |
26 | /** |
27 | * @inheritDoc |
28 | */ |
29 | public function execute() { |
30 | $params = $this->extractRequestParams(); |
31 | |
32 | /** @var UserIdentity $mentor */ |
33 | $mentor = $params['gemmmentor']; |
34 | |
35 | $this->getResult()->addValue( null, $this->getModuleName(), [ |
36 | 'mentor' => $mentor->getName(), |
37 | 'mentees' => array_map( static function ( UserIdentity $mentee ) { |
38 | return [ |
39 | 'name' => $mentee->getName(), |
40 | 'id' => $mentee->getId() |
41 | ]; |
42 | }, $this->mentorStore->getMenteesByMentor( |
43 | $mentor, |
44 | MentorStore::ROLE_PRIMARY |
45 | ) ) |
46 | ] ); |
47 | } |
48 | |
49 | /** |
50 | * @inheritDoc |
51 | */ |
52 | protected function getAllowedParams() { |
53 | return [ |
54 | 'gemmmentor' => [ |
55 | ParamValidator::PARAM_TYPE => 'user', |
56 | ParamValidator::PARAM_REQUIRED => true, |
57 | UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'id' ], |
58 | UserDef::PARAM_RETURN_OBJECT => true, |
59 | ] |
60 | ]; |
61 | } |
62 | } |