Internal: Course: Change entity listener to add tools when pre-persisting

pull/4853/head
Angel Fernando Quiroz Campos 1 year ago
parent 005d16a2ed
commit 53a53a3a0f
  1. 1
      public/main/inc/lib/add_course.lib.inc.php
  2. 11
      src/CoreBundle/Entity/Course.php
  3. 43
      src/CoreBundle/Entity/Listener/CourseListener.php

@ -753,7 +753,6 @@ class AddCourse
->setVideoUrl($params['video_url'] ?? '')
->setUnsubscribe($unsubscribe)
->setVisualCode($visual_code)
->addAccessUrl(api_get_url_entity())
->setCreator(api_get_user_entity())
;

@ -966,12 +966,11 @@ class Course extends AbstractResource implements
return $this->urls;
}
public function setUrls(Collection $urls): self
public function addUrls(AccessUrlRelCourse $urlRelCourse): static
{
$this->urls = new ArrayCollection();
foreach ($urls as $url) {
$this->addAccessUrl($url);
}
$urlRelCourse->setCourse($this);
$this->urls->add($urlRelCourse);
return $this;
}
@ -979,7 +978,7 @@ class Course extends AbstractResource implements
public function addAccessUrl(?AccessUrl $url): self
{
$urlRelCourse = (new AccessUrlRelCourse())->setCourse($this)->setUrl($url);
$this->addUrlRelCourse($urlRelCourse);
$this->addUrls($urlRelCourse);
return $this;
}

@ -6,13 +6,10 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity\Listener;
use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CoreBundle\Settings\SettingsManager;
use Chamilo\CoreBundle\Tool\ToolChain;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Exception;
use Doctrine\ORM\Event\PrePersistEventArgs;
/**
* Class CourseListener.
@ -28,46 +25,10 @@ class CourseListener
) {
}
/**
* This code is executed when a new course is created.
*
* new object : prePersist
* edited object: preUpdate
*
* This function add the course tools to the current course entity
* thanks to the tool chain see src/Chamilo/CourseBundle/ToolChain.php
*
* @throws Exception
*/
public function prePersist(Course $course, LifecycleEventArgs $args): void
{
//error_log('Course listener prePersist');
/*if ($course) {
// $this->checkLimit($repo, $course, $url);
$this->toolChain->addToolsInCourse($course);
}*/
}
public function postPersist(Course $course, LifecycleEventArgs $args): void
public function prePersist(Course $course, PrePersistEventArgs $args): void
{
///$this->checkLimit($repo, $course, $url);
$this->toolChain->addToolsInCourse($course);
$args->getObjectManager()->persist($course);
$args->getObjectManager()->flush();
}
/**
* This code is executed when a course is updated.
*
* @throws Exception
*/
public function preUpdate(Course $course, LifecycleEventArgs $args): void
{
//error_log('preUpdate');
/*$url = $course->getCurrentUrl();
$repo = $args->getEntityManager()->getRepository('ChamiloCoreBundle:Course');
$this->checkLimit($repo, $course, $url);*/
}
/*protected function checkLimit(CourseRepository $repo, Course $course, AccessUrl $url): void

Loading…
Cancel
Save