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 ApiQuery; |
6 | use ApiQueryBase; |
7 | use GrowthExperiments\Mentorship\Store\MentorStore; |
8 | use MediaWiki\ParamValidator\TypeDef\UserDef; |
9 | use MediaWiki\User\UserIdentity; |
10 | use Wikimedia\ParamValidator\ParamValidator; |
11 | |
12 | class ApiQueryMentorMentee extends ApiQueryBase { |
13 | |
14 | /** @var MentorStore */ |
15 | private $mentorStore; |
16 | |
17 | /** |
18 | * @param ApiQuery $queryModule |
19 | * @param string $moduleName |
20 | * @param MentorStore $mentorStore |
21 | */ |
22 | public function __construct( |
23 | ApiQuery $queryModule, |
24 | $moduleName, |
25 | MentorStore $mentorStore |
26 | ) { |
27 | parent::__construct( $queryModule, $moduleName ); |
28 | |
29 | $this->mentorStore = $mentorStore; |
30 | } |
31 | |
32 | /** |
33 | * @inheritDoc |
34 | */ |
35 | public function execute() { |
36 | $params = $this->extractRequestParams(); |
37 | |
38 | /** @var UserIdentity $mentor */ |
39 | $mentor = $params['gemmmentor']; |
40 | |
41 | $this->getResult()->addValue( null, $this->getModuleName(), [ |
42 | 'mentor' => $mentor->getName(), |
43 | 'mentees' => array_map( static function ( UserIdentity $mentee ) { |
44 | return [ |
45 | 'name' => $mentee->getName(), |
46 | 'id' => $mentee->getId() |
47 | ]; |
48 | }, $this->mentorStore->getMenteesByMentor( |
49 | $mentor, |
50 | MentorStore::ROLE_PRIMARY |
51 | ) ) |
52 | ] ); |
53 | } |
54 | |
55 | /** |
56 | * @inheritDoc |
57 | */ |
58 | protected function getAllowedParams() { |
59 | return [ |
60 | 'gemmmentor' => [ |
61 | ParamValidator::PARAM_TYPE => 'user', |
62 | ParamValidator::PARAM_REQUIRED => true, |
63 | UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'id' ], |
64 | UserDef::PARAM_RETURN_OBJECT => true, |
65 | ] |
66 | ]; |
67 | } |
68 | } |