Internal: Fix course creation

pull/3466/head
Julio Montoya 4 years ago
parent 60249b030d
commit 20bfa1b5cb
  1. 16
      src/CoreBundle/Entity/Listener/CourseListener.php
  2. 19
      src/CoreBundle/Entity/Listener/ResourceListener.php
  3. 6
      src/CoreBundle/Entity/Listener/ResourceNodeListener.php
  4. 7
      src/CoreBundle/ToolChain.php
  5. 3
      src/CourseBundle/Entity/CAnnouncement.php
  6. 3
      src/CourseBundle/Entity/CCalendarEvent.php
  7. 3
      src/CourseBundle/Entity/CDocument.php
  8. 3
      src/CourseBundle/Entity/CStudentPublication.php

@ -34,11 +34,10 @@ class CourseListener
/**
* CourseListener constructor.
*/
public function __construct(CToolRepository $toolRepository, ToolChain $toolChain, SettingsManager $settingsManager)
public function __construct(ToolChain $toolChain, SettingsManager $settingsManager)
{
$this->toolChain = $toolChain;
$this->settingsManager = $settingsManager;
$this->toolRepository = $toolRepository;
}
/**
@ -56,26 +55,25 @@ class CourseListener
{
error_log('Course listener prePersist');
if ($course) {
/*$urlRelCourse = $course->getUrls()->first();
$url = $urlRelCourse->getUrl();*/
//$url = $course->getCurrentUrl();
//$repo = $args->getEntityManager()->getRepository('ChamiloCoreBundle:Course');
///$this->checkLimit($repo, $course, $url);
$this->toolChain->addToolsInCourse($this->toolRepository, $course);
// $this->checkLimit($repo, $course, $url);
//$this->toolChain->addToolsInCourse($this->toolRepository, $course);
}
}
public function postPersist(Course $course, LifecycleEventArgs $args)
{
error_log('postPersist');
error_log('Course listener postPersist');
/** @var AccessUrlRelCourse $urlRelCourse */
if ($course) {
error_log('add tools');
//$this->toolChain->addToolsInCourse($this->toolRepository, $course);
/*$urlRelCourse = $course->getUrls()->first();
$url = $urlRelCourse->getUrl();*/
//$url = $course->getCurrentUrl();
//$repo = $args->getEntityManager()->getRepository('ChamiloCoreBundle:Course');
///$this->checkLimit($repo, $course, $url);
//$this->toolChain->addToolsInCourse($course);
$this->toolChain->addToolsInCourse($course);
}
}

