summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKhaled Lela <eng.khaled.lela@gmail.com>2022-02-10 18:59:23 +0200
committerKhaled Lela <eng.khaled.lela@gmail.com>2022-02-10 18:59:23 +0200
commite18d5c803a5bab898515fd87e1ca5de517b8d88f (patch)
tree81a6bd3e99b3933daf2d737dfb1347ad4f37c67c
parent910f5cee7439466d797d9202c955b6c6540d45f1 (diff)
fix storing Scorm sco children
-rw-r--r--src/Manager/ScormManager.php60
-rw-r--r--src/Model/ScormScoModel.php11
2 files changed, 45 insertions, 26 deletions
diff --git a/src/Manager/ScormManager.php b/src/Manager/ScormManager.php
index 21aaf73..56c723c 100644
--- a/src/Manager/ScormManager.php
+++ b/src/Manager/ScormManager.php
@@ -16,6 +16,7 @@ use Peopleaps\Scorm\Model\ScormModel;
use Peopleaps\Scorm\Model\ScormScoModel;
use Peopleaps\Scorm\Model\ScormScoTrackingModel;
use Illuminate\Support\Str;
+use Peopleaps\Scorm\Entity\Sco;
use ZipArchive;
class ScormManager
@@ -76,38 +77,49 @@ class ScormManager
$scorm->save();
if (!empty($scormData['scos']) && is_array($scormData['scos'])) {
+ /** @var Sco $scoData */
foreach ($scormData['scos'] as $scoData) {
-
- $scoParent = null;
- if (!empty($scoData->scoParent)) {
- $scoParent = ScormScoModel::where('uuid', $scoData->scoParent->uuid)->first();
+ $sco = $this->saveScormScos($scorm->id, $scoData);
+ if ($scoData->scoChildren) {
+ foreach ($scoData->scoChildren as $scoChild) {
+ $this->saveScormScos($scorm->id, $scoChild, $sco->id);
+ }
}
-
- // Check if scom package already exists update or create when not exists.
- $sco = new ScormScoModel();
- $sco->scorm_id = $scorm->id;
- $sco->uuid = $scoData->uuid;
- $sco->sco_parent_id = $scoParent ? $scoParent->id : null;
- $sco->entry_url = $scoData->entryUrl;
- $sco->identifier = $scoData->identifier;
- $sco->title = $scoData->title;
- $sco->visible = $scoData->visible;
- $sco->sco_parameters = $scoData->parameters;
- $sco->launch_data = $scoData->launchData;
- $sco->max_time_allowed = $scoData->maxTimeAllowed;
- $sco->time_limit_action = $scoData->timeLimitAction;
- $sco->block = $scoData->block;
- $sco->score_int = $scoData->scoreToPassInt;
- $sco->score_decimal = $scoData->scoreToPassDecimal;
- $sco->completion_threshold = $scoData->completionThreshold;
- $sco->prerequisites = $scoData->prerequisites;
- $sco->save();
}
}
return $scormData;
}
+ /**
+ * Save Scorm sco and it's nested children
+ * @param int $scorm_id scorm id.
+ * @param Sco $scoData Sco data to be store.
+ * @param int $sco_parent_id sco parent id for children
+ */
+ private function saveScormScos($scorm_id, $scoData, $sco_parent_id = null)
+ {
+ $sco = new ScormScoModel();
+ $sco->scorm_id = $scorm_id;
+ $sco->uuid = $scoData->uuid;
+ $sco->sco_parent_id = $sco_parent_id;
+ $sco->entry_url = $scoData->entryUrl;
+ $sco->identifier = $scoData->identifier;
+ $sco->title = $scoData->title;
+ $sco->visible = $scoData->visible;
+ $sco->sco_parameters = $scoData->parameters;
+ $sco->launch_data = $scoData->launchData;
+ $sco->max_time_allowed = $scoData->maxTimeAllowed;
+ $sco->time_limit_action = $scoData->timeLimitAction;
+ $sco->block = $scoData->block;
+ $sco->score_int = $scoData->scoreToPassInt;
+ $sco->score_decimal = $scoData->scoreToPassDecimal;
+ $sco->completion_threshold = $scoData->completionThreshold;
+ $sco->prerequisites = $scoData->prerequisites;
+ $sco->save();
+ return $sco;
+ }
+
private function parseScormArchive(UploadedFile $file)
{
$data = [];
diff --git a/src/Model/ScormScoModel.php b/src/Model/ScormScoModel.php
index de50741..d606d32 100644
--- a/src/Model/ScormScoModel.php
+++ b/src/Model/ScormScoModel.php
@@ -13,11 +13,18 @@ class ScormScoModel extends Model
return config('scorm.table_names.scorm_sco_table', parent::getTable());
}
- public function scorm() {
+ public function scorm()
+ {
return $this->belongsTo(ScormModel::class, 'scorm_id', 'id');
}
- public function scoTrackings() {
+ public function scoTrackings()
+ {
return $this->hasMany(ScormScoTrackingModel::class, 'sco_id', 'id');
}
+
+ public function children()
+ {
+ return $this->hasMany(ScormScoModel::class, 'sco_parent_id', 'id');
+ }
}