<?php
namespace App\EventSubscriber;
use App\Entity\ElCourseJoin;
use Doctrine\ORM\EntityManagerInterface;
use App\Event\ElTaskAttemptPostUpdateEvent;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ElTaskAttemptSubscriber implements EventSubscriberInterface
{
public function __construct(
private EntityManagerInterface $_em,
private Security $security
) {}
public static function getSubscribedEvents(): array
{
return [
ElTaskAttemptPostUpdateEvent::NAME => 'onPostUpdate'
];
}
public function onPostUpdate(ElTaskAttemptPostUpdateEvent $event)
{
$object = $event->getObject();
$elCourse = $object->getElTask()->getElCourse();
$this->_em->getRepository(ElCourseJoin::class)
->calculateCoursePorgress($elCourse, $this->security->getUser());
}
}