Skip to content

Commit

Permalink
Laminas migration asComposer.json update
Browse files Browse the repository at this point in the history
  • Loading branch information
rbbrioso28 committed Aug 17, 2020
2 parents 63b89ef + 98d5195 commit 4e7651a
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 166 deletions.
247 changes: 115 additions & 132 deletions Controller/AlbumController.php
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
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
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
65 changes: 33 additions & 32 deletions composer.json
@@ -1,34 +1,35 @@
{
"name": "melisplatform/melis-platform-framework-symfony-demo-tool-logic",
"type": "melisplatform-module",
"license": "OSL-3.0",
"homepage": "https://github.com/melisplatform/melis-platform-framework-symfony-demo-tool-logic",
"support": {
"email": "contact@melistechnology.com",
"source": "https://github.com/melisplatform/melis-platform-framework-symfony-demo-tool-logic",
"issues": "https://github.com/melisplatform/melis-platform-framework-symfony-demo-tool-logic/issues",
"docs": "https://www.melistechnology.com/melistechnology/resources/download-documentation/id/17#documentation"
},
"authors": [
{
"name": "Melis Technology",
"email": "contact@melistechnology.com",
"homepage": "https://www.melistechnology.com",
"role": "Developer"
}
],
"keywords": [
"cms",
"melis",
"zf2",
"module"
],
"require": {
"melisplatform/melis-platform-framework-symfony-demo-tool": "^3.2"
},
"autoload": {
"psr-4": {
"MelisPlatformFrameworkSymfonyDemoToolLogic\\": ""
}
}
"name": "melisplatform/melis-platform-framework-symfony-demo-tool-logic",
"type": "melisplatform-module",
"license": "OSL-3.0",
"homepage": "https://github.com/melisplatform/melis-platform-framework-symfony-demo-tool-logic",
"support": {
"email": "contact@melistechnology.com",
"source": "https://github.com/melisplatform/melis-platform-framework-symfony-demo-tool-logic",
"issues": "https://github.com/melisplatform/melis-platform-framework-symfony-demo-tool-logic/issues",
"docs": "https://www.melistechnology.com/melistechnology/resources/download-documentation/id/17#documentation"
},
"authors": [
{
"name": "Melis Technology",
"email": "contact@melistechnology.com",
"homepage": "https://www.melistechnology.com",
"role": "Developer"
}
],
"keywords": [
"cms",
"melis",
"zf2",
"module"
],
"require": {
"php": "^7.1.3|^7.2|^7.3",
"melisplatform/melis-platform-framework-symfony-demo-tool": "^4.0"
},
"autoload": {
"psr-4": {
"MelisPlatformFrameworkSymfonyDemoToolLogic\\": ""
}
}
}

0 comments on commit 4e7651a

Please sign in to comment.