Group FEWO | Upload Image FEWO | POS

Gruppen für die FEWO
Upload Images bei den Gruppen + vor und nach
Pos Sortierungen bei den Images
Einbau in den Frontend
Silder Bilder zuweisen  pre + page + post

git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3367 f459cee4-fb09-11de-96c3-f9c5f16c3c76
This commit is contained in:
adametz 2018-02-03 20:36:35 +00:00
parent ff986cd437
commit 1293c19bc6
25 changed files with 1249 additions and 37 deletions

View file

@ -10,16 +10,20 @@ namespace AppBundle\Controller;
use AppBundle\AppBundle;
use AppBundle\Entity\FewoBookingRequest;
use AppBundle\Entity\FewoLodging;
use AppBundle\Entity\FewoLodgingGroup;
use AppBundle\Entity\FewoPrice;
use AppBundle\Entity\FewoReservation;
use AppBundle\Entity\FewoSeason;
use AppBundle\Entity\FewoLodgingImage;
use AppBundle\Entity\FewoLodgingGroupImage;
use AppBundle\Form\FewoBookingRequestType;
use AppBundle\Form\FewoLodgingType;
use AppBundle\Form\FewoLodgingTypeGroup;
use AppBundle\Form\FewoPriceType;
use AppBundle\Form\FewoReservationType;
use AppBundle\Form\FewoSeasonType;
use AppBundle\Form\FewoLodgingImageType;
use AppBundle\Form\FewoLodgingGroupImageType;
use AppBundle\Service\FileManager;
use AppBundle\Util;
use Doctrine\Bundle\DoctrineCacheBundle\Tests\Functional\FileSystemCacheTest;
@ -73,12 +77,12 @@ class AdminController extends Controller
*/
public function adminFewoLodgingsAction(Request $request)
{
$fewoLodgingRepo = $this->getEntityManager()->getRepository('AppBundle:FewoLodging');
$lodgings = $fewoLodgingRepo->findAll();
$fewoLodgingGroupRepo = $this->getEntityManager()->getRepository('AppBundle:FewoLodgingGroup');
$lodgingGroups = $fewoLodgingGroupRepo->findAll();
return $this->render('default/admin/lodgings.html.twig', [
'lodgings' => $lodgings,
'lodgingGroups' => $lodgingGroups,
]);
}
@ -88,7 +92,6 @@ class AdminController extends Controller
public function adminFewoNewLodgingAction(Request $request)
{
$lodging = null;
if ($request->getMethod() != 'POST')
{
$lodging = new FewoLodging();
@ -120,6 +123,85 @@ class AdminController extends Controller
]);
}
/**
* @Route("/admin/fewo/lodgings/group/new")
*/
public function adminFewoGroupNewLodgingAction(Request $request)
{
$lodgingGroup = null;
if ($request->getMethod() != 'POST')
{
$lodgingGroup = new FewoLodgingGroup();
}
$form = $this->createForm(FewoLodgingTypeGroup::class, $lodgingGroup, [
]);
// todo if(form == null)...
if ($request->getMethod() == 'POST')
{
$form->handleRequest($request);
$lodgingGroup = $form->getData();
}
if ($request->getMethod() == 'POST' && $form->isValid())
{
$em = $this->getEntityManager();
$em->persist($lodgingGroup);
$em->flush();
return $this->redirect('/admin/fewo/lodgings');
}
return $this->render('default/admin/lodgingsGroupNew.html.twig', [
'form' => $form->createView(),
]);
}
/**
* @Route("/admin/fewo/lodging/group/{lodgingGroupId}", requirements={"lodgingGroupId": "\d+"})
*/
public function adminFewoEditLodgingGroupAction(Request $request, $lodgingGroupId)
{
$em = $this->getEntityManager();
$fewoLodgingGroupRepo = $em->getRepository('AppBundle:FewoLodgingGroup');
$lodgingGroup = null;
$lodgingGroup = $fewoLodgingGroupRepo->find($lodgingGroupId);
$form = $this->createForm(FewoLodgingTypeGroup::class, $lodgingGroup, [
//options
]);
if($request->getMethod() == 'POST')
{
$form->handleRequest($request);
}
if ($request->getMethod() == 'POST' && $form->isValid())
{
$em->flush();
return $this->redirect('/admin/fewo/lodgings');
}
return $this->render('default/admin/lodgingGroupEdit.html.twig', [
'form' => $form->createView(),
'lodgingGroup' => $lodgingGroup,
]);
}
private function getSeasons(FewoLodging $lodging)
{
$seasons = [];
@ -222,6 +304,25 @@ class AdminController extends Controller
return $this->redirect('/admin/fewo/lodgings');
}
/**
* @Route("/admin/fewo/lodging/group/{lodgingGroupId}/delete", requirements={"lodgingGroupId": "\d+"})
*/
public function adminFewoDeleteLodgingGroupAction(Request $request, $lodgingGroupId)
{
$em = $this->getEntityManager();
$fewoLodgingGroupRepo = $em->getRepository('AppBundle:FewoLodgingGroup');
$lodgingGroup = $fewoLodgingGroupRepo->find($lodgingGroupId);
if($lodgingGroup != null)
{
$em->remove($lodgingGroup);
$em->flush();
}
return $this->redirect('/admin/fewo/lodgings');
}
// todo, WEG
/**
@ -770,6 +871,8 @@ class AdminController extends Controller
return $this->redirect('/admin/fewo/seasons');
}
/* ---- FILES LODGING ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- */
/* ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- */
/**
* @Route("/admin/fewo/lodgings/{lodgingId}/images/multi-upload", requirements={"lodgingId": "\d+"})
@ -794,9 +897,11 @@ class AdminController extends Controller
$uploader = $this->container->get('app.image_uploader');
foreach ($form->getData() as $uploadedFile)
{
$image = new FewoLodgingImage();
$image->setFile($uploadedFile);
$image->setLodging($lodging);
$image->setPos(0);
$image->setFileName('');
$image->setDescription('');
$em->persist($image);
@ -865,6 +970,7 @@ class AdminController extends Controller
if ($request->getMethod() != 'POST' && $image == null)
{
$image = new FewoLodgingImage();
$image->setPos(0);
}
$form = $this->createForm(FewoLodgingImageType::class, $image);
@ -919,4 +1025,169 @@ class AdminController extends Controller
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
}
/* ---- FILES GROUP ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- */
/* ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- */
/**
* @Route("/admin/fewo/lodgings/group/{comp}/{lodgingGroupId}/images/multi-upload", requirements={"comp": "pre|post", "lodgingGroupId": "\d+"})
*/
public function adminFewoGroupImageMultiUploadAction(Request $request, $comp, $lodgingGroupId)
{
$em = $this->getEntityManager();
$lodgingGroup = $em->getRepository('AppBundle:FewoLodgingGroup')->find($lodgingGroupId);
if (!$lodgingGroup)
{
throw new HttpException(404, 'Unbekannte lodgingGroup-ID: '. $lodgingGroupId);
}
$form = $this->createForm(FileType::class, null, [
'multiple' => true
]);
if ($request->getMethod() == 'POST')
{
$form->handleRequest($request);
if ($form->isValid())
{
$uploader = $this->container->get('app.image_uploader');
foreach ($form->getData() as $uploadedFile)
{
$image = new FewoLodgingGroupImage();
$image->setFile($uploadedFile);
$image->setLodgingGroup($lodgingGroup);
$image->setComp($comp);
$image->setPos(0);
$image->setFileName('');
$image->setDescription('');
$em->persist($image);
$em->flush();
}
return $this->redirect('/admin/fewo/lodging/group/'. $lodgingGroup->getId());
}
}
return $this->render('default/admin/fewoGroupImageMultiUpload.html.twig', [
'form' => $form->createView(),
'lodgingGroup' => $lodgingGroup,
'comp' => $comp,
]);
}
/**
* @Route("/admin/fewo/lodgings/group/{comp}/{lodgingGroupId}/images/new", requirements={"comp": "pre|post", "lodgingGroupId": "\d+"})
*/
public function adminFewoGroupNewImageAction(Request $request, $comp, $lodgingGroupId)
{
$lodgingGroup = $this->getEntityManager()->getRepository('AppBundle:FewoLodgingGroup')->find($lodgingGroupId);
if (!$lodgingGroup)
{
throw new HttpException(404, 'Unbekannte lodgingGroup-ID: '. $lodgingGroupId);
}
return $this->processGroupImageForm($request, null, $comp, $lodgingGroup);
}
/**
* @Route("/admin/fewo/lodgings/group/{lodgingGroupId}/images/{imageId}", requirements={"lodgingGroupId": "\d+", "imageId": "\d+"})
*/
public function adminFewoGroupEditImageAction(Request $request, $lodgingGroupId, $imageId)
{
/** @var FewoLodgingGroupImage $image */
$image = $this->getEntityManager()->getRepository('AppBundle:FewoLodgingGroupImage')->find($imageId);
if (!$image || $image->getLodgingGroup()->getId() != $lodgingGroupId)
{
throw new HttpException(404, 'Unbekannte FewoLodgingGroupImage-ID oder lodgingGroup-ID passt nicht: '.
$imageId .' / '. $lodgingGroupId);
}
return $this->processGroupImageForm($request, $image);
}
/**
* @param Request $request
* @param FewoLodgingGroupImage $image
* @param FewoLodgingGroup|null $lodgingGroup
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function processGroupImageForm(Request $request, $image, $comp = null, $lodgingGroup = null)
{
$em = $this->getEntityManager();
if ($image == null)
{
$isNew = true;
}
else
{
$isNew = false;
$lodgingGroup = $image->getLodgingGroup();
$imageFileName = $image->getFile();
}
if ($request->getMethod() != 'POST' && $image == null)
{
$image = new FewoLodgingGroupImage();
$image->setComp($comp);
$image->setPos(0);
}
$form = $this->createForm(FewoLodgingGroupImageType::class, $image);
if ($request->getMethod() == 'POST')
{
$form->handleRequest($request);
}
if ($request->getMethod() == 'POST' && $form->isValid())
{
$image = $form->getData();
if ($isNew)
{
$image->setLodgingGroup($lodgingGroup);
$image->setComp($comp);
}
else
{
$image->setFile($imageFileName);
}
$em->persist($image);
$em->flush();
return $this->redirect('/admin/fewo/lodging/group/'. ($lodgingGroup->getId()));
}
return $this->render('default/admin/fewoGroupImage.html.twig', [
'form' => $form->createView(),
'lodgingGroup' => $lodgingGroup,
'is_new' => $isNew,
'image_file_name' => $isNew ? null : $imageFileName,
'image' => $image,
]);
}
/**
* @Route("/admin/fewo/lodgings/group/{lodgingGroupId}/images/{imageId}/delete", requirements={"lodgingGroupId": "\d+", "imageId": "\d+"})
*/
public function adminFewoGroupDeleteImageAction(Request $request, $lodgingGroupId, $imageId)
{
$em = $this->getEntityManager();
$fewoLodgingGroupImageRepo = $em->getRepository('AppBundle:FewoLodgingGroupImage');
$image = $fewoLodgingGroupImageRepo->find($imageId);
if($image != null)
{
$em->remove($image);
$em->flush();
}
return $this->redirect('/admin/fewo/lodging/group/'.$lodgingGroupId);
}
}