Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 182 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
MentorTools | |
0.00% |
0 / 182 |
|
0.00% |
0 / 7 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMentorWeight | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getBody | |
0.00% |
0 / 153 |
|
0.00% |
0 / 1 |
2 | |||
maybeGetAwayMessage | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
getMobileSummaryBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getJsConfigVars | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\MentorDashboard\Modules; |
4 | |
5 | use GrowthExperiments\MentorDashboard\MentorTools\IMentorWeights; |
6 | use GrowthExperiments\MentorDashboard\MentorTools\MentorStatusManager; |
7 | use GrowthExperiments\Mentorship\Provider\MentorProvider; |
8 | use LogicException; |
9 | use MediaWiki\Context\IContextSource; |
10 | use MediaWiki\Html\Html; |
11 | use MediaWiki\SpecialPage\SpecialPage; |
12 | use OOUI\ButtonWidget; |
13 | use OOUI\DropdownInputWidget; |
14 | |
15 | class MentorTools extends BaseModule { |
16 | |
17 | /** @var string Base CSS class for this module */ |
18 | private const BASE_MODULE_CSS_CLASS = 'growthexperiments-mentor-dashboard-module-mentor-tools'; |
19 | |
20 | private MentorProvider $mentorProvider; |
21 | private MentorStatusManager $mentorStatusManager; |
22 | |
23 | /** |
24 | * @param string $name |
25 | * @param IContextSource $ctx |
26 | * @param MentorProvider $mentorProvider |
27 | * @param MentorStatusManager $mentorStatusManager |
28 | */ |
29 | public function __construct( |
30 | $name, |
31 | IContextSource $ctx, |
32 | MentorProvider $mentorProvider, |
33 | MentorStatusManager $mentorStatusManager |
34 | ) { |
35 | parent::__construct( $name, $ctx ); |
36 | |
37 | $this->mentorProvider = $mentorProvider; |
38 | $this->mentorStatusManager = $mentorStatusManager; |
39 | } |
40 | |
41 | /** |
42 | * @inheritDoc |
43 | */ |
44 | protected function getHeaderText() { |
45 | return $this->msg( 'growthexperiments-mentor-dashboard-mentor-tools-headline' )->text(); |
46 | } |
47 | |
48 | /** |
49 | * @return int |
50 | */ |
51 | private function getMentorWeight() { |
52 | return $this->mentorProvider |
53 | ->newMentorFromUserIdentity( $this->getUser() ) |
54 | ->getWeight(); |
55 | } |
56 | |
57 | /** |
58 | * @inheritDoc |
59 | */ |
60 | protected function getBody() { |
61 | $weightOptions = [ |
62 | [ |
63 | 'data' => IMentorWeights::WEIGHT_NONE, |
64 | 'label' => $this->msg( |
65 | 'growthexperiments-mentor-dashboard-mentor-tools-mentor-weight-none' |
66 | )->text() |
67 | ], |
68 | [ |
69 | 'data' => IMentorWeights::WEIGHT_LOW, |
70 | 'label' => $this->msg( |
71 | 'growthexperiments-mentor-dashboard-mentor-tools-mentor-weight-low' |
72 | )->text(), |
73 | ], |
74 | [ |
75 | 'data' => IMentorWeights::WEIGHT_NORMAL, |
76 | 'label' => $this->msg( |
77 | 'growthexperiments-mentor-dashboard-mentor-tools-mentor-weight-medium' |
78 | )->text(), |
79 | ], |
80 | [ |
81 | 'data' => IMentorWeights::WEIGHT_HIGH, |
82 | 'label' => $this->msg( |
83 | 'growthexperiments-mentor-dashboard-mentor-tools-mentor-weight-high' |
84 | )->text(), |
85 | ], |
86 | ]; |
87 | |
88 | return implode( "\n", [ |
89 | Html::rawElement( |
90 | 'div', |
91 | [ 'class' => self::BASE_MODULE_CSS_CLASS . '-status' ], |
92 | implode( "\n", [ |
93 | Html::element( |
94 | 'h4', |
95 | [], |
96 | $this->msg( 'growthexperiments-mentor-dashboard-mentor-tools-mentor-status-headline' ) |
97 | ->text() |
98 | ), |
99 | // keep in sync with ext.growthExperiments.MentorDashboard/MentorTools.js |
100 | new DropdownInputWidget( [ |
101 | 'id' => 'growthexperiments-mentor-dashboard-mentor-tools-mentor-status-dropdown', |
102 | 'infusable' => true, |
103 | 'disabled' => !$this->mentorStatusManager->canChangeStatus( |
104 | $this->getUser() |
105 | )->isOK(), |
106 | 'value' => $this->mentorStatusManager->getMentorStatus( |
107 | $this->getUser() |
108 | ), |
109 | 'options' => [ |
110 | [ |
111 | 'data' => MentorStatusManager::STATUS_ACTIVE, |
112 | 'label' => $this->msg( |
113 | 'growthexperiments-mentor-dashboard-mentor-tools-mentor-status-active' |
114 | )->text(), |
115 | ], |
116 | [ |
117 | 'data' => MentorStatusManager::STATUS_AWAY, |
118 | 'label' => $this->msg( |
119 | 'growthexperiments-mentor-dashboard-mentor-tools-mentor-status-away' |
120 | )->text(), |
121 | ], |
122 | ] |
123 | ] ), |
124 | Html::element( |
125 | 'p', |
126 | [ |
127 | 'id' => self::BASE_MODULE_CSS_CLASS . '-status-away-message' |
128 | ], |
129 | $this->maybeGetAwayMessage() |
130 | ) |
131 | ] ) |
132 | ), |
133 | Html::rawElement( |
134 | 'div', |
135 | [ 'class' => self::BASE_MODULE_CSS_CLASS . '-mentor-weight' ], |
136 | implode( "\n", [ |
137 | Html::element( |
138 | 'h4', |
139 | [], |
140 | $this->msg( 'growthexperiments-mentor-dashboard-mentor-tools-mentor-weight-headline' ) |
141 | ->text() |
142 | ), |
143 | // keep in sync with ext.growthExperiments.MentorDashboard/MentorTools.js |
144 | new DropdownInputWidget( [ |
145 | 'id' => 'growthexperiments-mentor-dashboard-mentor-tools-mentor-weight-dropdown', |
146 | 'infusable' => true, |
147 | 'value' => $this->getMentorWeight(), |
148 | 'options' => $weightOptions |
149 | ] ) |
150 | ] ) |
151 | ), |
152 | Html::rawElement( |
153 | 'div', |
154 | [ 'class' => self::BASE_MODULE_CSS_CLASS . '-message' ], |
155 | implode( "\n", [ |
156 | Html::rawElement( |
157 | 'div', |
158 | [ |
159 | 'class' => self::BASE_MODULE_CSS_CLASS . '-mentor-message-headline-container' |
160 | ], |
161 | implode( "\n", [ |
162 | Html::element( |
163 | 'h4', |
164 | [], |
165 | $this->msg( 'growthexperiments-mentor-dashboard-mentor-tools-mentor-message-headline' ) |
166 | ->text() |
167 | ), |
168 | new ButtonWidget( [ |
169 | 'icon' => 'edit', |
170 | 'framed' => false, |
171 | 'id' => 'growthexperiments-mentor-dashboard-mentor-tools-signup-button', |
172 | 'infusable' => true, |
173 | 'href' => $this->mentorProvider->getSignupTitle()->getLocalURL() |
174 | ] ), |
175 | ] ) |
176 | ), |
177 | Html::element( |
178 | 'div', |
179 | [ |
180 | 'id' => self::BASE_MODULE_CSS_CLASS . '-message-content' |
181 | ], |
182 | $this->mentorProvider->newMentorFromUserIdentity( $this->getUser() ) |
183 | ->getIntroText() |
184 | ) |
185 | ] ) |
186 | ), |
187 | Html::rawElement( |
188 | 'div', |
189 | [ 'class' => self::BASE_MODULE_CSS_CLASS . '-other-actions' ], |
190 | implode( "\n", [ |
191 | Html::rawElement( |
192 | 'div', |
193 | [ |
194 | 'class' => self::BASE_MODULE_CSS_CLASS . '-claim-mentee' |
195 | ], |
196 | implode( "\n", [ |
197 | new ButtonWidget( [ |
198 | 'label' => $this->msg( |
199 | 'growthexperiments-mentor-dashboard-mentor-tools-claim-mentee' |
200 | ), |
201 | 'href' => SpecialPage::getTitleFor( 'ClaimMentee' )->getLocalURL() |
202 | ] ), |
203 | Html::element( |
204 | 'p', |
205 | [ |
206 | 'class' => self::BASE_MODULE_CSS_CLASS . '-claim-mentee-footer' |
207 | ], |
208 | $this->msg( |
209 | 'growthexperiments-mentor-dashboard-mentor-tools-claim-mentee-footer' |
210 | )->text() |
211 | ) |
212 | ] ) |
213 | ) |
214 | ] ) |
215 | ) |
216 | ] ); |
217 | } |
218 | |
219 | /** |
220 | * @return string |
221 | */ |
222 | private function maybeGetAwayMessage(): string { |
223 | $awayReason = $this->mentorStatusManager->getAwayReason( $this->getUser() ); |
224 | if ( $awayReason === null ) { |
225 | // user is not away |
226 | return ''; |
227 | } |
228 | |
229 | switch ( $awayReason ) { |
230 | case MentorStatusManager::AWAY_BECAUSE_TIMESTAMP: |
231 | return $this->msg( |
232 | 'growthexperiments-mentor-dashboard-mentor-tools-mentor-status-away-message', |
233 | $this->getContext()->getLanguage()->date( |
234 | (string)$this->mentorStatusManager->getMentorBackTimestamp( $this->getUser() ), |
235 | true |
236 | ) |
237 | )->text(); |
238 | case MentorStatusManager::AWAY_BECAUSE_BLOCK: |
239 | return $this->msg( |
240 | 'growthexperiments-mentor-dashboard-mentor-tools-mentor-status-away-block' |
241 | )->text(); |
242 | default: |
243 | throw new LogicException( |
244 | 'MentorStatusManager::getAwayReason returned unknown reason' |
245 | ); |
246 | } |
247 | } |
248 | |
249 | /** |
250 | * @inheritDoc |
251 | */ |
252 | protected function getMobileSummaryBody() { |
253 | return ''; |
254 | } |
255 | |
256 | /** |
257 | * @inheritDoc |
258 | */ |
259 | protected function getJsConfigVars() { |
260 | $mentor = $this->mentorProvider->newMentorFromUserIdentity( $this->getUser() ); |
261 | |
262 | return [ |
263 | 'GEMentorDashboardMentorIntroMessage' => $mentor->getIntroText(), |
264 | 'GEMentorDashboardMentorIntroMessageMaxLength' => MentorProvider::INTRO_TEXT_LENGTH |
265 | ]; |
266 | } |
267 | } |