Skip to content

Commit 3da4550

Browse files
authored
Merge pull request #8 from devianl2/revert-7-main
Revert "Improve SCORM disk storage handler"
2 parents 9a3d5c6 + 359e258 commit 3da4550

File tree

8 files changed

+166
-296
lines changed

8 files changed

+166
-296
lines changed

README.md

-34
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,8 @@ php artisan vendor:publish --provider="Peopleaps\Scorm\ScormServiceProvider"
3232
```
3333

3434
## Step 3:
35-
Run config cache for update cached configuration
36-
```sh
37-
php artisan config:cache
38-
```
39-
40-
## Step 4:
4135
Migrate file to database
4236
```sh
4337
php artisan migrate
4438
```
4539

46-
## Step 5 (Optional):
47-
update SCORM config under config/scorm
48-
- update scorm table names.
49-
- update SCORM disk and configure disk @see config/filesystems.php
50-
```
51-
'disk' => 'scorm-local',
52-
'disk' => 'scorm-s3',
53-
54-
// @see config/filesystems.php
55-
'disks' => [
56-
.....
57-
'scorm-local' => [
58-
'driver' => 'local',
59-
'root' => env('SCORM_ROOT_DIR'), // set root dir
60-
'visibility' => 'public',
61-
],
62-
63-
's3-scorm' => [
64-
'driver' => 's3',
65-
'root' => env('SCORM_ROOT_DIR'), // set root dir
66-
'key' => env('AWS_ACCESS_KEY_ID'),
67-
'secret' => env('AWS_SECRET_ACCESS_KEY'),
68-
'region' => env('AWS_DEFAULT_REGION'),
69-
'bucket' => env('AWS_SCORM_BUCKET'),
70-
],
71-
.....
72-
]
73-
```

config/scorm.php

+2-16
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,11 @@
33
return [
44

55
'table_names' => [
6-
'user_table' => 'users', // user table name on main LMS app.
6+
'user_table' => 'users',
77
'scorm_table' => 'scorm',
88
'scorm_sco_table' => 'scorm_sco',
99
'scorm_sco_tracking_table' => 'scorm_sco_tracking',
1010
],
11-
/**
12-
* Scorm directory. You may create a custom path in file system
13-
* Define Scorm disk under @see config/filesystems.php
14-
* 'disk' => 'local',
15-
* 'disk' => 's3-scorm',
16-
* ex.
17-
* 's3-scorm' => [
18-
* 'driver' => 's3',
19-
* 'root' => env('SCORM_ROOT_DIR'), // define root dir
20-
* 'key' => env('AWS_ACCESS_KEY_ID'),
21-
* 'secret' => env('AWS_SECRET_ACCESS_KEY'),
22-
* 'region' => env('AWS_DEFAULT_REGION'),
23-
* 'bucket' => env('AWS_SCORM_BUCKET'),
24-
* ],
25-
*/
11+
// Scorm directory. You may create a custom path in file system
2612
'disk' => 'local',
2713
];

database/migrations/create_scorm_tables.php.stub

+13-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,19 @@ class CreateScormTables extends Migration
9797
*/
9898
public function down()
9999
{
100-
$tableNames = config('scorm.table_names');
100+
$tableNames = config('scorm_sco_tracking_table');
101+
102+
if (empty($tableNames)) {
103+
throw new \Exception('Error: Table not found.');
104+
}
105+
106+
$tableNames = config('scorm_sco_table');
107+
108+
if (empty($tableNames)) {
109+
throw new \Exception('Error: Table not found.');
110+
}
111+
112+
$tableNames = config('scorm_table');
101113

102114
if (empty($tableNames)) {
103115
throw new \Exception('Error: Table not found.');

src/Entity/Scorm.php

+10-25
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33

44
namespace Peopleaps\Scorm\Entity;
55

6+
7+
use Doctrine\Common\Collections\ArrayCollection;
8+
69
class Scorm
710
{
811
const SCORM_12 = 'scorm_12';
912
const SCORM_2004 = 'scorm_2004';
1013

1114
public $uuid;
1215
public $id;
13-
public $title;
1416
public $version;
15-
public $entryUrl;
17+
public $hashName;
1618
public $ratio = 56.25;
1719
public $scos;
1820
public $scoSerializer;
@@ -68,33 +70,17 @@ public function setVersion($version)
6870
/**
6971
* @return string
7072
*/
71-
public function getTitle()
72-
{
73-
return $this->title;
74-
}
75-
76-
/**
77-
* @param string $title
78-
*/
79-
public function setTitle($title)
80-
{
81-
$this->title = $title;
82-
}
83-
84-
/**
85-
* @return string
86-
*/
87-
public function getEntryUrl()
73+
public function getHashName()
8874
{
89-
return $this->entryUrl;
75+
return $this->hashName;
9076
}
9177

9278
/**
93-
* @param string $title
79+
* @param string $hashName
9480
*/
95-
public function setEntryUrl($entryUrl)
81+
public function setHashName($hashName)
9682
{
97-
$this->entryUrl = $entryUrl;
83+
$this->hashName = $hashName;
9884
}
9985

10086
/**
@@ -145,8 +131,7 @@ public function serialize(Scorm $scorm)
145131
return [
146132
'id' => $scorm->getUuid(),
147133
'version' => $scorm->getVersion(),
148-
'title' => $scorm->getTitle(),
149-
'entryUrl' => $scorm->getEntryUrl(),
134+
'hashName' => $scorm->getHashName(),
150135
'ratio' => $scorm->getRatio(),
151136
'scos' => $this->serializeScos($scorm),
152137
];

src/Library/ScormLib.php

+11-19
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use DOMDocument;
88
use Peopleaps\Scorm\Entity\Sco;
99
use Peopleaps\Scorm\Exception\InvalidScormArchiveException;
10-
use Illuminate\Support\Str;
10+
use Ramsey\Uuid\Uuid;
1111

1212
class ScormLib
1313
{
@@ -28,20 +28,16 @@ public function parseOrganizationsNode(DOMDocument $dom)
2828
$organizations = $organizationsList->item(0);
2929
$organization = $organizations->firstChild;
3030

31-
if (
32-
!is_null($organizations->attributes)
33-
&& !is_null($organizations->attributes->getNamedItem('default'))
34-
) {
31+
if (!is_null($organizations->attributes)
32+
&& !is_null($organizations->attributes->getNamedItem('default'))) {
3533
$defaultOrganization = $organizations->attributes->getNamedItem('default')->nodeValue;
3634
} else {
3735
$defaultOrganization = null;
3836
}
3937
// No default organization is defined
4038
if (is_null($defaultOrganization)) {
41-
while (
42-
!is_null($organization)
43-
&& 'organization' !== $organization->nodeName
44-
) {
39+
while (!is_null($organization)
40+
&& 'organization' !== $organization->nodeName) {
4541
$organization = $organization->nextSibling;
4642
}
4743

@@ -52,12 +48,10 @@ public function parseOrganizationsNode(DOMDocument $dom)
5248
// A default organization is defined
5349
// Look for it
5450
else {
55-
while (
56-
!is_null($organization)
51+
while (!is_null($organization)
5752
&& ('organization' !== $organization->nodeName
5853
|| is_null($organization->attributes->getNamedItem('identifier'))
59-
|| $organization->attributes->getNamedItem('identifier')->nodeValue !== $defaultOrganization)
60-
) {
54+
|| $organization->attributes->getNamedItem('identifier')->nodeValue !== $defaultOrganization)) {
6155
$organization = $organization->nextSibling;
6256
}
6357

@@ -88,7 +82,7 @@ private function parseItemNodes(\DOMNode $source, \DOMNodeList $resources, Sco $
8882
if ('item' === $item->nodeName) {
8983
$sco = new Sco();
9084
$scos[] = $sco;
91-
$sco->setUuid(Str::uuid());
85+
$sco->setUuid(Uuid::uuid4());
9286
$sco->setScoParent($parentSco);
9387
$this->findAttrParams($sco, $item, $resources);
9488
$this->findNodeParams($sco, $item->firstChild);
@@ -125,7 +119,7 @@ private function parseResourceNodes(\DOMNodeList $resources)
125119
throw new InvalidScormArchiveException('sco_resource_without_href_message');
126120
}
127121
$sco = new Sco();
128-
$sco->setUuid(Str::uuid());
122+
$sco->setUuid(Uuid::uuid4());
129123
$sco->setBlock(false);
130124
$sco->setVisible(true);
131125
$sco->setIdentifier($identifier->nodeValue);
@@ -201,12 +195,10 @@ private function findNodeParams(Sco $sco, \DOMNode $item)
201195
case 'adlcp:timeLimitAction':
202196
$action = strtolower($item->nodeValue);
203197

204-
if (
205-
'exit,message' === $action
198+
if ('exit,message' === $action
206199
|| 'exit,no message' === $action
207200
|| 'continue,message' === $action
208-
|| 'continue,no message' === $action
209-
) {
201+
|| 'continue,no message' === $action) {
210202
$sco->setTimeLimitAction($action);
211203
}
212204
break;

src/Manager/ScormDisk.php

-74
This file was deleted.

0 commit comments

Comments
 (0)