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

@ -46,4 +46,12 @@ trait CourseControllerTrait
{ {
return $this->session; 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 * Class CourseAccessListener
* In and outs of a course * In and outs of a course
* This listeners is always called when user enters the course home. * This listeners is always called when user enters the course home.
*
* @package Chamilo\CourseBundle\EventListener
*/ */
class CourseAccessListener class CourseAccessListener
{ {

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

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

@ -1,18 +1,18 @@
{% extends "@ChamiloTheme/Layout/layout_one_col.html.twig" %} {% extends "@ChamiloTheme/Layout/layout_one_col.html.twig" %}
{% block content %} {% block content %}
{% if is_granted('ROLE_CURRENT_COURSE_TEACHER') %} {% if is_granted('EDIT', course) %}
<div class="actions"> <div class="actions">
<a class="btn btn-secondary" <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 }} {{ 'New folder' | trans }}
</a> </a>
<a class="btn btn-secondary" <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 }} {{ 'Create new document' | trans }}
</a> </a>
<a class="btn btn-secondary" <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 }} {{ 'Upload' | trans }}
</a> </a>
</div> </div>

Loading…
Cancel
Save