Skip to content

Commit

Permalink
Update to adopt to Laminas FW
Browse files Browse the repository at this point in the history
  • Loading branch information
sircxes committed May 6, 2020
1 parent baa1c8f commit 1355be8
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 134 deletions.
247 changes: 115 additions & 132 deletions Controller/AlbumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,30 @@ public function __construct(ParameterBagInterface $parameterBag)
*/
public function getAlbumTool(): Response
{
try {
/**
* Get the languages on melis back office
*/
$melisCoreTableLang = $this->melisServiceManager()->getService('MelisCoreTableLang');
$melisCorelangList = $melisCoreTableLang->fetchAll()->toArray();
/**
* Get the languages on melis back office
*/
$melisCoreTableLang = $this->melisServiceManager()->getService('MelisCoreTableLang');
$melisCorelangList = $melisCoreTableLang->fetchAll()->toArray();

/**
* Get the album list using
* the album entity
*/
$album = $this->getDoctrine()
->getRepository(Album::class)
->findAll();

//add the action column
$view = $this->render('@MelisPlatformFrameworkSymfonyDemoToolLogic/lists.html.twig',
[
'album_list' => $album,
'lang_core_list' => $melisCorelangList,
"tableConfig" => $this->getAlbumTableConfig(),
"modalConfig" => $this->getAlbumModalConfig()
])->getContent();

return new Response($view);
}catch (\Exception $ex){
exit($ex->getMessage());
}
/**
* Get the album list using
* the album entity
*/
$album = $this->getDoctrine()
->getRepository(Album::class)
->findAll();

//add the action column
$view = $this->render('@MelisPlatformFrameworkSymfonyDemoToolLogic/lists.html.twig',
[
'album_list' => $album,
'lang_core_list' => $melisCorelangList,
"tableConfig" => $this->getAlbumTableConfig(),
"modalConfig" => $this->getAlbumModalConfig()
])->getContent();

return new Response($view);
}

/**
Expand All @@ -77,25 +73,20 @@ public function getAlbumTool(): Response
*/
public function getAlbumPlugin(): Response
{
try {
/**
* Get the album list using
* the album entity
*/
$album = $this->getDoctrine()
->getRepository(Album::class)
->findAll();

$view = $this->render('@MelisPlatformFrameworkSymfonyDemoToolLogic/album_plugin.html.twig',
[
'album_list' => $album
])->getContent();
/**
* Get the album list using
* the album entity
*/
$album = $this->getDoctrine()
->getRepository(Album::class)
->findAll();

return new Response($view);
$view = $this->render('@MelisPlatformFrameworkSymfonyDemoToolLogic/album_plugin.html.twig',
[
'album_list' => $album
])->getContent();

}catch (\Exception $ex){
exit($ex->getMessage());
}
return new Response($view);
}