@ -5,11 +5,11 @@
namespace Chamilo\CoreBundle\Entity\Listener;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\ResourceFile;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\ResourceRight;
use Chamilo\CoreBundle\Entity\ResourceToCourseInterface;
use Chamilo\CoreBundle\Entity\ResourceToRootInterface;
use Chamilo\CoreBundle\Entity\ResourceWithUrlInterface;
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
@ -245,15 +245,20 @@ class ResourceListener
}
}
if ($resource instanceof ResourceToCourseInterface) {
if (null !== $resource->getParent()) {
$resourceNode->setParent($resource->getParent()->getResourceNode());
}
if (null !== $resource->getParent()) {
$resourceNode->setParent($resource->getParent()->getResourceNode());
}
error_log('Listener end, adding resource node');
$resource->setResourceNode($resourceNode);
// All resources should have a parent, except AccessUrl.
if (!($resource instanceof AccessUrl)) {
if (null == $resourceNode->getParent()) {
throw new \InvalidArgumentException('Resource Node should have a parent');
}
}
return $resourceNode;
}
@ -262,7 +267,7 @@ class ResourceListener
*/
public function preUpdate(AbstractResource $resource, PreUpdateEventArgs $event)
{
error_log('resource listener preUpdate');
//error_log('resource listener preUpdate');
$this->updateResourceName($resource);
$resourceNode = $resource->getResourceNode();
@ -285,7 +290,7 @@ class ResourceListener
public function postUpdate(AbstractResource $resource, LifecycleEventArgs $event)
{
error_log('resource listener postUpdate');
//error_log('resource listener postUpdate');
//$em = $event->getEntityManager();
//$this->updateResourceName($resource, $resource->getResourceName(), $em);
}

@ -43,7 +43,7 @@ class ResourceNodeListener
public function prePersist(ResourceNode $resourceNode, LifecycleEventArgs $event)
{
error_log('resource node prePersist');
//error_log('resource node prePersist');
return true;
}
@ -53,7 +53,7 @@ class ResourceNodeListener
*/
public function preUpdate(ResourceNode $resourceNode, PreUpdateEventArgs $event)
{
error_log('resource node preUpdate');
//error_log('resource node preUpdate');
if ($resourceNode->hasResourceFile() && $resourceNode->isFileEditableText()) {
$fileName = $this->resourceNodeRepository->getFilename($resourceNode->getResourceFile());
@ -68,6 +68,6 @@ class ResourceNodeListener
public function postUpdate(ResourceNode $resourceNode, LifecycleEventArgs $event)
{
error_log('ResourceNode postUpdate');
//error_log('ResourceNode postUpdate');
}
}

@ -129,13 +129,11 @@ class ToolChain
//$tool->addToolResourceRight($toolResourceRightReader);
}
public function addToolsInCourse(CToolRepository $toolRepository, Course $course): Course
public function addToolsInCourse(Course $course): Course
{
$tools = $this->getTools();
$manager = $this->entityManager;
$toolVisibility = $this->settingsManager->getSetting('course.active_tools_on_create');
$token = $this->security->getToken();
$user = $token->getUser();
// Hardcoded tool list order
$toolList = [
@ -184,8 +182,9 @@ class ToolChain
->setPosition($position)
->setVisibility($visibility)
->setCategory($tool->getCategory())
->setParent($course)
->addCourseLink($course)
;
$toolRepository->addResourceToCourse($courseTool, ResourceLink::VISIBILITY_PUBLISHED, $user, $course);
$course->addTool($courseTool);
}

@ -6,7 +6,6 @@ namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceToCourseInterface;
use Doctrine\ORM\Mapping as ORM;
/**
@ -15,7 +14,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(name="c_announcement")
* @ORM\Entity
*/
class CAnnouncement extends AbstractResource implements ResourceInterface, ResourceToCourseInterface
class CAnnouncement extends AbstractResource implements ResourceInterface
{
/**
* @var int

@ -6,7 +6,6 @@ namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceToCourseInterface;
use Chamilo\CoreBundle\Entity\Room;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
@ -23,7 +22,7 @@ use Doctrine\ORM\Mapping as ORM;
* )
* @ORM\Entity
*/
class CCalendarEvent extends AbstractResource implements ResourceInterface, ResourceToCourseInterface
class CCalendarEvent extends AbstractResource implements ResourceInterface
{
/**
* @var int

@ -14,7 +14,6 @@ use Chamilo\CoreBundle\Controller\Api\UpdateResourceNodeFileAction;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceToCourseInterface;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait;
use Doctrine\ORM\Mapping as ORM;
@ -127,7 +126,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\ResourceListener"})
* @ORM\Entity
*/
class CDocument extends AbstractResource implements ResourceInterface, ResourceToCourseInterface
class CDocument extends AbstractResource implements ResourceInterface
{
use ShowCourseResourcesInSessionTrait;

@ -6,7 +6,6 @@ namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceToCourseInterface;
use Chamilo\CoreBundle\Entity\Session;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@ -24,7 +23,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* )
* @ORM\Entity()
*/
class CStudentPublication extends AbstractResource implements ResourceInterface, ResourceToCourseInterface
class CStudentPublication extends AbstractResource implements ResourceInterface
{
/**
* @var int

Loading…
Cancel
Save