1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\PluginBundle\XApi\Parser; |
8
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\XApiToolLaunch; |
10
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class TinCanParser. |
14
|
|
|
*/ |
15
|
|
|
class TinCanParser extends PackageParser |
16
|
|
|
{ |
17
|
|
|
public function parse(): XApiToolLaunch |
18
|
|
|
{ |
19
|
|
|
$content = file_get_contents($this->filePath); |
20
|
|
|
|
21
|
|
|
$xml = new Crawler($content); |
22
|
|
|
|
23
|
|
|
$activityNode = $xml->filter('tincan activities activity')->first(); |
24
|
|
|
$nodeName = $activityNode->filter('name'); |
25
|
|
|
$nodeDescription = $activityNode->filter('description'); |
26
|
|
|
$nodeLaunch = $activityNode->filter('launch'); |
27
|
|
|
|
28
|
|
|
$toolLaunch = new XApiToolLaunch(); |
29
|
|
|
$toolLaunch |
30
|
|
|
->setCourse($this->course) |
31
|
|
|
->setSession($this->session) |
32
|
|
|
->setCreatedAt(api_get_utc_datetime(null, false, true)) |
33
|
|
|
->setActivityId($activityNode->attr('id')) |
34
|
|
|
->setActivityType($activityNode->attr('type')) |
35
|
|
|
->setLaunchUrl($this->parseLaunchUrl($nodeLaunch)) |
36
|
|
|
; |
37
|
|
|
|
38
|
|
|
if ($nodeName) { |
39
|
|
|
$toolLaunch->setTitle($nodeName->text()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ($nodeDescription) { |
43
|
|
|
$toolLaunch->setDescription($nodeDescription->text() ?: null); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $toolLaunch; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function parseLaunchUrl(Crawler $launchNode): string |
50
|
|
|
{ |
51
|
|
|
$launchUrl = $launchNode->text(); |
52
|
|
|
|
53
|
|
|
$urlInfo = parse_url($launchUrl); |
54
|
|
|
|
55
|
|
|
if (empty($urlInfo['scheme'])) { |
56
|
|
|
$baseUrl = str_replace( |
57
|
|
|
api_get_path(SYS_COURSE_PATH), |
|
|
|
|
58
|
|
|
api_get_path(WEB_COURSE_PATH), |
59
|
|
|
\dirname($this->filePath) |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
return "$baseUrl/$launchUrl"; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $launchUrl; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|