/**
Expand Down Expand Up @@ -170,52 +161,48 @@ public function getAlbumList(Request $request)
*/
public function createAlbumForm($id)
{
try{
$translator = $this->get('translator');
$data = [];
foreach($this->getAlbumModalConfig()['tabs'] as $tabName => $tab) {
/**
* Check if we use form as our content
*/
if(!empty($tab['form'])) {

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

if (!$album) {
throw $this->createNotFoundException(
$translator->trans('tool_no_album_found').' '. $id
);
}
}else{
$album = new Album();
}
$translator = $this->get('translator');
$data = [];
foreach($this->getAlbumModalConfig()['tabs'] as $tabName => $tab) {
/**
* Check if we use form as our content
*/
if(!empty($tab['form'])) {

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

$entityName = $tab['form']['entity_class_name'];
$formTypeName = $tab['form']['form_type_class_name'];
$formView = $tab['form']['form_view_file'];
$formId = $tab['form']['form_id'];

/**
* Create form
*/
$param['form'] = $this->createForm($formTypeName, $album, [
'attr' => [
'id' => $formId
]
])->createView();

$data[$tabName] = $this->renderView($formView, $param);
}else {
$data[$tabName] = $tab['content'];
if (!$album) {
throw $this->createNotFoundException(
$translator->trans('tool_no_album_found').' '. $id
);
}
}else{
$album = new Album();
}

$entityName = $tab['form']['entity_class_name'];
$formTypeName = $tab['form']['form_type_class_name'];
$formView = $tab['form']['form_view_file'];
$formId = $tab['form']['form_id'];

/**
* Create form
*/
$param['form'] = $this->createForm($formTypeName, $album, [
'attr' => [
'id' => $formId
]
])->createView();

$data[$tabName] = $this->renderView($formView, $param);
}else {
$data[$tabName] = $tab['content'];
}
return new JsonResponse($data);
}catch (\Exception $ex){
exit($ex->getMessage());
}
return new JsonResponse($data);
}

/**
Expand All @@ -234,54 +221,50 @@ public function saveAlbum($id, Request $request): JsonResponse
'errors' => []
];

try {
$translator = $this->get('translator');
if($request->getMethod() == 'POST') {
$entityManager = $this->getDoctrine()->getManager();
if (empty($id)) {//create new album
$album = new Album();
//set typeCode form logs
$typeCode = 'SYMFONY_DEMO_TOOL_SAVE';
} else {//update album
$album = $entityManager->getRepository(Album::class)->find($id);
//set typeCode form logs
$typeCode = 'SYMFONY_DEMO_TOOL_UPDATE';
if (!$album) {
throw $this->createNotFoundException(
$translator->trans('tool_no_album_found') .' '. $id
);
}
}
$form = $this->createForm(AlbumType::class, $album);
$form->handleRequest($request);
//validate form
if($form->isSubmitted() && $form->isValid()) {
$album = $form->getData();
// tell Doctrine you want to (eventually) save the Album (no queries yet)
$entityManager->persist($album);
// executes the queries
$entityManager->flush();
//get id
$itemId = $album->getAlbId();

$result['message'] = (empty($id)) ? $translator->trans('tool_album_successfully_saved') : $translator->trans('tool_album_successfully_updated');
$result['success'] = true;
//set icon for flash messenger
$icon = 'glyphicon-info-sign';
}else{
$result['message'] = (empty($id)) ? $translator->trans('tool_unable_to_save_album') : $translator->trans('tool_unable_to_update_album');
$result['errors'] = $this->getErrorsFromForm($form);
//set icon for flash messenger
$icon = 'glyphicon-warning-sign';
$translator = $this->get('translator');
if($request->getMethod() == 'POST') {
$entityManager = $this->getDoctrine()->getManager();
if (empty($id)) {//create new album
$album = new Album();
//set typeCode form logs
$typeCode = 'SYMFONY_DEMO_TOOL_SAVE';
} else {//update album
$album = $entityManager->getRepository(Album::class)->find($id);
//set typeCode form logs
$typeCode = 'SYMFONY_DEMO_TOOL_UPDATE';
if (!$album) {
throw $this->createNotFoundException(
$translator->trans('tool_no_album_found') .' '. $id
);
}

//add message notification
$this->addToFlashMessenger($result['title'], $result['message'], $icon);
//save logs
$this->saveLogs($result['title'], $result['message'], $result['success'], $typeCode, $itemId);
}
}catch (\Exception $ex){
$result['message'] = $ex->getMessage();
$form = $this->createForm(AlbumType::class, $album);
$form->handleRequest($request);
//validate form
if($form->isSubmitted() && $form->isValid()) {
$album = $form->getData();
// tell Doctrine you want to (eventually) save the Album (no queries yet)
$entityManager->persist($album);
// executes the queries
$entityManager->flush();
//get id
$itemId = $album->getAlbId();

$result['message'] = (empty($id)) ? $translator->trans('tool_album_successfully_saved') : $translator->trans('tool_album_successfully_updated');
$result['success'] = true;
//set icon for flash messenger
$icon = 'glyphicon-info-sign';
}else{
$result['message'] = (empty($id)) ? $translator->trans('tool_unable_to_save_album') : $translator->trans('tool_unable_to_update_album');
$result['errors'] = $this->getErrorsFromForm($form);
//set icon for flash messenger
$icon = 'glyphicon-warning-sign';
}

//add message notification
$this->addToFlashMessenger($result['title'], $result['message'], $icon);
//save logs
$this->saveLogs($result['title'], $result['message'], $result['success'], $typeCode, $itemId);
}

return new JsonResponse($result);
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/album.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</p>

{# Create table using melis helper#}
{{ melis_helper('melisdatatable', 'createTable', tableConfig)|raw }}
{{ melis_helper('MelisDataTable', 'createTable', tableConfig)|raw }}

{{ create_modal(modalConfig)|raw }}
{% endblock %}
2 changes: 1 addition & 1 deletion Resources/views/album_plugin.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
{% trans %} tool_album_table_desc {% endtrans %}
</p>
<table class="table table-primary table-bordered table-striped">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Id</th>
Expand Down

0 comments on commit 1355be8

Please sign in to comment.