Skip to content

Commit

Permalink
set melis package version to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
mariateresapomar committed Jun 21, 2022
2 parents 4e7651a + 2cccf41 commit fd6c9f4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
37 changes: 23 additions & 14 deletions Controller/AlbumController.php
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Psr\Container\ContainerInterface;
use Doctrine\Persistence\ManagerRegistry;

class AlbumController extends AbstractController
{
Expand All @@ -22,14 +24,18 @@ class AlbumController extends AbstractController
* @var ParameterBagInterface
*/
protected $parameters;
protected $container;
protected $doctrine;

/**
* AlbumController constructor.
* @param ParameterBagInterface $parameterBag
*/
public function __construct(ParameterBagInterface $parameterBag)
public function __construct(ParameterBagInterface $parameterBag, ContainerInterface $container, ManagerRegistry $doctrine)
{
$this->parameters = $parameterBag;
$this->container = $container;
$this->doctrine = $doctrine;
}

/**
Expand All @@ -50,7 +56,7 @@ public function getAlbumTool(): Response
* Get the album list using
* the album entity
*/
$album = $this->getDoctrine()
$album = $this->doctrine
->getRepository(Album::class)
->findAll();

Expand All @@ -77,7 +83,7 @@ public function getAlbumPlugin(): Response
* Get the album list using
* the album entity
*/
$album = $this->getDoctrine()
$album = $this->doctrine
->getRepository(Album::class)
->findAll();

Expand Down Expand Up @@ -129,7 +135,7 @@ public function getAlbumList(Request $request)
$search = $search['value'];

//get repository
$repository = $this->getDoctrine()->getRepository(Album::class);
$repository = $this->doctrine->getRepository(Album::class);
//get total records
$total = $repository->getTotalRecords();
//get data
Expand Down Expand Up @@ -161,7 +167,7 @@ public function getAlbumList(Request $request)
*/
public function createAlbumForm($id)
{
$translator = $this->get('translator');
$translator = $this->container->get('translator');
$data = [];
foreach($this->getAlbumModalConfig()['tabs'] as $tabName => $tab) {
/**
Expand All @@ -170,7 +176,7 @@ public function createAlbumForm($id)
if(!empty($tab['form'])) {

if(!empty($id)) {
$album = $this->getDoctrine()
$album = $this->doctrine
->getRepository(Album::class)
->find($id);

Expand Down Expand Up @@ -221,9 +227,9 @@ public function saveAlbum($id, Request $request): JsonResponse
'errors' => []
];

$translator = $this->get('translator');
$translator = $this->container->get('translator');
if($request->getMethod() == 'POST') {
$entityManager = $this->getDoctrine()->getManager();
$entityManager = $this->doctrine->getManager();
if (empty($id)) {//create new album
$album = new Album();
//set typeCode form logs
Expand All @@ -243,6 +249,9 @@ public function saveAlbum($id, Request $request): JsonResponse
//validate form
if($form->isSubmitted() && $form->isValid()) {
$album = $form->getData();
if (empty($id)) {
$album->setAlbDate(date("Y-m-d H:i:s", time()));
}
// tell Doctrine you want to (eventually) save the Album (no queries yet)
$entityManager->persist($album);
// executes the queries
Expand Down Expand Up @@ -282,15 +291,15 @@ public function deleteAlbum(Request $request): JsonResponse
$typeCode = 'SYMFONY_DEMO_TOOL_DELETE';
$id = $request->get('id', null);

$translator = $this->get('translator');
$translator = $this->container->get('translator');

$result = [
'title' => 'Album',
'success' => false,
'message' => $translator->trans('tool_cannot_delete_album'),
];
try {
$entityManager = $this->getDoctrine()->getManager();
$entityManager = $this->doctrine->getManager();
$album = $entityManager->getRepository(Album::class)->find($id);
$entityManager->remove($album);
$entityManager->flush();
Expand All @@ -316,7 +325,7 @@ public function deleteAlbum(Request $request): JsonResponse
*/
private function getErrorsFromForm(FormInterface $form)
{
$translator = $this->get('translator');
$translator = $this->container->get('translator');
$errors = array();
foreach ($form->getErrors() as $error) {
$errors[] = $error->getMessage();
Expand Down Expand Up @@ -392,7 +401,7 @@ private function getAlbumTableConfigColumns()
*/
private function getAlbumTableConfig()
{
$translator = $this->get('translator');
$translator = $this->container->get('translator');
$tableConfig = [];
if(!empty($this->parameters->get('symfony_demo_album_table'))){
$tableConfig = $this->parameters->get('symfony_demo_album_table');
Expand All @@ -407,7 +416,7 @@ private function getAlbumTableConfig()
*/
private function getAlbumModalConfig()
{
$translator = $this->get('translator');
$translator = $this->container->get('translator');
$modalConfig = [];
if(!empty($this->parameters->get('symfony_demo_album_modal'))){
$modalConfig = $this->parameters->get('symfony_demo_album_modal');
Expand Down Expand Up @@ -440,6 +449,6 @@ private function translateConfig($config, $translator)
*/
private function melisServiceManager()
{
return $this->get('melis_platform.service_manager');
return $this->container->get('melis_platform.service_manager');
}
}
4 changes: 2 additions & 2 deletions Form/Type/AlbumType.php
Expand Up @@ -58,10 +58,10 @@ public function configureOptions(OptionsResolver $resolver)
* so that we can use some of the
* melis javascript helper and tool
*
* @return string|null
* @return string
*/
public function getBlockPrefix()
{
return null;
return '';
}
}
6 changes: 3 additions & 3 deletions Repository/AlbumRepository.php
Expand Up @@ -5,7 +5,7 @@
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Tools\Pagination\Paginator;
use MelisPlatformFrameworkSymfonyDemoToolLogic\Entity\Album;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Doctrine\Persistence\ManagerRegistry;

/**
* @method Album|null find($id, $lockMode = null, $lockVersion = null)
Expand All @@ -23,9 +23,9 @@ class AlbumRepository extends ServiceEntityRepository

/**
* AlbumRepository constructor.
* @param RegistryInterface $registry
* @param ManagerRegistry $registry
*/
public function __construct(RegistryInterface $registry)
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Album::class);
}
Expand Down
4 changes: 2 additions & 2 deletions Resources/translations/messages.en.yaml
@@ -1,5 +1,5 @@
tool_title: A tool embryo made in Symfony4
tool_description: This demo tool has for goal to show how you can use the framework Symfony4 inside Melis Platform, so you're not locked on ZF.
tool_title: A tool embryo made in Symfony5
tool_description: This demo tool has for goal to show how you can use the framework Symfony5 inside Melis Platform, so you're not locked on ZF.
tool_album_table_desc: The table below shows the data fetched from the database using Symfony.
tool_lang_table_desc: The table below shows the data fetched from Melis Platform Services using Symfony.
tool_album_list: Album List
Expand Down
4 changes: 2 additions & 2 deletions Resources/translations/messages.fr.yaml
@@ -1,5 +1,5 @@
tool_title: Un embryon d'outil fait en Symfony4
tool_description: Cet outil a pour but de montrer comment utiliser le framework Symfony4 à l'intérieur de Melis Platform, et ne pas être bloqué en ZF.
tool_title: Un embryon d'outil fait en Symfony5
tool_description: Cet outil a pour but de montrer comment utiliser le framework Symfony5 à l'intérieur de Melis Platform, et ne pas être bloqué en ZF.
tool_album_table_desc: Le tableau ci-dessous affiche les données extraites de la base de données en utilisant Symfony.
tool_lang_table_desc: Le tableau ci-dessous affiche les données extraites des services de Melis Platform en utilisant Symfony.
tool_album_list: Liste des albums
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -24,8 +24,8 @@
"module"
],
"require": {
"php": "^7.1.3|^7.2|^7.3",
"melisplatform/melis-platform-framework-symfony-demo-tool": "^4.0"
"php": "^7.3|^8.0",
"melisplatform/melis-platform-framework-symfony-demo-tool": "^5.0"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit fd6c9f4

Please sign in to comment.