-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from dmolineus/feature/recorded-event
Dispatch an event when a survey is submitted
- Loading branch information
Showing
11 changed files
with
132 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @author Moritz Vondano | ||
* @license MIT | ||
*/ | ||
|
||
namespace Mvo\ContaoSurvey\Event; | ||
|
||
use Contao\Model; | ||
use Mvo\ContaoSurvey\Entity\Record; | ||
use Mvo\ContaoSurvey\Entity\Survey; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
class SurveySubmittedEvent | ||
{ | ||
private Survey $survey; | ||
|
||
private Record $record; | ||
|
||
private Model $context; | ||
|
||
public function __construct(Survey $survey, Record $record, Model $context) | ||
{ | ||
$this->survey = $survey; | ||
$this->record = $record; | ||
$this->context = $context; | ||
} | ||
|
||
public function getSurvey(): Survey | ||
{ | ||
return $this->survey; | ||
} | ||
|
||
public function getRecord(): Record | ||
{ | ||
return $this->record; | ||
} | ||
|
||
/** | ||
* Get the context where the survey was stored. Usually a content element or module model. | ||
*/ | ||
public function getContext(): Model | ||
{ | ||
return $this->context; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @author Moritz Vondano | ||
* @license MIT | ||
*/ | ||
|
||
namespace Mvo\ContaoSurvey\EventListener; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Mvo\ContaoSurvey\Event\SurveySubmittedEvent; | ||
use Terminal42\ServiceAnnotationBundle\Annotation\ServiceTag; | ||
|
||
class StoreRecordListener | ||
{ | ||
private EntityManagerInterface $entityManager; | ||
|
||
public function __construct(EntityManagerInterface $entityManager) | ||
{ | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
/** | ||
* @ServiceTag(name="kernel_event_listener", event="Mvo\ContaoSurvey\Event\SurveySubmittedEvent", priority="128") | ||
*/ | ||
public function __invoke(SurveySubmittedEvent $event): void | ||
{ | ||
if (!$event->getSurvey()->isStoreRecords()) { | ||
return; | ||
} | ||
|
||
$this->entityManager->persist($event->getRecord()); | ||
$this->entityManager->flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters