Browse Source

Ajout des clefs clientes sur les objets moteur

Mael ETIENNE 3 years ago
parent
commit
d68b4da870

+ 31
- 2
Entity/Course.php View File

@@ -57,6 +57,12 @@ class Course
57 57
      */
58 58
     protected $versionRule = self::VERSIONING_RULE_DEFAULT;
59 59
 
60
+     /**
61
+     *
62
+     * @var string
63
+     */
64
+    protected $courseKey;
65
+
60 66
     /**
61 67
      *
62 68
      * @var ArrayCollection
@@ -72,9 +78,8 @@ class Course
72 78
     /**
73 79
      * Constructeur de track.
74 80
      */
75
-    public function __construct(int $courseId)
81
+    public function __construct()
76 82
     {
77
-        $this->courseId = $courseId;
78 83
         $this->registrations = new ArrayCollection();
79 84
     }
80 85
 
@@ -216,6 +221,30 @@ class Course
216 221
         return $this;
217 222
     }
218 223
 
224
+    /**
225
+     * Get the value of courseKey
226
+     *
227
+     * @return string
228
+     */
229
+    public function getCourseKey()
230
+    {
231
+        return $this->courseKey;
232
+    }
233
+
234
+    /**
235
+     * Set the value of courseKey
236
+     *
237
+     * @param string $courseKey
238
+     *
239
+     * @return self
240
+     */
241
+    public function setCourseKey(string $courseKey)
242
+    {
243
+        $this->courseKey = $courseKey;
244
+
245
+        return $this;
246
+    }
247
+
219 248
     /**
220 249
      * Get the value of registrations
221 250
      *

+ 30
- 0
Entity/Learner.php View File

@@ -37,6 +37,12 @@ class Learner
37 37
      * @var string
38 38
      */
39 39
     protected $givenName;
40
+
41
+    /**
42
+     *
43
+     * @var string
44
+     */
45
+    protected $learnerKey;
40 46
     
41 47
     /**
42 48
      *
@@ -167,6 +173,30 @@ class Learner
167 173
         return $this;
168 174
     }
169 175
 
176
+    /**
177
+     * Get the value of learnerKey
178
+     *
179
+     * @return string
180
+     */
181
+    public function getLearnerKey()
182
+    {
183
+        return $this->learnerKey;
184
+    }
185
+
186
+    /**
187
+     * Set the value of learnerKey
188
+     *
189
+     * @param string $learnerKey
190
+     *
191
+     * @return self
192
+     */
193
+    public function setLearnerKey(string $learnerKey)
194
+    {
195
+        $this->learnerKey = $learnerKey;
196
+
197
+        return $this;
198
+    }
199
+
170 200
     /**
171 201
      * Get the value of registrations
172 202
      *

+ 30
- 0
Entity/Registration.php View File

@@ -30,6 +30,12 @@ class Registration
30 30
      */
31 31
     protected $updateDate;
32 32
 
33
+     /**
34
+     *
35
+     * @var string
36
+     */
37
+    protected $registrationKey;
38
+
33 39
     /**
34 40
      *
35 41
      * @var Course
@@ -122,6 +128,30 @@ class Registration
122 128
         return $this->updateDate;
123 129
     }
124 130
 
131
+    /**
132
+     * Get the value of registrationKey
133
+     *
134
+     * @return string
135
+     */
136
+    public function getRegistrationKey()
137
+    {
138
+        return $this->registrationKey;
139
+    }
140
+
141
+    /**
142
+     * Set the value of registrationKey
143
+     *
144
+     * @param string $registrationKey
145
+     *
146
+     * @return self
147
+     */
148
+    public function setRegistrationKey(string $registrationKey)
149
+    {
150
+        $this->registrationKey = $registrationKey;
151
+
152
+        return $this;
153
+    }
154
+
125 155
     /**
126 156
      * Get the value of course
127 157
      *

+ 1
- 1
Entity/RegistrationAttempt.php View File

@@ -3,7 +3,7 @@ namespace Logipro\Bundle\SCORMBundle\Entity;
3 3
 
4 4
 use Logipro\Bundle\SCORMBundle\Entity\Registration;
5 5
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Track;
6
-
6
+use Doctrine\Common\Collections\ArrayCollection;
7 7
 
8 8
 /**
9 9
  * Représente une tentative pour une inscription donnée dans le moteur SCORM.

+ 4
- 1
Resources/config/doctrine/Course.orm.xml View File

@@ -7,13 +7,16 @@
7 7
 	<entity name="Logipro\Bundle\SCORMBundle\Entity\Course" 
8 8
 		table="sen_core_course">
9 9
 		
10
-		<id name="courseId" column="course_id" type="integer" />
10
+		<id name="courseId" column="course_id" type="integer">
11
+			<generator strategy="AUTO" />
12
+		</id>
11 13
 		
12 14
 		<field name="creationDate" column="creation_date" type="datetimetz" />
13 15
         <field name="updateDate" column="updateDate" type="datetimetz" />
14 16
 		<field name="type" column="type" type="string" length="50" />
15 17
 		<field name="maxVersion" column="max_version" type="integer" />
16 18
 		<field name="versionRule" column="version_rule" type="string" length="50" />
19
+		<field name="courseKey" column="course_key" type="string" length="255" />
17 20
 				 
18 21
         <one-to-many field="registrations" target-entity="Logipro\Bundle\SCORMBundle\Entity\Registration" mapped-by="course">
19 22
 			<cascade>

+ 4
- 1
Resources/config/doctrine/Learner.orm.xml View File

@@ -7,11 +7,14 @@
7 7
 	<entity name="Logipro\Bundle\SCORMBundle\Entity\Learner" 
8 8
 		table="sen_core_learner">
9 9
 		
10
-		<id name="learnerId" column="learner_id" type="integer" />
10
+		<id name="learnerId" column="learner_id" type="integer">
11
+			<generator strategy="AUTO" />
12
+		</id>
11 13
 		
12 14
 		<field name="creationDate" column="creation_date" type="datetimetz" />
13 15
 		<field name="familyName" column="family_name" type="string" length="50" />
14 16
 		<field name="givenName" column="given_name" type="string" length="50" />
17
+		<field name="learnerKey" column="learner_key" type="string" length="255" />
15 18
 				
16 19
 		<one-to-many field="registrations" target-entity="Logipro\Bundle\SCORMBundle\Entity\Registration" mapped-by="learner">
17 20
 			<cascade>

+ 5
- 2
Resources/config/doctrine/Registration.orm.xml View File

@@ -7,10 +7,13 @@
7 7
 	<entity name="Logipro\Bundle\SCORMBundle\Entity\Registration" 
8 8
 		table="sen_core_registration">
9 9
 		
10
-		<id name="registrationId" column="registration_id" type="integer" />
10
+		<id name="registrationId" column="registration_id" type="integer">
11
+			<generator strategy="AUTO" />
12
+		</id>
11 13
 		
12 14
 		<field name="creationDate" column="creation_date" type="datetimetz" />
13
-        <field name="updateDate" column="updateDate" type="datetimetz" />				
15
+        <field name="updateDate" column="updateDate" type="datetimetz" />
16
+		<field name="registrationKey" column="registration_key" type="string" length="255" />	
14 17
 		 
15 18
     	<many-to-one field="course" target-entity="Logipro\Bundle\SCORMBundle\Entity\Course" inversed-by="registrations">
16 19
 			<join-column name="course_fk" referenced-column-name="course_id" />

+ 2
- 1
Resources/config/services.xml View File

@@ -4,6 +4,7 @@
4 4
     xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5 5
 
6 6
     <services>
7
-        <service id="scorm.services.engine" class="Logipro\Bundle\SCORMBundle\Services\ScormEngine" public="true" />
7
+        <service id="Logipro\Bundle\SCORMBundle\Services\ScormEngine" class="Logipro\Bundle\SCORMBundle\Services\ScormEngine" public="true"/>
8
+        <service id="scorm.services.engine" alias="Logipro\Bundle\SCORMBundle\Services\ScormEngine"/>
8 9
     </services>
9 10
 </container>

+ 121
- 29
Services/ScormEngine.php View File

@@ -1,16 +1,19 @@
1 1
 <?php
2 2
 namespace Logipro\Bundle\SCORMBundle\Services;
3 3
 
4
-use Doctrine\Common\Persistence\ManagerRegistry;
4
+use Logipro\Bundle\SCORMBundle\Entity\Course;
5
+
5 6
 
6
-use Logipro\Bundle\SCORMBundle\Entity\ScormEngine\ZipFile;
7 7
 use Logipro\Bundle\SCORMBundle\Entity\Learner;
8
-use Logipro\Bundle\SCORMBundle\Entity\Course;
8
+use Doctrine\Common\Persistence\ManagerRegistry;
9
+use Doctrine\ORM\EntityManagerInterface;
9 10
 use Logipro\Bundle\SCORMBundle\Entity\Registration;
10
-use Logipro\Bundle\SCORMBundle\Package\Common\PackageTypeDetector;
11
+use Logipro\Bundle\SCORMBundle\Entity\MapCourseZipfile;
12
+use Logipro\Bundle\SCORMBundle\Entity\RegistrationAttempt;
13
+use Logipro\Bundle\SCORMBundle\Entity\ZipFile;
11 14
 use Symfony\Component\DependencyInjection\ContainerInterface;
12 15
 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
13
-use Logipro\Bundle\SCORMBundle\Entity\RegistrationAttempt;
16
+use Logipro\Bundle\SCORMBundle\Package\Common\PackageTypeDetector;
14 17
 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15 18
 
16 19
 /**
@@ -22,12 +25,6 @@ class ScormEngine implements ContainerAwareInterface
22 25
 
23 26
     public function __construct()
24 27
     {
25
-        // rien à faire
26
-    }
27
-
28
-    public static function myTest() : string
29
-    {
30
-        return "coucou";
31 28
     }
32 29
 
33 30
     // ACTIVITÉ
@@ -37,7 +34,7 @@ class ScormEngine implements ContainerAwareInterface
37 34
      *
38 35
      * @return int
39 36
      */
40
-  /*  public function createCourse(string $zipPath, string $versioningRule = Course::VERSIONING_RULE_DEFAULT)
37
+    public function createCourse(string $zipPath, string $versioningRule = Course::VERSIONING_RULE_DEFAULT)
41 38
     {
42 39
         $em = $this->getDoctrine()->getManager();
43 40
 
@@ -47,7 +44,7 @@ class ScormEngine implements ContainerAwareInterface
47 44
             'error' => '',
48 45
             'parserErrors' => array(),
49 46
             'course' => array(
50
-                'courseId' => 0,
47
+                'courseKey' => '',
51 48
                 'maxVersion' => 0,
52 49
                 'versioningRule' => $versioningRule
53 50
             ),
@@ -82,14 +79,14 @@ class ScormEngine implements ContainerAwareInterface
82 79
         $repository = $em->getRepository(ZipFile::class);
83 80
         $zipFile = $repository->findOneBy(['zipFileprint' => $hash]);
84 81
         $response['metadata']['isAlreadyExisting'] = true;
85
-        
82
+
86 83
         // si le fichier n'existe pas déjà on le crée et on le stock coté moteur
87 84
         if (empty($zipFile)) {
88 85
             $response['metadata']['isAlreadyExisting'] = false;
89 86
 
90 87
             //upload du fichier coté moteur
91 88
             $uploadDate = new \DateTime('NOW');
92
-            $uploadPath = $this->container->getParameter('moteur-scorm.upload_tmp_directory');
89
+            $uploadPath = $this->container->getParameter('kernel.root_dir');
93 90
             $fileName = pathinfo($zipPath)['filename'];
94 91
             $filePath = $uploadPath . $fileName;
95 92
             if (copy($zipPath, $filePath) === false) {
@@ -141,7 +138,68 @@ class ScormEngine implements ContainerAwareInterface
141 138
         $response['isSuccessfullyCreated'] = true;
142 139
         return $response;
143 140
     }
144
-*/
141
+
142
+     /**
143
+     * Crée une activité à partir d'un package
144
+     *
145
+     * @return int
146
+     */
147
+    public function createMockCourse(string $courseKey, string $zipPath, string $versioningRule = Course::VERSIONING_RULE_DEFAULT)
148
+    {
149
+        $em = $this->getDoctrine()->getManager();
150
+        
151
+        // Récupération de la signature du zip
152
+        $hash = md5($zipPath);
153
+
154
+        // Test de l'existence de la signature
155
+        $repository = $em->getRepository(ZipFile::class);
156
+        $zipFile = $repository->findOneBy(['zipFileprint' => $hash]);
157
+        $response['metadata']['isAlreadyExisting'] = true;
158
+
159
+        // si le fichier n'existe pas déjà on le crée et on le stock coté moteur
160
+        if (empty($zipFile)) {
161
+            $response['metadata']['isAlreadyExisting'] = false;
162
+
163
+            //upload du fichier coté moteur
164
+            $uploadDate = new \DateTime('NOW');
165
+            $fileName = pathinfo($zipPath)['filename'];
166
+            $endUploadDate = new \DateTime('NOW');
167
+
168
+            // Création d'un objet permettant de traiter le fichier zip
169
+            $zipFile = new ZipFile();
170
+            $zipFile->setZipFileName($fileName);
171
+            $zipFile->setZipFileprint($hash);
172
+            $zipFile->setUploadDate($uploadDate);
173
+            $zipFile->setEndUploadDate($endUploadDate);
174
+            $zipFile->setFilePath('filePath');
175
+            $zipFile->setImportStatus(ZipFile::IMPORT_STATUS_PROCESSING);
176
+
177
+            $em->persist($zipFile);
178
+        }
179
+
180
+    // COURS
181
+        // Création du cours
182
+        $course = new Course();
183
+        $course->setType(Course::SCORM_2004);
184
+        $course->setVersionRule($versioningRule);
185
+        $course->setCourseKey($courseKey);
186
+        $em->persist($course);
187
+
188
+        // Métadonées du cours
189
+        $response['course']['courseId'] = $courseKey;
190
+        $response['course']['maxVersion'] = $course->getMaxVersion();
191
+
192
+    // Mapping Zip/Cours
193
+
194
+        $mapping = new MapCourseZipfile();
195
+        $mapping->setCourse($course);
196
+        $mapping->setZipFile($zipFile);
197
+        $mapping->setVersion($response['course']['maxVersion']);
198
+        $em->persist($mapping);
199
+
200
+        $em->flush();
201
+    }
202
+
145 203
     /**
146 204
      * Remplace le package d'une activité
147 205
      */
