chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | |||
| 3 | /* For licensing terms, see /license.txt */ |
||
| 4 | |||
| 5 | use Chamilo\PluginBundle\Entity\XApi\Cmi5Item; |
||
| 6 | use Chamilo\PluginBundle\Entity\XApi\ToolLaunch; |
||
| 7 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
||
|
0 ignored issues
–
show
|
|||
| 8 | use Xabbuh\XApi\Model\LanguageMap; |
||
| 9 | |||
| 10 | require_once __DIR__.'/../../../main/inc/global.inc.php'; |
||
| 11 | |||
| 12 | api_protect_course_script(true); |
||
| 13 | api_block_anonymous_users(); |
||
| 14 | |||
| 15 | $request = HttpRequest::createFromGlobals(); |
||
| 16 | |||
| 17 | $em = Database::getManager(); |
||
| 18 | |||
| 19 | $toolLaunch = $em->find( |
||
| 20 | ToolLaunch::class, |
||
| 21 | $request->query->getInt('id') |
||
| 22 | ); |
||
| 23 | |||
| 24 | if (null === $toolLaunch |
||
| 25 | || 'cmi5' !== $toolLaunch->getActivityType() |
||
| 26 | ) { |
||
| 27 | header('Location: '.api_get_course_url()); |
||
| 28 | exit; |
||
| 29 | } |
||
| 30 | |||
| 31 | $plugin = XApiPlugin::create(); |
||
| 32 | $course = api_get_course_entity(); |
||
| 33 | $session = api_get_session_entity(); |
||
| 34 | $cidReq = api_get_cidreq(); |
||
| 35 | $user = api_get_user_entity(api_get_user_id()); |
||
| 36 | $interfaceLanguage = api_get_interface_language(); |
||
| 37 | |||
| 38 | $itemsRepo = $em->getRepository(Cmi5Item::class); |
||
| 39 | |||
| 40 | $query = $em->createQueryBuilder() |
||
| 41 | ->select('item') |
||
| 42 | ->from(Cmi5Item::class, 'item') |
||
| 43 | ->where('item.tool = :tool') |
||
| 44 | ->setParameter('tool', $toolLaunch->getId()) |
||
| 45 | ->getQuery(); |
||
| 46 | |||
| 47 | $tocHtml = $itemsRepo->buildTree( |
||
| 48 | $query->getArrayResult(), |
||
| 49 | [ |
||
| 50 | 'decorate' => true, |
||
| 51 | 'rootOpen' => '<ul>', |
||
| 52 | 'rootClose' => '</ul>', |
||
| 53 | 'childOpen' => '<li>', |
||
| 54 | 'childClose' => '</li>', |
||
| 55 | 'nodeDecorator' => function ($node) use ($interfaceLanguage, $cidReq, $toolLaunch) { |
||
| 56 | $titleMap = LanguageMap::create($node['title']); |
||
| 57 | $title = XApiPlugin::extractVerbInLanguage($titleMap, $interfaceLanguage); |
||
| 58 | |||
| 59 | if ('block' === $node['type']) { |
||
| 60 | return Display::page_subheader($title, null, 'h4'); |
||
| 61 | } |
||
| 62 | |||
| 63 | return Display::url( |
||
| 64 | $title, |
||
| 65 | "launch.php?tool={$toolLaunch->getId()}&id={$node['id']}&$cidReq", |
||
| 66 | [ |
||
| 67 | 'target' => 'ifr_content', |
||
| 68 | 'class' => 'text-left btn-link', |
||
| 69 | ] |
||
| 70 | ); |
||
| 71 | }, |
||
| 72 | ] |
||
| 73 | ); |
||
| 74 | |||
| 75 | $webPluginPath = api_get_path(WEB_PLUGIN_PATH); |
||
| 76 | |||
| 77 | $htmlHeadXtra[] = api_get_css($webPluginPath.'xapi/assets/css/cmi5_launch.css'); |
||
| 78 | $htmlHeadXtra[] = api_get_js_simple($webPluginPath.'xapi/assets/js/cmi5_launch.js'); |
||
| 79 | |||
| 80 | $view = new Template('', false, false, true, true, false); |
||
| 81 | $view->assign('tool', $toolLaunch); |
||
| 82 | $view->assign('toc_html', $tocHtml); |
||
| 83 | $view->assign('content', $view->fetch('xapi/views/cmi5_launch.twig')); |
||
| 84 | $view->display_no_layout_template(); |
||
| 85 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: