From 89e09a4a45bffa8d89ebd7b1ca0a77ba4121dd01 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 28 Jan 2022 16:39:50 +0100 Subject: [PATCH] wip #5045 @0.5 --- .idea/workspace.xml | 18 +++- composer.json | 3 +- src/Manifest.php | 228 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 244 insertions(+), 5 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4fc8576..b5351b4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,8 +1,10 @@ - + + + @@ -130,6 +139,7 @@ \ No newline at end of file diff --git a/composer.json b/composer.json index 11b7435..282481e 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ } }, "require": { - "php": ">=7.3" + "php": ">=7.3", + "ext-mbstring": "*" } } \ No newline at end of file diff --git a/src/Manifest.php b/src/Manifest.php index a0fe5f0..17fd2ab 100644 --- a/src/Manifest.php +++ b/src/Manifest.php @@ -1,7 +1,235 @@ setVersion($version); + $this->setTitle($title); + if (null !== $organization) { + $this->setOrganization($organization); + } + if (null !== $reference) { + $this->setReference($reference); + } + $this->setStart($start); + } + + public function __toString() + { + if ($this->getVersion() === self::SCORM_1_2) { + return $this->_render12(); + } else { + return $this->_render2004(); + } + + } + + public function getManifestID() + { + $hash = '!!' . $this->getTitle() . '//' . $this->getOrganization() . '///' . $this->getReference() . '|||' . $this->getVersion() . '::'; + return 'MANIFEST-' . mb_strtoupper(sha1($hash)); + } + + protected function _render2004() + { + return ' + + + ADL SCORM + 2004 4th Edition + + + + ' . $this->_escape($this->getTitle()) . ' + + ' . $this->_escape($this->getTitle()) . ' + + + continue + previous + exit + exitAll + suspendAll + abandonAll + + + + + + + + + + +'; + } + + /** + * @return string + */ + protected function _render12() + { + $res = ' + + + ADL SCORM + 1.2 + + + + ' . $this->_escape($this->getTitle()) . ' + + ' . $this->_escape($this->getTitle()) . ' + + + + + + + + +'; + + return $res; + } + + protected function _escape($string, $flags = ENT_XML1) + { + return htmlspecialchars($string, $flags); + } + + protected function _escapeAttr($string) + { + return $this->_escape($string, ENT_XML1 | ENT_COMPAT); + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @return string + */ + public function getVersion() + { + return $this->version; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @param string $version + */ + public function setVersion($version) + { + $this->version = $version; + } + + /** + * @param string $organization + */ + public function setOrganization($organization) + { + $this->organization = $organization; + } + + /** + * @param string $reference + */ + public function setReference($reference) + { + $this->reference = $reference; + } + + /** + * @return string + */ + public function getOrganization() + { + return $this->organization; + } + + /** + * @return string + */ + public function getReference() + { + if (null === $this->reference) { + $this->reference = 'SCORM_SCO_' . sha1(uniqid()); + } + return $this->reference; + } + + /** + * @return string + */ + public function getStart() + { + return $this->start; + } + /** + * @param string $start + */ + public function setStart($start) + { + $this->start = $start; + } } \ No newline at end of file -- 2.39.5