Add session support for resources

pull/3064/head
Julio Montoya 5 years ago
parent f2f2945312
commit 87bc432356
  1. 16
      src/CoreBundle/Controller/ResourceController.php
  2. 8
      src/CourseBundle/Controller/CourseControllerTrait.php
  3. 2
      src/CourseBundle/EventListener/CourseAccessListener.php
  4. 3
      src/CourseBundle/EventListener/CourseListener.php
  5. 13
      src/CourseBundle/EventListener/SessionAccessListener.php
  6. 8
      src/ThemeBundle/Resources/views/Resource/index.html.twig

@ -133,7 +133,13 @@ class ResourceController extends AbstractResourceController implements CourseCon
$translation = $this->translator;
$courseIdentifier = $course->getCode();
$routeParams = ['tool' => $tool, 'type' => $type, 'cidReq' => $courseIdentifier, 'id'];
$routeParams = [
'tool' => $tool,
'type' => $type,
'cidReq' => $courseIdentifier,
'id',
'id_session' => $this->getSessionId(),
];
// Title link.
$grid->getColumn('title')->setTitle($this->trans('Name'));
@ -210,7 +216,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$grid->setHiddenColumns(['iid']);
// Delete mass action.
if ($this->isGranted(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER)) {
if ($this->isGranted(ResourceNodeVoter::DELETE, $this->getCourse())) {
$deleteMassAction = new MassAction(
'Delete',
'ChamiloCoreBundle:Resource:deleteMass',
@ -240,7 +246,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$myRowAction->addManipulateRender($setNodeParameters);
$grid->addRowAction($myRowAction);
if ($this->isGranted(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER)) {
if ($this->isGranted(ResourceNodeVoter::EDIT, $this->getCourse())) {
// Edit action.
$myRowAction = new RowAction(
$translation->trans('Edit'),
@ -728,8 +734,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$this->setBreadCrumb( $request);
//$helper = $this->container->get('oneup_uploader.templating.uploader_helper');
//$endpoint = $helper->endpoint('courses');
$session = $this->getSession();
$sessionId = $session ? $session->getId() : 0;
$sessionId = $this->getSessionId();
return $this->render(
'@ChamiloTheme/Resource/upload.html.twig',
@ -962,6 +967,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
'tool' => $tool,
'type' => $type,
'cidReq' => $this->getCourse()->getCode(),
'id_session' => $this->getSessionId(),
]
);
}

@ -46,4 +46,12 @@ trait CourseControllerTrait
{
return $this->session;
}
/**
* @return int
*/
public function getSessionId()
{
return $this->session ? $this->getSession()->getId() : 0;
}
}

@ -12,8 +12,6 @@ use Symfony\Component\HttpFoundation\RequestStack;
* Class CourseAccessListener
* In and outs of a course
* This listeners is always called when user enters the course home.
*
* @package Chamilo\CourseBundle\EventListener
*/
class CourseAccessListener
{

@ -150,6 +150,9 @@ class CourseListener
$sessionHandler->set('session_name', $session->getName());
$sessionHandler->set('id_session', $session->getId());
$sessionHandler->set('sessionObj', $session);
$container->get('twig')->addGlobal('sessionObj', $session);
} else {
throw new NotFoundHttpException($translator->trans('Session not found'));
}

@ -10,8 +10,6 @@ use Symfony\Component\HttpFoundation\RequestStack;
/**
* Class SessionAccessListener.
*
* @package Chamilo\CourseBundle\EventListener
*/
class SessionAccessListener
{
@ -22,16 +20,27 @@ class SessionAccessListener
*/
protected $request;
/**
* SessionAccessListener constructor.
*
* @param EntityManager $em
*/
public function __construct(EntityManager $em)
{
$this->em = $em;
}
/**
* @param RequestStack $requestStack
*/
public function setRequest(RequestStack $requestStack)
{
$this->request = $requestStack->getCurrentRequest();
}
/**
* @param SessionAccess $event
*/
public function onSessionAccessEvent(SessionAccess $event)
{
$user = $event->getUser();

@ -1,18 +1,18 @@
{% extends "@ChamiloTheme/Layout/layout_one_col.html.twig" %}
{% block content %}
{% if is_granted('ROLE_CURRENT_COURSE_TEACHER') %}
{% if is_granted('EDIT', course) %}
<div class="actions">
<a class="btn btn-secondary"
href="{{ url('chamilo_core_resource_new_folder', { 'tool': tool, 'type': type, 'cidReq': course.code, 'id': id}) }}">
href="{{ url('chamilo_core_resource_new_folder', {'tool': tool, 'type': type, 'cidReq': course.code, 'id_session': sessionObj.id, 'id': id }) }}">
{{ 'New folder' | trans }}
</a>
<a class="btn btn-secondary"
href="{{ url('chamilo_core_resource_new', { 'tool': tool, 'type': type, 'cidReq': course.code, 'id': id }) }}">
href="{{ url('chamilo_core_resource_new', { 'tool': tool, 'type': type, 'cidReq': course.code, 'id_session': sessionObj.id, 'id': id }) }}">
{{ 'Create new document' | trans }}
</a>
<a class="btn btn-secondary"
href="{{ url('chamilo_core_resource_upload', { 'tool': tool, 'type': type, 'cidReq': course.code, 'id': id }) }}">
href="{{ url('chamilo_core_resource_upload', { 'tool': tool, 'type': type, 'cidReq': course.code, 'id_session': sessionObj.id, 'id': id }) }}">
{{ 'Upload' | trans }}
</a>
</div>

Loading…
Cancel
Save