Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Conflicts:
	composer.json
  • Loading branch information
ngodfraind committed Apr 30, 2015
2 parents 8082796 + 5cbb890 commit 98d43c9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 38 deletions.
33 changes: 19 additions & 14 deletions Controller/ScormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration as EXT;
use JMS\DiExtraBundle\Annotation as DI;

Expand All @@ -36,30 +37,34 @@ class ScormController extends Controller
private $om;
private $request;
private $scormManager;
private $securityContext;
private $tokenStorage;
private $authorization;

/**
* @DI\InjectParams({
* "eventDispatcher" = @DI\Inject("event_dispatcher"),
* "om" = @DI\Inject("claroline.persistence.object_manager"),
* "requestStack" = @DI\Inject("request_stack"),
* "scormManager" = @DI\Inject("claroline.manager.scorm_manager"),
* "securityContext" = @DI\Inject("security.context")
* "authorization" = @DI\Inject("security.authorization_checker"),
* "tokenStorage" = @DI\Inject("security.token_storage")
* })
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
ObjectManager $om,
RequestStack $requestStack,
ScormManager $scormManager,
SecurityContextInterface $securityContext
TokenStorageInterface $tokenStorage,
AuthorizationCheckerInterface $authorization
)
{
$this->eventDispatcher = $eventDispatcher;
$this->om = $om;
$this->request = $requestStack;
$this->scormManager = $scormManager;
$this->securityContext = $securityContext;
$this->tokenStorage = $tokenStorage;
$this->authorization = $authorization;
}

/**
Expand All @@ -81,7 +86,7 @@ public function __construct(
public function renderScorm12ResourceAction(Scorm12Resource $scorm)
{
$this->checkAccess('OPEN', $scorm);
$user = $this->securityContext->getToken()->getUser();
$user = $this->tokenStorage->getToken()->getUser();
$rootScos = array();
$trackings = array();
$scos = $scorm->getScos();
Expand Down Expand Up @@ -132,7 +137,7 @@ public function renderScorm12ResourceAction(Scorm12Resource $scorm)
*/
public function renderScorm12ScoAction(Scorm12Sco $scorm12Sco)
{
$user = $this->securityContext->getToken()->getUser();
$user = $this->tokenStorage->getToken()->getUser();
$scorm = $scorm12Sco->getScormResource();
$this->checkAccess('OPEN', $scorm);

Expand Down Expand Up @@ -213,7 +218,7 @@ public function commitScorm12Tracking(
$entry = $datasArray[11];
$exitMode = $datasArray[12];

$user = $this->securityContext->getToken()->getUser();
$user = $this->tokenStorage->getToken()->getUser();

if ($user->getId() !== $studentId) {
throw new AccessDeniedException();
Expand Down Expand Up @@ -364,7 +369,7 @@ private function logScorm12ScoResult(
public function renderScorm2004ResourceAction(Scorm2004Resource $scorm)
{
$this->checkScorm2004ResourceAccess('OPEN', $scorm);
$user = $this->securityContext->getToken()->getUser();
$user = $this->tokenStorage->getToken()->getUser();
$rootScos = array();
$trackings = array();
$scos = $scorm->getScos();
Expand Down Expand Up @@ -415,7 +420,7 @@ public function renderScorm2004ResourceAction(Scorm2004Resource $scorm)
*/
public function renderScorm2004ScoAction(Scorm2004Sco $scorm2004Sco)
{
$user = $this->securityContext->getToken()->getUser();
$user = $this->tokenStorage->getToken()->getUser();
$scorm = $scorm2004Sco->getScormResource();
$this->checkScorm2004ResourceAccess('OPEN', $scorm);

Expand Down Expand Up @@ -513,7 +518,7 @@ public function commitScorm2004Tracking(
Scorm2004Sco $scorm2004Sco
)
{
$user = $this->securityContext->getToken()->getUser();
$user = $this->tokenStorage->getToken()->getUser();
$datas = $this->request->getCurrentRequest()->request->all();
$learnerId = isset($datas['cmi.learner_id']) ?
(int)$datas['cmi.learner_id'] :
Expand Down Expand Up @@ -733,7 +738,7 @@ private function checkAccess($permission, Scorm12Resource $resource)
{
$collection = new ResourceCollection(array($resource->getResourceNode()));

if (!$this->securityContext->isGranted($permission, $collection)) {
if (!$this->authorization->isGranted($permission, $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
}
Expand All @@ -750,8 +755,8 @@ private function checkScorm2004ResourceAccess($permission, Scorm2004Resource $re
{
$collection = new ResourceCollection(array($resource->getResourceNode()));

if (!$this->securityContext->isGranted($permission, $collection)) {
if (!$this->authorization->isGranted($permission, $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
}
}
}
11 changes: 3 additions & 8 deletions Listener/Scorm12Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\TranslatorInterface;

/**
* @DI\Service
Expand All @@ -53,7 +52,6 @@ class Scorm12Listener
// path to the Scorm unzipped files
private $scormResourcesPath;
private $scorm12ScoTrackingRepo;
private $securityContext;
private $templating;
private $translator;
private $scormManager;
Expand All @@ -66,7 +64,6 @@ class Scorm12Listener
* "om" = @DI\Inject("claroline.persistence.object_manager"),
* "requestStack" = @DI\Inject("request_stack"),
* "router" = @DI\Inject("router"),
* "securityContext" = @DI\Inject("security.context"),
* "templating" = @DI\Inject("templating"),
* "translator" = @DI\Inject("translator"),
* "scormManager" = @DI\Inject("claroline.manager.scorm_manager")
Expand All @@ -79,9 +76,8 @@ public function __construct(
ObjectManager $om,
RequestStack $requestStack,
UrlGeneratorInterface $router,
SecurityContextInterface $securityContext,
TwigEngine $templating,
Translator $translator
TranslatorInterface $translator
)
{
$this->container = $container;
Expand All @@ -96,7 +92,6 @@ public function __construct(
$this->scormResourcesPath = $this->container
->getParameter('kernel.root_dir') . '/../web/uploads/scormresources/';
$this->scorm12ScoTrackingRepo = $om->getRepository('ClarolineScormBundle:Scorm12ScoTracking');
$this->securityContext = $securityContext;
$this->templating = $templating;
$this->translator = $translator;
}
Expand Down Expand Up @@ -332,4 +327,4 @@ private function copySco(
$this->copySco($scoChild, $resource, $scoCopy);
}
}
}
}
9 changes: 2 additions & 7 deletions Listener/Scorm2004Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\TranslatorInterface;

/**
* @DI\Service
Expand All @@ -52,7 +51,6 @@ class Scorm2004Listener
// path to the Scorm unzipped files
private $scormResourcesPath;
private $scorm2004ScoTrackingRepo;
private $securityContext;
private $templating;
private $translator;

Expand All @@ -64,7 +62,6 @@ class Scorm2004Listener
* "om" = @DI\Inject("claroline.persistence.object_manager"),
* "requestStack" = @DI\Inject("request_stack"),
* "router" = @DI\Inject("router"),
* "securityContext" = @DI\Inject("security.context"),
* "templating" = @DI\Inject("templating"),
* "translator" = @DI\Inject("translator")
* })
Expand All @@ -76,9 +73,8 @@ public function __construct(
ObjectManager $om,
RequestStack $requestStack,
UrlGeneratorInterface $router,
SecurityContextInterface $securityContext,
TwigEngine $templating,
Translator $translator
TranslatorInterface $translator
)
{
$this->container = $container;
Expand All @@ -93,7 +89,6 @@ public function __construct(
$this->scormResourcesPath = $this->container
->getParameter('kernel.root_dir') . '/../web/uploads/scormresources/';
$this->scorm2004ScoTrackingRepo = $om->getRepository('ClarolineScormBundle:Scorm2004ScoTracking');
$this->securityContext = $securityContext;
$this->templating = $templating;
$this->translator = $translator;
}
Expand Down
24 changes: 24 additions & 0 deletions Resources/public/js/iframe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This file is part of the Claroline Connect package.
*
* (c) Claroline Consortium <consortium@claroline.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

(function () {
'use strict';

window.Claroline = window.Claroline || {};

var iframe = window.Claroline.Iframe = {};

iframe.resize = function(frameId) {
var height = window.innerWidth;//Firefox
if (document.body.clientHeight) height=document.body.clientHeight;//IE

var frame = document.getElementById(frameId);
frame.style.height = parseInt(height - frame.offsetTop - 8) + "px";
}
}());
15 changes: 11 additions & 4 deletions Resources/views/scorm12MenuSco.html.twig
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% macro renderMenu(scos) %}
<ul>
{% for sco in scos %}

{% if sco.getIsBlock() %}
{% set scoChildren = sco.getScoChildren() %}
<li><b>{{ sco.getTitle() }}</b></li>

{% if scoChildren is not null %}
{{ _self.renderMenu(scoChildren) }}
{% endif %}

{% else %}
<li sco-id="{{sco.getId()}}">
<a href="{{ path('claro_render_scorm_12_sco', {'scoId': sco.getId()}) }}"
Expand All @@ -33,6 +33,13 @@
{% extends layout %}

{% block javascripts %}
<script src="{{ asset('bundles/clarolinescorm/js/iframe.js') }}" type="text/javascript"></script>
<script type="text/javascript">
window.Claroline.Iframe.resize('scorm-frame');
$(window).resize(function() {
window.Claroline.Iframe.resize('scorm-frame');
});
</script>
<script src="{{ asset('bundles/clarolinescorm/js/scorm_12_api.js') }}" type="text/javascript"></script>
{{ parent() }}
<script type="text/javascript">
Expand Down Expand Up @@ -67,7 +74,7 @@
runPrefixedMethod(document.getElementById('scorm-frame'), 'RequestFullScreen');
}
}
</script>
{% endblock %}

Expand Down
17 changes: 12 additions & 5 deletions Resources/views/scorm2004MenuSco.html.twig
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% macro renderMenu(scos) %}
<ul>
{% for sco in scos %}

{% if sco.getIsBlock() %}
{% set scoChildren = sco.getScoChildren() %}
<li><b>{{ sco.getTitle() }}</b></li>

{% if scoChildren is not null %}
{{ _self.renderMenu(scoChildren) }}
{% endif %}

{% else %}
<li sco-id="{{sco.getId()}}">
<a href="{{ path('claro_render_scorm_2004_sco', {'scoId': sco.getId()}) }}"
Expand All @@ -33,7 +33,13 @@
{% extends layout %}

{% block javascripts %}
<script src="{{ asset('bundles/clarolinescorm/js/iframe.js') }}" type="text/javascript">
</script>
<script type="text/javascript">
window.Claroline.Iframe.resize('scorm-frame');
$(window).resize(function() {
window.Claroline.Iframe.resize('scorm-frame');
});
var trackingDetails = {{ scoTrackingDetails|raw }};
</script>
<script src="{{ asset('bundles/clarolinescorm/js/scorm_2004_api.js') }}" type="text/javascript">
Expand Down Expand Up @@ -71,7 +77,7 @@
runPrefixedMethod(document.getElementById('scorm-frame'), 'RequestFullScreen');
}
}
</script>
{% endblock %}

Expand Down Expand Up @@ -107,7 +113,8 @@
<iframe id="scorm-frame"
class="full-size"
src="{{ asset(scormUrl) }}"
frameborder="0">
frameborder="0"
>
</iframe>
</div>
</div>
Expand Down

0 comments on commit 98d43c9

Please sign in to comment.