|
@@ -23,6 +23,8 @@ use Logipro\Bundle\PhoenixJupyterBundle\Services\ApiLayer\ApiLayerService;
|
23
|
23
|
use Logipro\Bundle\PhoenixJupyterBundle\Services\Uploader\NotebookUploader;
|
24
|
24
|
|
25
|
25
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
26
|
+use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterSubmission;
|
|
27
|
+use Logipro\Phoenix\Entity\Sequence;
|
26
|
28
|
|
27
|
29
|
class PhoenixServices extends Services
|
28
|
30
|
{
|
|
@@ -30,67 +32,60 @@ class PhoenixServices extends Services
|
30
|
32
|
private $isAvalaible;
|
31
|
33
|
private $layoutPath = '@LogiproPhoenixJupyter/back-office/';
|
32
|
34
|
|
33
|
|
- public function __construct
|
34
|
|
- (
|
|
35
|
+ public function __construct(
|
35
|
36
|
FormFactoryInterface $formFactory,
|
36
|
37
|
EntityManagerInterface $manager,
|
37
|
38
|
RouterInterface $router,
|
38
|
39
|
ApiLayerService $layer,
|
39
|
40
|
NotebookUploader $uploader
|
40
|
|
- )
|
41
|
|
- {
|
42
|
|
- parent::__construct($formFactory,$manager,$router);
|
|
41
|
+ ) {
|
|
42
|
+ parent::__construct($formFactory, $manager, $router);
|
43
|
43
|
|
44
|
44
|
$this->layer = $layer;
|
45
|
45
|
$this->uploader = $uploader;
|
46
|
46
|
}
|
47
|
47
|
|
48
|
|
- /**
|
49
|
|
- * retourne le chemin de la classe de l'entité du bundle
|
50
|
|
- * @return string
|
51
|
|
- */
|
52
|
|
- public function getEntityClass() : string
|
53
|
|
- {
|
54
|
|
- return JupyterVirtualClassroom::class;
|
|
48
|
+ /**
|
|
49
|
+ * retourne le chemin de la classe de l'entité du bundle
|
|
50
|
+ * @return string
|
|
51
|
+ */
|
|
52
|
+ public function getEntityClass(): string
|
|
53
|
+ {
|
|
54
|
+ return JupyterVirtualClassroom::class;
|
55
|
55
|
}
|
56
|
|
-
|
|
56
|
+
|
57
|
57
|
public function serviceIsAvalaible()
|
58
|
58
|
{
|
59
|
|
- if (is_null($this->isAvalaible))
|
60
|
|
- {
|
|
59
|
+ if (is_null($this->isAvalaible)) {
|
61
|
60
|
$this->isAvalaible = $this->layer->serviceIsAvalaible();
|
62
|
61
|
}
|
63
|
62
|
return $this->isAvalaible;
|
64
|
63
|
}
|
65
|
64
|
|
66
|
|
- protected function getApiService()
|
67
|
|
- {
|
68
|
|
- if (!$this->isAvalaible)
|
69
|
|
- {
|
|
65
|
+ protected function getApiService()
|
|
66
|
+ {
|
|
67
|
+ if (!$this->isAvalaible) {
|
70
|
68
|
$this->isAvalaible = $this->layer->serviceIsAvalaible();
|
71
|
69
|
}
|
72
|
|
-
|
73
|
|
- if ($this->isAvalaible)
|
74
|
|
- {
|
|
70
|
+
|
|
71
|
+ if ($this->isAvalaible) {
|
75
|
72
|
return $this->layer;
|
76
|
|
- }
|
77
|
|
- else
|
78
|
|
- {
|
|
73
|
+ } else {
|
79
|
74
|
throw new \Exception('Service Jupyter indisponible');
|
80
|
75
|
}
|
81
|
76
|
return null;
|
82
|
|
- }
|
83
|
|
-
|
84
|
|
- /**
|
85
|
|
- * créé le serveur distant jupyter et persist le token si créé
|
86
|
|
- *
|
87
|
|
- * @param JupyterVirtualClassroom $jupyter
|
88
|
|
- * @param string $fromurl
|
89
|
|
- * @param string $notebookContent
|
90
|
|
- *
|
91
|
|
- * @return string
|
92
|
|
- */
|
93
|
|
- private function createTrainerJupyterServer(JupyterVirtualClassroom $jupyter,$fromurl = null,$notebookContent = null,$useUrl = true) : string
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ /**
|
|
80
|
+ * créé le serveur distant jupyter et persist le token si créé
|
|
81
|
+ *
|
|
82
|
+ * @param JupyterVirtualClassroom $jupyter
|
|
83
|
+ * @param string $fromurl
|
|
84
|
+ * @param string $notebookContent
|
|
85
|
+ *
|
|
86
|
+ * @return string
|
|
87
|
+ */
|
|
88
|
+ private function createTrainerJupyterServer(JupyterVirtualClassroom $jupyter, $fromurl = null, $notebookContent = null, $useUrl = true): string
|
94
|
89
|
{
|
95
|
90
|
ignore_user_abort(true);
|
96
|
91
|
|
|
@@ -98,49 +93,45 @@ class PhoenixServices extends Services
|
98
|
93
|
$trainer = $jupyter->getTrainer();
|
99
|
94
|
$repository = $this->getRepository(JupyterToken::class);
|
100
|
95
|
$token = $repository->findOneBy(array('person' => $trainer));
|
101
|
|
- if (is_null($token))
|
102
|
|
- {
|
|
96
|
+ if (is_null($token)) {
|
103
|
97
|
$token = new JupyterToken();
|
104
|
98
|
$token->setPerson($trainer);
|
105
|
99
|
}
|
106
|
100
|
// test si l'utilisateur a déja un token
|
107
|
101
|
$manager = $this->getManager();
|
108
|
102
|
$layer = $this->getApiService();
|
109
|
|
- $url = $layer->createTrainerServerIfNoneAndSetContent($jupyter,$token,$fromurl,$notebookContent,$useUrl);
|
|
103
|
+ $url = $layer->createTrainerServerIfNoneAndSetContent($jupyter, $token, $fromurl, $notebookContent, $useUrl);
|
110
|
104
|
|
111
|
105
|
// persiste l'entité créé
|
112
|
|
- if ($token && !$token->getTokenId())
|
113
|
|
- {
|
|
106
|
+ if ($token && !$token->getTokenId()) {
|
114
|
107
|
$manager->persist($token);
|
115
|
|
- }
|
116
|
|
- return $url;
|
117
|
|
- }
|
|
108
|
+ }
|
|
109
|
+ return $url;
|
|
110
|
+ }
|
118
|
111
|
|
119
|
|
- /**
|
|
112
|
+ /**
|
120
|
113
|
* retourne le token d'un utilisateur
|
121
|
114
|
*
|
122
|
115
|
* @param Person $person
|
123
|
116
|
* @return JupyterToken/null
|
124
|
117
|
*/
|
125
|
|
- protected function getToken(Person $person)
|
|
118
|
+ protected function getToken(Person $person): JupyterToken
|
126
|
119
|
{
|
127
|
120
|
$tokenRepository = $this->getRepository(JupyterToken::class);
|
128
|
121
|
return $tokenRepository->findOneBy(array('person' => $person));
|
129
|
122
|
}
|
130
|
123
|
|
131
|
124
|
/**
|
132
|
|
- * demarre le serveur
|
133
|
|
- *
|
|
125
|
+ * demarre le serveur
|
|
126
|
+ *
|
134
|
127
|
* @return array: isStarted: dit si le serveur était déja démarré, result: dit si le serveur a été démarré
|
135
|
128
|
*/
|
136
|
129
|
protected function startServer(Person $person)
|
137
|
130
|
{
|
138
|
131
|
$layer = $this->getApiService();
|
139
|
|
- if ($layer)
|
140
|
|
- {
|
|
132
|
+ if ($layer) {
|
141
|
133
|
$token = $this->getToken($person);
|
142
|
|
- if ($token)
|
143
|
|
- {
|
|
134
|
+ if ($token) {
|
144
|
135
|
$response = $layer->startServer($token);
|
145
|
136
|
return $response;
|
146
|
137
|
}
|
|
@@ -149,13 +140,13 @@ class PhoenixServices extends Services
|
149
|
140
|
}
|
150
|
141
|
|
151
|
142
|
|
152
|
|
- /**
|
153
|
|
- * retourne les informations du formateur à partir de la classe
|
154
|
|
- *
|
155
|
|
- * @param JupyterVirtualClassroom $sequenceItem
|
156
|
|
- * @return Array
|
157
|
|
- */
|
158
|
|
- protected function getTrainerDatasBySequenceItem(JupyterVirtualClassroom $sequenceItem) : array
|
|
143
|
+ /**
|
|
144
|
+ * retourne les informations du formateur à partir de la classe
|
|
145
|
+ *
|
|
146
|
+ * @param JupyterVirtualClassroom $sequenceItem
|
|
147
|
+ * @return Array
|
|
148
|
+ */
|
|
149
|
+ protected function getTrainerDatasBySequenceItem(JupyterVirtualClassroom $sequenceItem): array
|
159
|
150
|
{
|
160
|
151
|
$idTrainer = 0;
|
161
|
152
|
$initials = '';
|
|
@@ -165,17 +156,16 @@ class PhoenixServices extends Services
|
165
|
156
|
$avatar = '';
|
166
|
157
|
$visibleInformation = '';
|
167
|
158
|
|
168
|
|
- $trainer = $sequenceItem->getTrainer();
|
169
|
|
-
|
170
|
|
- // test si le formateu est présent
|
171
|
|
- if ($trainer)
|
172
|
|
- {
|
|
159
|
+ $trainer = $sequenceItem->getTrainer();
|
|
160
|
+
|
|
161
|
+ // test si le formateu est présent
|
|
162
|
+ if ($trainer) {
|
173
|
163
|
$idTrainer = $trainer->getPersonId();
|
174
|
164
|
$initials = $trainer->getInitials();
|
175
|
165
|
$fullName = $trainer->getFullName();
|
176
|
166
|
$email = $trainer->getEmail();
|
177
|
167
|
$telephone = $trainer->getTelephone();
|
178
|
|
- $avatar = "";//$this->renderString("{{ phx_get_avatar(phx_uploader_asset(person,'imageFile'), initials, 'sm')|raw }}" , array('person' => $trainer, 'initials' => $trainer->getInitials()));
|
|
168
|
+ $avatar = ""; //$this->renderString("{{ phx_get_avatar(phx_uploader_asset(person,'imageFile'), initials, 'sm')|raw }}" , array('person' => $trainer, 'initials' => $trainer->getInitials()));
|
179
|
169
|
$visibleInformation = $trainer->getVisibleInformation();
|
180
|
170
|
}
|
181
|
171
|
|
|
@@ -191,80 +181,75 @@ class PhoenixServices extends Services
|
191
|
181
|
}
|
192
|
182
|
|
193
|
183
|
|
194
|
|
- /**
|
195
|
|
- * retourne le bouton pour ajouter le JupyterVirtualClassroom au parcours
|
196
|
|
- *
|
197
|
|
- * @return ButtonLayer
|
198
|
|
- */
|
199
|
|
- public function getButton() : ButtonLayer
|
200
|
|
- {
|
201
|
|
- $button = new ButtonLayer();
|
202
|
|
-
|
203
|
|
- $button->setImage('icon-jupyter.svg');
|
204
|
|
- $button->setText('Jupyter');
|
205
|
|
- $button->setClass('ali-EditorJupyterCreate');
|
206
|
|
- $button->setHelp('Notebook Jupyter');
|
207
|
|
-
|
208
|
|
- return $button;
|
209
|
|
- }
|
210
|
|
-
|
211
|
|
- /**
|
212
|
|
- * retourne le code html de la modal pour ajouter un JupyterVirtualClassroom au aprcours
|
213
|
|
- *
|
214
|
|
- * @return ModalLayer
|
215
|
|
- */
|
216
|
|
- public function getModalAdd() : ModalLayer
|
217
|
|
- {
|
218
|
|
- $modal = new ModalLayer();
|
219
|
|
-
|
|
184
|
+ /**
|
|
185
|
+ * retourne le bouton pour ajouter le JupyterVirtualClassroom au parcours
|
|
186
|
+ *
|
|
187
|
+ * @return ButtonLayer
|
|
188
|
+ */
|
|
189
|
+ public function getButton(): ButtonLayer
|
|
190
|
+ {
|
|
191
|
+ $button = new ButtonLayer();
|
|
192
|
+
|
|
193
|
+ $button->setImage('icon-jupyter.svg');
|
|
194
|
+ $button->setText('Jupyter');
|
|
195
|
+ $button->setClass('ali-EditorJupyterCreate');
|
|
196
|
+ $button->setHelp('Notebook Jupyter');
|
|
197
|
+
|
|
198
|
+ return $button;
|
|
199
|
+ }
|
|
200
|
+
|
|
201
|
+ /**
|
|
202
|
+ * retourne le code html de la modal pour ajouter un JupyterVirtualClassroom au aprcours
|
|
203
|
+ *
|
|
204
|
+ * @return ModalLayer
|
|
205
|
+ */
|
|
206
|
+ public function getModalAdd(): ModalLayer
|
|
207
|
+ {
|
|
208
|
+ $modal = new ModalLayer();
|
|
209
|
+
|
220
|
210
|
$jupyter = new JupyterVirtualClassroom();
|
221
|
|
- $form = $this->createForm(JupyterCreateType::class, $jupyter);
|
|
211
|
+ $form = $this->createForm(JupyterCreateType::class, $jupyter);
|
222
|
212
|
|
223
|
|
- $modal->setTitle('Créer une activité Jupyter');
|
|
213
|
+ $modal->setTitle('Créer une activité Jupyter');
|
224
|
214
|
$modal->setCss('test_css.css');
|
225
|
215
|
$modal->setScript('back-office.js');
|
226
|
|
-
|
227
|
|
- $modal->setForm($form->createView());
|
228
|
|
- $modal->setLayout($this->layoutPath . 'formCreate.html.twig');
|
229
|
|
-
|
230
|
|
- return $modal;
|
231
|
|
- }
|
232
|
|
-
|
233
|
|
- /**
|
234
|
|
- * valide le formulaire du ModalLayer et retourne l'identifiant du nouveau JupyterVirtualClassroom
|
235
|
|
- *
|
236
|
|
- * @param Request $request
|
237
|
|
- * @param Sequence $sequence
|
238
|
|
- * @param int $order
|
239
|
|
- *
|
240
|
|
- * @return int
|
241
|
|
- */
|
242
|
|
- public function validateModalAdd(Request $request,$sequence,$order)
|
243
|
|
- {
|
244
|
|
- $jupyter = new JupyterVirtualClassroom();
|
|
216
|
+
|
|
217
|
+ $modal->setForm($form->createView());
|
|
218
|
+ $modal->setLayout($this->layoutPath . 'formCreate.html.twig');
|
|
219
|
+
|
|
220
|
+ return $modal;
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ /**
|
|
224
|
+ * valide le formulaire du ModalLayer et retourne l'identifiant du nouveau JupyterVirtualClassroom
|
|
225
|
+ *
|
|
226
|
+ * @param Request $request
|
|
227
|
+ * @param Sequence $sequence
|
|
228
|
+ * @param int $order
|
|
229
|
+ *
|
|
230
|
+ * @return int
|
|
231
|
+ */
|
|
232
|
+ public function validateModalAdd(Request $request, Sequence $sequence, $order)
|
|
233
|
+ {
|
|
234
|
+ $jupyter = new JupyterVirtualClassroom();
|
245
|
235
|
$jupyter->setSequence($sequence);
|
246
|
236
|
|
247
|
237
|
$form = $this->createForm(JupyterCreateType::class, $jupyter);
|
248
|
238
|
|
249
|
239
|
// Traitement du POST
|
250
|
|
- if ($request->isMethod('POST'))
|
251
|
|
- {
|
|
240
|
+ if ($request->isMethod('POST')) {
|
252
|
241
|
// envoi post non ajax => 404
|
253
|
|
- if (!$request->isXmlHttpRequest())
|
254
|
|
- {
|
|
242
|
+ if (!$request->isXmlHttpRequest()) {
|
255
|
243
|
throw $this->createNotFoundException();
|
256
|
244
|
}
|
257
|
245
|
|
258
|
246
|
$form->handleRequest($request);
|
259
|
|
- if ($form->isSubmitted())
|
260
|
|
- {
|
261
|
|
- if ($form->isValid())
|
262
|
|
- {
|
|
247
|
+ if ($form->isSubmitted()) {
|
|
248
|
+ if ($form->isValid()) {
|
263
|
249
|
// créé la classe distante
|
264
|
250
|
$repository = $this->getRepository(Trainer::class);
|
265
|
251
|
$trainer = $jupyter->getTrainer();
|
266
|
|
- if ($trainer)
|
267
|
|
- {
|
|
252
|
+ if ($trainer) {
|
268
|
253
|
$jupyter->setTrainer($trainer);
|
269
|
254
|
$this->createTrainerJupyterServer($jupyter);
|
270
|
255
|
}
|
|
@@ -276,117 +261,110 @@ class PhoenixServices extends Services
|
276
|
261
|
$manager->flush();
|
277
|
262
|
|
278
|
263
|
return $jupyter->getSequenceItemId();
|
279
|
|
- }
|
280
|
|
- else
|
281
|
|
- {
|
|
264
|
+ } else {
|
282
|
265
|
throw new \InvalidArgumentException($form->getErrors(true));
|
283
|
266
|
}
|
284
|
|
- }
|
285
|
|
- else
|
286
|
|
- {
|
|
267
|
+ } else {
|
287
|
268
|
throw new \InvalidArgumentException($form->getErrors(true));
|
288
|
269
|
}
|
289
|
270
|
}
|
290
|
271
|
return null;
|
291
|
|
- }
|
292
|
|
-
|
293
|
|
- /**
|
294
|
|
- * retourne les variables necessaire pour l'affichage du bloc au niveau du parcours
|
295
|
|
- *
|
296
|
|
- * @return array
|
297
|
|
- */
|
298
|
|
- public function getBlocVariables($item)
|
299
|
|
- {
|
300
|
|
- return array(
|
301
|
|
- 'sequenceItemClass' => 'ali-SequenceJupyterClassroom',
|
302
|
|
- 'label' => 'Jupyter',
|
303
|
|
- 'imageClass' => 'ali-EditorJupyterEdit',
|
304
|
|
- 'image' => "bundles/logiprophoenixjupyter/images/icon-jupyter.svg",
|
305
|
|
- 'description' => 'toto',
|
306
|
|
- 'bottom_layout' => '@LogiproPhoenixJupyter/back-office/blocBottom.html.twig'
|
307
|
|
- );
|
308
|
|
- }
|
309
|
|
-
|
310
|
|
- public function getLearningSpaceBlocVariables($item)
|
311
|
|
- {
|
312
|
|
- return array(
|
313
|
|
- 'middle_layout' => '@LogiproPhoenixJupyter/learning_space/blocMiddle.html.twig',
|
314
|
|
- 'bottom_layout' => '@LogiproPhoenixJupyter/learning_space/blocBottom.html.twig',
|
315
|
|
- 'hide_trainer' => true,
|
316
|
|
- 'image' => "bundles/logiprophoenixjupyter/images/icon-ls-jupyter.svg",
|
317
|
|
- 'type' => ($item->getIsAssesment())?'JupyterEval':'Jupyter',
|
318
|
|
- 'type_name' => ($item->getIsAssesment())?'Évaluation':'Jupyter',
|
319
|
|
- 'notebookname' => basename($item->getUrl()),
|
320
|
|
- );
|
321
|
|
- }
|
322
|
|
-
|
323
|
|
- public function getLearningSpaceScript()
|
324
|
|
- {
|
325
|
|
- return 'bundles/logiprophoenixjupyter/Js/learning-space.js';
|
326
|
|
- }
|
327
|
|
-
|
328
|
|
- public function getLearningSpaceCss()
|
329
|
|
- {
|
330
|
|
- return 'bundles/logiprophoenixjupyter/Css/learning-space.css';
|
331
|
|
- }
|
332
|
|
-
|
333
|
|
-
|
334
|
|
- /**
|
335
|
|
- * retourne le FormLayer pour l'édition du JupyterVirtualClassroom
|
336
|
|
- *
|
337
|
|
- * @param JupyterVirtualClassroom $jupyterVirtualClassroom
|
338
|
|
- *
|
339
|
|
- * @return FormLayer
|
340
|
|
- */
|
341
|
|
- public function getHtmlEdit(JupyterVirtualClassroom $jupyterVirtualClassroom) : FormLayer
|
342
|
|
- {
|
343
|
|
- $formLayer = new FormLayer();
|
|
272
|
+ }
|
|
273
|
+
|
|
274
|
+ /**
|
|
275
|
+ * retourne les variables necessaire pour l'affichage du bloc au niveau du parcours
|
|
276
|
+ *
|
|
277
|
+ * @return array
|
|
278
|
+ */
|
|
279
|
+ public function getBlocVariables($item)
|
|
280
|
+ {
|
|
281
|
+ return array(
|
|
282
|
+ 'sequenceItemClass' => 'ali-SequenceJupyterClassroom',
|
|
283
|
+ 'label' => 'Jupyter',
|
|
284
|
+ 'imageClass' => 'ali-EditorJupyterEdit',
|
|
285
|
+ 'image' => "bundles/logiprophoenixjupyter/images/icon-jupyter.svg",
|
|
286
|
+ 'description' => 'toto',
|
|
287
|
+ 'bottom_layout' => '@LogiproPhoenixJupyter/back-office/blocBottom.html.twig'
|
|
288
|
+ );
|
|
289
|
+ }
|
|
290
|
+
|
|
291
|
+ public function getLearningSpaceBlocVariables($item)
|
|
292
|
+ {
|
|
293
|
+ return array(
|
|
294
|
+ 'middle_layout' => '@LogiproPhoenixJupyter/learning_space/blocMiddle.html.twig',
|
|
295
|
+ 'bottom_layout' => '@LogiproPhoenixJupyter/learning_space/blocBottom.html.twig',
|
|
296
|
+ 'hide_trainer' => true,
|
|
297
|
+ 'image' => "bundles/logiprophoenixjupyter/images/icon-ls-jupyter.svg",
|
|
298
|
+ 'type' => ($item->getIsAssesment()) ? 'JupyterEval' : 'Jupyter',
|
|
299
|
+ 'type_name' => ($item->getIsAssesment()) ? 'Évaluation' : 'Jupyter',
|
|
300
|
+ 'notebookname' => basename($item->getUrl()),
|
|
301
|
+ );
|
|
302
|
+ }
|
|
303
|
+
|
|
304
|
+ public function getLearningSpaceScript()
|
|
305
|
+ {
|
|
306
|
+ return 'bundles/logiprophoenixjupyter/Js/learning-space.js';
|
|
307
|
+ }
|
|
308
|
+
|
|
309
|
+ public function getLearningSpaceCss()
|
|
310
|
+ {
|
|
311
|
+ return 'bundles/logiprophoenixjupyter/Css/learning-space.css';
|
|
312
|
+ }
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+ /**
|
|
316
|
+ * retourne le FormLayer pour l'édition du JupyterVirtualClassroom
|
|
317
|
+ *
|
|
318
|
+ * @param JupyterVirtualClassroom $jupyterVirtualClassroom
|
|
319
|
+ *
|
|
320
|
+ * @return FormLayer
|
|
321
|
+ */
|
|
322
|
+ public function getHtmlEdit(JupyterVirtualClassroom $jupyterVirtualClassroom): FormLayer
|
|
323
|
+ {
|
|
324
|
+ $formLayer = new FormLayer();
|
344
|
325
|
|
345
|
326
|
$options['search_action'] = $this->generateUrl('nbo_user_search_trainer');
|
346
|
327
|
$options['replacement_value'] = $this->getTrainerDatasBySequenceItem($jupyterVirtualClassroom);
|
347
|
328
|
|
348
|
|
- $form = $form = $this->createForm(JupyterUpdateType::class, $jupyterVirtualClassroom,$options);
|
|
329
|
+ $form = $form = $this->createForm(JupyterUpdateType::class, $jupyterVirtualClassroom, $options);
|
349
|
330
|
|
350
|
331
|
$formLayer->setForm($form);
|
351
|
332
|
$formLayer->setLayout($this->layoutPath . 'formUpdate.html.twig');
|
352
|
333
|
|
353
|
|
- return $formLayer;
|
354
|
|
- }
|
|
334
|
+ return $formLayer;
|
|
335
|
+ }
|
355
|
336
|
|
356
|
|
- public function getRoutes()
|
357
|
|
- {
|
358
|
|
- return '@LogiproPhoenixJupyterBundle/Resources/config/routes.yaml';
|
359
|
|
- }
|
|
337
|
+ public function getRoutes()
|
|
338
|
+ {
|
|
339
|
+ return '@LogiproPhoenixJupyterBundle/Resources/config/routes.yaml';
|
|
340
|
+ }
|
360
|
341
|
|
361
|
|
- public function preFlush($request,$form,$sequenceItem)
|
362
|
|
- {
|
|
342
|
+ public function preFlush($request, $form, $sequenceItem)
|
|
343
|
+ {
|
363
|
344
|
$personId = $form->get('person_id')->getData();
|
364
|
|
-
|
365
|
|
- // met en place le formateur
|
|
345
|
+
|
|
346
|
+ // met en place le formateur
|
366
|
347
|
$trainerRepository = $this->getRepository(Trainer::class);
|
367
|
348
|
$trainer = $trainerRepository->find($personId);
|
368
|
|
- if ($trainer)
|
369
|
|
- {
|
|
349
|
+ if ($trainer) {
|
370
|
350
|
$sequenceItem->setTrainer($trainer);
|
371
|
|
- }
|
372
|
|
- else {
|
|
351
|
+ } else {
|
373
|
352
|
$sequenceItem->removeTrainer();
|
374
|
353
|
}
|
375
|
354
|
|
376
|
|
- // récupére kes informations de l'ancien formateur
|
|
355
|
+ // récupére kes informations de l'ancien formateur
|
377
|
356
|
$oldEntityData = $this->getManager()->getUnitOfWork()->getOriginalEntityData($sequenceItem);
|
378
|
357
|
$oldTrainer = $oldEntityData['trainer'];
|
379
|
358
|
$oldTitle = $oldEntityData['title'];
|
380
|
359
|
|
381
|
|
- // test s'il y a un upload
|
|
360
|
+ // test s'il y a un upload
|
382
|
361
|
$upload = null;
|
383
|
362
|
$uploadedFile = $form['notebook']->getData();
|
384
|
|
- if ($uploadedFile)
|
385
|
|
- {
|
|
363
|
+ if ($uploadedFile) {
|
386
|
364
|
$upload = $this->uploader->upload($uploadedFile);
|
387
|
365
|
}
|
388
|
|
-
|
389
|
|
-
|
|
366
|
+
|
|
367
|
+
|
390
|
368
|
// calcul si le formateur a changé
|
391
|
369
|
$currentTrainer = $sequenceItem->getTrainer();
|
392
|
370
|
$trainerChanged = $oldTrainer != $currentTrainer;
|
|
@@ -398,91 +376,79 @@ class PhoenixServices extends Services
|
398
|
376
|
$mustStopServer = array();
|
399
|
377
|
|
400
|
378
|
// si le titre change ou si le formateur change ou si l'upload est rempli
|
401
|
|
- if ($upload || $trainerChanged || $titleChanged)
|
402
|
|
- {
|
|
379
|
+ if ($upload || $trainerChanged || $titleChanged) {
|
403
|
380
|
// calcul le contenu du notebook
|
404
|
381
|
$content = null;
|
405
|
|
- if ($upload)
|
406
|
|
- {
|
|
382
|
+ if ($upload) {
|
407
|
383
|
$content = $upload;
|
408
|
384
|
}
|
409
|
385
|
// on tente de récupérer le contenu du notebook de l'ancien formateur
|
410
|
|
- elseif ($oldTrainer)
|
411
|
|
- {
|
|
386
|
+ elseif ($oldTrainer) {
|
412
|
387
|
$response = $this->startServer($oldTrainer);
|
413
|
|
- if (!$response['isStarted'])
|
414
|
|
- {
|
|
388
|
+ if (!$response['isStarted']) {
|
415
|
389
|
$mustStopServer[] = $oldTrainer;
|
416
|
390
|
}
|
417
|
391
|
}
|
418
|
392
|
|
419
|
393
|
// si l'item a un formateur
|
420
|
|
- if ($currentTrainer)
|
421
|
|
- {
|
|
394
|
+ if ($currentTrainer) {
|
422
|
395
|
$fromUrl = null;
|
423
|
|
- if ($oldTrainer)
|
424
|
|
- {
|
|
396
|
+ if ($oldTrainer) {
|
425
|
397
|
$fromUrl = $oldEntityData['url'];
|
426
|
398
|
}
|
427
|
|
-
|
|
399
|
+
|
428
|
400
|
// met en place le compte et le contenu du notebook
|
429
|
|
- $url = $this->createTrainerJupyterServer($sequenceItem,$fromUrl,$content,false);
|
|
401
|
+ $url = $this->createTrainerJupyterServer($sequenceItem, $fromUrl, $content, false);
|
430
|
402
|
|
431
|
403
|
// calcul le nouvel url si le formateur a changé et/ou si le titre a changé
|
432
|
404
|
$sequenceItem->setUrl($url);
|
433
|
405
|
}
|
434
|
406
|
// il y avait un formateur et on l'a supprimé, donc le formateur n'a plu le notebook
|
435
|
|
- elseif ($oldTrainer)
|
436
|
|
- {
|
|
407
|
+ elseif ($oldTrainer) {
|
437
|
408
|
$layer = $this->getApiService();
|
438
|
|
- $$oldToken = $this->getToken($oldTrainer);
|
439
|
|
- if ($$oldToken)
|
440
|
|
- {
|
|
409
|
+ $oldToken = $this->getToken($oldTrainer);
|
|
410
|
+ if ($$oldToken) {
|
441
|
411
|
$oldSequenceItem = new JupyterVirtualClassroom();
|
442
|
412
|
$oldSequenceItem->setUrl($oldEntityData['url']);
|
443
|
413
|
$oldSequenceItem->setSequence($sequenceItem->getSequence());
|
444
|
|
- $layer->deleteNotebook($$oldToken,$oldSequenceItem);
|
|
414
|
+ $layer->deleteNotebook($$oldToken, $oldSequenceItem);
|
445
|
415
|
}
|
446
|
416
|
}
|
447
|
417
|
}
|
448
|
|
- foreach ($mustStopServer as $token)
|
449
|
|
- {
|
|
418
|
+ foreach ($mustStopServer as $token) {
|
450
|
419
|
// fixme a dev
|
451
|
420
|
//$layer->stopServer($token);
|
452
|
421
|
}
|
453
|
|
- }
|
|
422
|
+ }
|
454
|
423
|
|
455
|
|
- public function getManifestPath()
|
456
|
|
- {
|
457
|
|
- return 'vendor/logipro/PhoenixJupyterBundle/Resources/public/bundles/logiprophoenixjupyter/manifest.json';
|
458
|
|
- }
|
|
424
|
+ public function getManifestPath()
|
|
425
|
+ {
|
|
426
|
+ return 'vendor/logipro/PhoenixJupyterBundle/Resources/public/bundles/logiprophoenixjupyter/manifest.json';
|
|
427
|
+ }
|
459
|
428
|
|
460
|
429
|
|
461
|
|
- public function startTrainerServer(JupyterVirtualClassroom $classRoom) : string
|
462
|
|
- {
|
|
430
|
+ public function startTrainerServer(JupyterVirtualClassroom $classRoom): string
|
|
431
|
+ {
|
463
|
432
|
// récupère le token du formateur
|
464
|
433
|
$trainer = $classRoom->getTrainer();
|
465
|
434
|
$jupyterToken = null;
|
466
|
|
- if ($trainer)
|
467
|
|
- {
|
|
435
|
+ if ($trainer) {
|
468
|
436
|
$jupyterToken = $this->getToken($trainer);
|
469
|
437
|
}
|
470
|
|
-
|
|
438
|
+
|
471
|
439
|
|
472
|
440
|
// si pas de token, on tente de créé le serveur
|
473
|
441
|
$tokenExist = !is_null($jupyterToken);
|
474
|
|
- if (!$tokenExist)
|
475
|
|
- {
|
|
442
|
+ if (!$tokenExist) {
|
476
|
443
|
$jupyterToken = $this->createTrainerJupyterServer($classRoom);
|
477
|
|
- $manager->flush();
|
478
|
|
- }
|
479
|
|
-
|
480
|
|
- // demarre le serveur du formateur
|
|
444
|
+ $this->getManager()->flush();
|
|
445
|
+ }
|
|
446
|
+
|
|
447
|
+ // demarre le serveur du formateur
|
481
|
448
|
$this->startServer($classRoom->getTrainer());
|
482
|
449
|
|
483
|
|
- // redirige sur jupyter
|
484
|
|
- if ($jupyterToken)
|
485
|
|
- {
|
|
450
|
+ // redirige sur jupyter
|
|
451
|
+ if ($jupyterToken) {
|
486
|
452
|
// calcul l'url d'accès au notebook
|
487
|
453
|
$apiService = $this->getApiService();
|
488
|
454
|
$classroomUrl = $apiService->getFolderUrlByNotebookUrl($classRoom->getUrl());
|
|
@@ -491,24 +457,22 @@ class PhoenixServices extends Services
|
491
|
457
|
$endUrl = $classroomUrl . '?token=' . $jupyterToken->getToken();
|
492
|
458
|
|
493
|
459
|
// ajoute le protocole
|
494
|
|
- $scheme = parse_url ($_SERVER['JUPYTER_API_URL'],PHP_URL_SCHEME);
|
495
|
|
- if (strpos('http',$endUrl) === false)
|
496
|
|
- {
|
|
460
|
+ $scheme = parse_url($_SERVER['JUPYTER_API_URL'], PHP_URL_SCHEME);
|
|
461
|
+ if (strpos('http', $endUrl) === false) {
|
497
|
462
|
$endUrl = $scheme . '://' . $endUrl;
|
498
|
|
- }
|
499
|
|
- return $endUrl;
|
|
463
|
+ }
|
|
464
|
+ return $endUrl;
|
500
|
465
|
}
|
501
|
|
- return "";
|
|
466
|
+ return "";
|
502
|
467
|
}
|
503
|
468
|
|
504
|
|
- private function createStudentServer(Person $person,JupyterVirtualClassroom $sequenceItem) : string
|
|
469
|
+ private function createStudentServer(Person $person, JupyterVirtualClassroom $sequenceItem): string
|
505
|
470
|
{
|
506
|
471
|
$personToken = $this->getToken($person);
|
507
|
472
|
$trainerToken = $this->getToken($sequenceItem->getTrainer());
|
508
|
473
|
|
509
|
474
|
// créé le token apprenant s'il n'en a pas
|
510
|
|
- if (!$personToken)
|
511
|
|
- {
|
|
475
|
+ if (!$personToken) {
|
512
|
476
|
$personToken = new jupyterToken();
|
513
|
477
|
$personToken->setPerson($person);
|
514
|
478
|
}
|
|
@@ -516,39 +480,33 @@ class PhoenixServices extends Services
|
516
|
480
|
// créé le serveur de l'apprenant + met en place son cours
|
517
|
481
|
$layer = $this->getApiService();
|
518
|
482
|
|
519
|
|
- /*if ($sequenceItem->getIsAssesment())
|
520
|
|
- {
|
|
483
|
+ if ($sequenceItem->getIsAssesment()) {
|
521
|
484
|
// cours d'évaluation
|
522
|
|
- $url = $layer->createStudentAssesmentServerIfNone($sequenceItem,$trainerToken,$personToken);
|
523
|
|
- }
|
524
|
|
- else
|
525
|
|
- {*/
|
|
485
|
+ $url = $layer->createStudentAssesmentServerIfNone($sequenceItem, $trainerToken, $personToken);
|
|
486
|
+ } else {
|
526
|
487
|
// cours classique
|
527
|
|
- $url = $layer->createStudentServerIfNoneAndSetContent($sequenceItem,$trainerToken,$personToken,true);
|
528
|
|
- //}
|
|
488
|
+ $url = $layer->createStudentServerIfNoneAndSetContent($sequenceItem, $trainerToken, $personToken, true);
|
|
489
|
+ }
|
529
|
490
|
|
530
|
491
|
// persist le token s'il vient d'être créé
|
531
|
492
|
$manager = $this->getManager();
|
532
|
|
- if (!$personToken->getTokenId())
|
533
|
|
- {
|
|
493
|
+ if (!$personToken->getTokenId()) {
|
534
|
494
|
$manager->persist($personToken);
|
535
|
495
|
}
|
536
|
496
|
|
537
|
497
|
return $url;
|
538
|
|
-
|
539
|
498
|
}
|
540
|
|
-
|
541
|
|
- public function startStudentServer(JupyterVirtualClassroom $sequenceItem,Person $person) : string
|
|
499
|
+
|
|
500
|
+ public function startStudentServer(JupyterVirtualClassroom $sequenceItem, Person $person): string
|
542
|
501
|
{
|
543
|
502
|
// recherche l'inscription dans la classe jupyter
|
544
|
503
|
$jupyterClassroomRegistrationRepository = $this->getRepository(JupyterClassroomRegistration::class);
|
545
|
504
|
|
546
|
505
|
// recherche l'url pour l'apprenant de l'inscription
|
547
|
|
- $jupyterClassroomRegistration = $jupyterClassroomRegistrationRepository->getLastClassroomRegistration($sequenceItem,$person);
|
|
506
|
+ $jupyterClassroomRegistration = $jupyterClassroomRegistrationRepository->getLastClassroomRegistration($sequenceItem, $person);
|
548
|
507
|
$registrationExist = !is_null($jupyterClassroomRegistration);
|
549
|
508
|
|
550
|
|
- if (!$registrationExist)
|
551
|
|
- {
|
|
509
|
+ if (!$registrationExist) {
|
552
|
510
|
// créé une nouvelle ClassroomRegistration pour cet apprenant
|
553
|
511
|
$jupyterClassroomRegistration = new JupyterClassroomRegistration();
|
554
|
512
|
$jupyterClassroomRegistration->setPerson($person);
|
|
@@ -557,12 +515,11 @@ class PhoenixServices extends Services
|
557
|
515
|
// récupère le contenu de la classe du formateur
|
558
|
516
|
$trainer = $sequenceItem->getTrainer();
|
559
|
517
|
$trainerToken = $this->getToken($trainer);
|
560
|
|
- if (!$trainerToken)
|
561
|
|
- {
|
|
518
|
+ if (!$trainerToken) {
|
562
|
519
|
throw new \Exception();
|
563
|
520
|
}
|
564
|
521
|
|
565
|
|
- $url = $this->createStudentServer($person,$sequenceItem);
|
|
522
|
+ $url = $this->createStudentServer($person, $sequenceItem);
|
566
|
523
|
|
567
|
524
|
// met en place l'url de la ClassroomRegistration
|
568
|
525
|
$jupyterClassroomRegistration->setUrl($url);
|
|
@@ -575,28 +532,25 @@ class PhoenixServices extends Services
|
575
|
532
|
|
576
|
533
|
// demarre le serveur de l'apprenant
|
577
|
534
|
$response = $this->startServer($person);
|
578
|
|
-
|
|
535
|
+
|
579
|
536
|
// récupère le token de l'apprenant
|
580
|
537
|
$personToken = $this->getToken($person);
|
581
|
538
|
|
582
|
539
|
// redirige sur jupyter
|
583
|
540
|
$classroomRegistrationUrl = $jupyterClassroomRegistration->getUrl();
|
584
|
541
|
$endUrl = $classroomRegistrationUrl . '?token=' . $personToken->getToken();
|
585
|
|
-
|
|
542
|
+
|
586
|
543
|
// test si le notebook existe encore
|
587
|
|
- if ($registrationExist)
|
588
|
|
- {
|
|
544
|
+ if ($registrationExist) {
|
589
|
545
|
// s'il n'existe pas => on redirige l'utilisateur sur le dossier
|
590
|
546
|
$layer = $this->getApiService();
|
591
|
|
- if (!$layer->notebookExist($personToken,$classroomRegistrationUrl))
|
592
|
|
- {
|
|
547
|
+ if (!$layer->notebookExist($personToken, $classroomRegistrationUrl)) {
|
593
|
548
|
$endUrl = $layer->getFolderUrlByNotebookUrl($classroomRegistrationUrl);
|
594
|
549
|
}
|
595
|
550
|
}
|
596
|
551
|
|
597
|
|
- $scheme = parse_url ($_SERVER['JUPYTER_API_URL'],PHP_URL_SCHEME);
|
598
|
|
- if (strpos('http',$endUrl) === false)
|
599
|
|
- {
|
|
552
|
+ $scheme = parse_url($_SERVER['JUPYTER_API_URL'], PHP_URL_SCHEME);
|
|
553
|
+ if (strpos('http', $endUrl) === false) {
|
600
|
554
|
$endUrl = $scheme . '://' . $endUrl;
|
601
|
555
|
}
|
602
|
556
|
|
|
@@ -611,7 +565,7 @@ class PhoenixServices extends Services
|
611
|
565
|
* @param JupyterVirtualClassroom $sequenceItem
|
612
|
566
|
* @return void
|
613
|
567
|
*/
|
614
|
|
- public function sendStudentNotebookAndGetScore(JupyterVirtualClassroom $sequenceItem,Person $person)
|
|
568
|
+ public function sendStudentNotebookAndGetScore(JupyterVirtualClassroom $sequenceItem, Person $person)
|
615
|
569
|
{
|
616
|
570
|
$personToken = $this->getToken($person);
|
617
|
571
|
|
|
@@ -620,14 +574,13 @@ class PhoenixServices extends Services
|
620
|
574
|
// créé le serveur de l'apprenant + met en place son cours
|
621
|
575
|
$layer = $this->getApiService();
|
622
|
576
|
// met en place le score automatiquement
|
623
|
|
- $data = $layer->sendStudentNotebook($trainerToken,$personToken,$sequenceItem);
|
|
577
|
+ $data = $layer->sendStudentNotebook($trainerToken, $personToken, $sequenceItem);
|
624
|
578
|
|
625
|
579
|
$jupyterClassroomRegistrationRepository = $this->getRepository(JupyterClassroomRegistration::class);
|
626
|
580
|
|
627
|
581
|
// recherche l'url pour l'apprenant de l'inscription
|
628
|
|
- $jupyterClassroomRegistration = $jupyterClassroomRegistrationRepository->getLastClassroomRegistration($sequenceItem,$person);
|
629
|
|
- if ($jupyterClassroomRegistration)
|
630
|
|
- {
|
|
582
|
+ $jupyterClassroomRegistration = $jupyterClassroomRegistrationRepository->getLastClassroomRegistration($sequenceItem, $person);
|
|
583
|
+ if ($jupyterClassroomRegistration) {
|
631
|
584
|
// création de la soumission
|
632
|
585
|
$manager = $this->getManager();
|
633
|
586
|
|
|
@@ -639,7 +592,7 @@ class PhoenixServices extends Services
|
639
|
592
|
}
|
640
|
593
|
|
641
|
594
|
// supprime le notebook
|
642
|
|
- $layer->deleteNotebook($personToken,$sequenceItem);
|
|
595
|
+ $layer->deleteNotebook($personToken, $sequenceItem);
|
643
|
596
|
$jupyterClassroomRegistration->setUrl(null);
|
644
|
597
|
|
645
|
598
|
$manager->flush();
|
|
@@ -647,23 +600,21 @@ class PhoenixServices extends Services
|
647
|
600
|
return $submission->getScoreFormat();
|
648
|
601
|
}
|
649
|
602
|
|
650
|
|
- public function resetNotebook(JupyterVirtualClassroom $sequenceItem,Person $person) : bool
|
|
603
|
+ public function resetNotebook(JupyterVirtualClassroom $sequenceItem, Person $person): bool
|
651
|
604
|
{
|
652
|
605
|
$layer = $this->getApiService();
|
653
|
|
-
|
|
606
|
+
|
654
|
607
|
$personToken = $this->getToken($person);
|
655
|
|
-
|
|
608
|
+
|
656
|
609
|
$trainerToken = $this->getToken($sequenceItem->getTrainer());
|
657
|
610
|
|
658
|
611
|
// recherche l'url pour l'apprenant de l'inscription
|
659
|
612
|
$jupyterClassroomRegistrationRepository = $this->getRepository(JupyterClassroomRegistration::class);
|
660
|
|
- $jupyterClassroomRegistration = $jupyterClassroomRegistrationRepository->getLastClassroomRegistration($sequenceItem,$person);
|
661
|
|
- if (!$jupyterClassroomRegistration)
|
662
|
|
- {
|
|
613
|
+ $jupyterClassroomRegistration = $jupyterClassroomRegistrationRepository->getLastClassroomRegistration($sequenceItem, $person);
|
|
614
|
+ if (!$jupyterClassroomRegistration) {
|
663
|
615
|
return false;
|
664
|
616
|
}
|
665
|
617
|
|
666
|
|
- return $layer->resetNotebook($trainerToken,$personToken,$sequenceItem->getUrl(),$jupyterClassroomRegistration->getUrl());
|
|
618
|
+ return $layer->resetNotebook($trainerToken, $personToken, $sequenceItem->getUrl(), $jupyterClassroomRegistration->getUrl());
|
667
|
619
|
}
|
668
|
|
-
|
669
|
620
|
}
|