Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryMenteeStatus | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Api; |
4 | |
5 | use ApiQuery; |
6 | use ApiQueryBase; |
7 | use GrowthExperiments\Mentorship\MentorManager; |
8 | |
9 | class ApiQueryMenteeStatus extends ApiQueryBase { |
10 | |
11 | /** @var MentorManager */ |
12 | private $mentorManager; |
13 | |
14 | /** |
15 | * @param ApiQuery $queryModule |
16 | * @param string $moduleName |
17 | * @param MentorManager $mentorManager |
18 | */ |
19 | public function __construct( |
20 | ApiQuery $queryModule, |
21 | $moduleName, |
22 | MentorManager $mentorManager |
23 | ) { |
24 | parent::__construct( $queryModule, $moduleName ); |
25 | |
26 | $this->mentorManager = $mentorManager; |
27 | } |
28 | |
29 | /** |
30 | * @inheritDoc |
31 | */ |
32 | public function execute() { |
33 | if ( !$this->getUser()->isNamed() ) { |
34 | $this->dieWithError( [ 'apierror-permissiondenied-generic' ] ); |
35 | } |
36 | |
37 | switch ( $this->mentorManager->getMentorshipStateForUser( $this->getUser() ) ) { |
38 | case MentorManager::MENTORSHIP_ENABLED: |
39 | $statusHumanReadable = 'enabled'; |
40 | break; |
41 | case MentorManager::MENTORSHIP_DISABLED: |
42 | $statusHumanReadable = 'disabled'; |
43 | break; |
44 | case MentorManager::MENTORSHIP_OPTED_OUT: |
45 | $statusHumanReadable = 'optout'; |
46 | break; |
47 | default: |
48 | $statusHumanReadable = 'unknown'; |
49 | break; |
50 | } |
51 | |
52 | $this->getResult()->addValue( null, $this->getModuleName(), [ |
53 | 'menteestatus' => $statusHumanReadable |
54 | ] ); |
55 | } |
56 | } |