@@ -244,9 +302,10 @@ class ScormEngine implements ContainerAwareInterface
244 302
     public function getCourses() : array
245 303
     {
246 304
         $em = $this->getDoctrine()->getManager();
247
-        $courses = $em->getRepository(Course::class)->findAll();
305
+        $repository = $em->getRepository(Course::class);
306
+        $courses = $repository->findAll();
307
+        
248 308
         return $courses;
249
-
250 309
     }
251 310
 
252 311
     // LEARNER
@@ -254,22 +313,28 @@ class ScormEngine implements ContainerAwareInterface
254 313
     /**
255 314
      * Création d'un apprenant
256 315
      *
316
+     * @param string $learnerKey
257 317
      * @param string $familyName
258 318
      * @param string $givenName
259 319
      * @return int
260 320
      */
261
-    public function createLearner(string $familyName, string $givenName)
321
+    public function createLearner(string $learnerKey, string $familyName, string $givenName)
262 322
     {
263
-        $em = $this->getDoctrine()->getManager();
323
+        if (!empty($learnerKey)) {
324
+            $em = $this->getDoctrine()->getManager();
264 325
 
265
-        $learner = new Learner();
266
-        $learner->setFamilyName($familyName);
267
-        $learner->setGivenName($givenName);
326
+            $learner = new Learner();
327
+            $learner->setLearnerKey($learnerKey);
328
+            $learner->setFamilyName($familyName);
329
+            $learner->setGivenName($givenName);
268 330
 
269
-        $em->persist($learner);
270
-        $em->flush();
331
+            $em->persist($learner);
332
+            $em->flush();
271 333
 
272
-        return $learner->getLearnerId();
334
+            return $learner->getLearnerId();
335
+        }
336
+        
337
+        return null;
273 338
     }
274 339
 
275 340
     /**
@@ -313,6 +378,15 @@ class ScormEngine implements ContainerAwareInterface
313 378
         return $learner;
314 379
     }
315 380
 
381
+    public function getLearners()
382
+    {
383
+        $em = $this->getDoctrine()->getManager();
384
+        $repository = $em->getRepository(Learner::class);
385
+        $learners = $repository->findAll();
386
+
387
+        return $learners;
388
+    }
389
+
316 390
     /**
317 391
      * supprime un apprenant
318 392
      *
@@ -339,26 +413,35 @@ class ScormEngine implements ContainerAwareInterface
339 413
     /**
340 414
      * création d'une inscription
341 415
      *
416
+     * @param string $registrationKey
342 417
      * @param int $courseId
343 418
      * @param int $learnerId
344 419
      * @return int
345 420
      */
346
-    public function createRegistration(int $courseId, int $learnerId)
421
+    public function createRegistration(string $registrationKey, int $courseId, int $learnerId)
347 422
     {
348 423
         $em = $this->getDoctrine()->getManager();
349 424
 
350 425
         $course = $this->requireActvity($courseId);
351 426
         $learner = $this->requireLearner($learnerId);
352 427
 
353
-        if ($course && $learner) {
428
+        if (!empty($registrationKey) && $course && $learner) {
354 429
             $registration = new Registration();
430
+            $registration->setRegistrationKey($registrationKey);
355 431
             $registration->setCourse($course);
356 432
             $registration->setLearner($learner);
357 433
 
358 434
             $em->persist($registration);
435
+
436
+            // Création du RegistrationAttempt
437
+            $attempt = new RegistrationAttempt();
438
+            $attempt->setCourseVersion($course->getMaxVersion());
439
+            $attempt->setRegistration($registration);
440
+
441
+            $em->persist($attempt);
359 442
             $em->flush();
360 443
 
361
-            return $registration->getRegistrationId();
444
+            return $registration->getRegistrationKey();
362 445
         }
363 446
         
364 447
         return null;
@@ -396,6 +479,15 @@ class ScormEngine implements ContainerAwareInterface
396 479
         return false;
397 480
     }
398 481
 
482
+    public function getRegistrations()
483
+    {
484
+        $em = $this->getDoctrine()->getManager();
485
+        $repository = $em->getRepository(Registration::class);
486
+        $registrations = $repository->findAll();
487
+
488
+        return $registrations;
489
+    }
490
+
399 491
     // ATTEMPT
400 492
 
401 493
     /**

Loading…
Cancel
Save