<?php
namespace App\Controller;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\CodeEditorType;
use App\Entity\Eshop;
use App\Entity\Gallery;
use App\Entity\GalleryItem;
use App\Entity\Website;
use App\Entity\WebMenu;
use App\Entity\WebMenuItem;
use App\Entity\WebPage;
use App\Entity\WireFrame;
use App\Entity\Module;
use App\Entity\Service;
use App\Entity\User;
use App\Entity\Language;
use App\Entity\CssDesign;
use App\Entity\ServiceExample;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use App\Entity\Contact;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
class WebPagesController extends DefaultController
{
protected KernelInterface $appKernel;
protected ManagerRegistry $doctrine;
protected TranslatorInterface $translator;
protected Environment $twig;
public function __construct(KernelInterface $appKernel,
ManagerRegistry $doctrine,
TranslatorInterface $translator,
Environment $twig)
{
$this->appKernel = $appKernel;
$this->doctrine = $doctrine;
$this->translator = $translator;
$this->twig = $twig;
}
/**
* @Route("/webpages", name="webpages")
*/
public function indexAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
/* we get current user */
if ($session->get('user')) {
$currentUserId = $session->get('user')->getUserId();
} else {
$currentUserId = null;
}
if ($currentUserId) {
$user = $em->getRepository(User::class)->getUser($currentUserId);
} else {
$user = null;
}
/* we load list of modules for connector service */
$service = $em->getRepository(Service::class)->getService(3);
/* we load examples */
$exampleCollection = $em->getRepository(ServiceExample::class)->getServiceExampleListByService(3, 3);
shuffle($exampleCollection);
/* we render data */
return $this->render('webpages.html.twig',
array('headerData' => $this -> getPageHeader($request),
'moduleList' => $service->getModules(),
'exampleCollection' => $exampleCollection,
'service' => $service,
'user' => $user,
)
);
}
/**
* @Route("/webpagesAdmin", name="webpagesAdmin")
*/
public function webpagesAdminAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we check if user is logged in */
if(empty($session->get('user'))) {
return $this->redirectToRoute('login');
}
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current user */
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
/* setting current webpages */
if(!empty($request->query->get('setCurrent'))) {
$website = $em->getRepository(Website::class)->getWebsite($request->query->get('setCurrent'));
$em->getRepository(Website::class)->setCurrentWebsite($currentUserId, $request->query->get('setCurrent'));
$session->set('website', $website);
$this->addFlash('notice', 'The website '.$website->getWebsiteName().' was set as current one.');
return $this->redirectToRoute('webpagesAdmin');
}
/* we get current website */
$currentWeb = $em->getRepository(Website::class)->getCurrentWebsite($currentUserId);
/* we load list of websites for logged user */
$websiteList = $em->getRepository(Website::class)->getWebsiteListByUser($currentUserId);
//we create new web if there is none
if(count($websiteList) == 0) {
$this->webCreate($request);
return $this->redirectToRoute('webpagesAdmin');
}
/*
print('<br>qqw count web: '.count($websiteList));
print('<br>qqw current web: ');
\Doctrine\Common\Util\Debug::dump($currentWeb);
*/
/* if there is no current website set then we set one */
if(empty($currentWeb) && count($websiteList) == 1) {
//print('<br>qqw setting current web ');
$website = $websiteList[0];
$em->getRepository(Website::class)->setCurrentWebsite($currentUserId, $website->getWebsiteId());
$session->set('website', $website);
}
/* we display lists of menus, pages etc only if there is current website */
if(!empty($currentWeb)) {
/* we load list of web pages for the current website */
$webPageList = $dem->getRepository(WebPage::class)->getWebPageListByWebsite($currentWeb->getWebsiteId());
/* we load list of web menus for the current website */
$webMenuList = $dem->getRepository(WebMenu::class)->getWebMenuListByWebsite($currentWeb->getWebsiteId());
/* we load header for the current website */
$webPageHeader = $dem->getRepository(WebPage::class)->getWebPageHeader($currentWeb->getWebsiteId());
// print('<br>webPageHeader: ');
// print_r($webPageHeader);
/* we load footer for the current website */
$webPageFooter = $dem->getRepository(WebPage::class)->getWebPageFooter($currentWeb->getWebsiteId());
} else {
$webPageList = array();
$webMenuList = array();
$webPageHeader = null;
$webPageFooter = null;
}
/* we load list of wireframes */
$wireFrameList = $em->getRepository(WireFrame::class)->getWireFrameList();
/* we prepare array of wireframes */
$wireFrameArray = array();
foreach($wireFrameList as $wireFrame) {
$wireFrameArray[$wireFrame->getWireFrameId()] = $wireFrame;
}
/* we prepare array of count(pages) */
$webPageCountArray = array();
foreach($websiteList as $website) {
$webPageCountArray[$website->getWebsiteId()] = $dem->getRepository(WebPage::class)->getWebPageCountByWebsite($website->getWebsiteId());
}
/*
print('<br>qqw PageCount: ');
\Doctrine\Common\Util\Debug::dump($webPageCountArray);
*/
/* we load list of modules for website service */
$service = $em->getRepository(Service::class)->getService(3);
$moduleCollection = $em->getRepository(Module::class)->getModuleList();
/* we render data */
return $this->render('webpagesAdmin.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'websiteList' => $websiteList,
'webPageList' => $webPageList,
'webPageHeader' => $webPageHeader,
'webPageFooter' => $webPageFooter,
'webMenuList' => $webMenuList,
'wireFrameArray' => $wireFrameArray,
'webPageCountArray' => $webPageCountArray,
'moduleList' => $service->getModules(),
'userModuleList' => $user->getModules(),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'user' => $user
)
);
}
/**
* @Route("/webPagesHeader", name="webPagesHeader")
*/
public function webPagesHeaderAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load users entity manager */
$em = $this->doctrine->getManager();
//$dem = $this->doctrine->getManager('dynamic_em');
/* we get current user */
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
/* we render data */
return $this->render('webpagesHeader.html.php',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
)
);
}
/**
* @Route("/webnew", name="webNew")
*/
public function webNewAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$em = $this->doctrine->getManager();
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we build form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('websiteName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('webpages.name'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
if ($form->isValid()) {
// perform some action, such as save the object to the database
/* we load users entity manager */
//$dem = $this->doctrine->getManager('dynamic_em');
$website = new Website;
$website->setWebsiteName($request->request->get('form')['websiteName']);
$website->setUserId($session->get('user')->getUserId());
/* we persist and save */
$em->persist($website);
$em->flush();
$this->addFlash('notice', 'New website was created.');
return $this->redirectToRoute('webpagesAdmin');
}
}
/* we render data */
return $this->render('webNew.html.twig',
array( 'form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'user' => $user,
)
);
}
/**
* @Route("/web/{webId}", name="web")
*/
public function webAction(Request $request, $webId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
//print('<br>QQW web ID: '.$webId);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current web */
$web = $em->getRepository(Website::class)->getWebsite($webId);
try {
//print('<br>Twig - adds php functions ...');
$this->twig->addFunction(new \Twig\TwigFunction('deg2rad', 'deg2rad'));
$this->twig->addFunction(new \Twig\TwigFunction('sin', 'sin'));
$this->twig->addFunction(new \Twig\TwigFunction('imagecreatefromstring', 'imagecreatefromstring'));
$this->twig->addFunction(new \Twig\TwigFunction('file_get_contents', 'file_get_contents'));
$this->twig->addFunction(new \Twig\TwigFunction('ImageSX', 'ImageSX'));
$this->twig->addFunction(new \Twig\TwigFunction('ImageSY', 'ImageSY'));
} catch(Exception $e) {
$this->addFlash('error', "Twig functions init error");
}
/* we load header for the current website */
$webPageHeader = $dem->getRepository(WebPage::class)->getWebPageHeader($webId);
/* we load footer for the current website */
$webPageFooter = $dem->getRepository(WebPage::class)->getWebPageFooter($webId);
$webPageLeftColumn = $dem->getRepository(WebPage::class)->getWebPageLeftColumn($webId);
$webPageRightColumn = $dem->getRepository(WebPage::class)->getWebPageRightColumn($webId);
/* we load main menu for the current website */
$webMenuMain = $dem->getRepository(WebMenu::class)->getMainMenu($webId);
if(!empty($webMenuMain)) {
$webMenuItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuMain->getWebMenuId());
} else {
$webMenuItemList = array();
}
/* we load top menu for the current website */
$webMenuTop = $dem->getRepository(WebMenu::class)->getTopMenu($webId);
if(!empty($webMenuTop)) {
$webMenuTopItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuTop->getWebMenuId());
} else {
$webMenuTopItemList = array();
}
/* we load home page for the current website */
$homePage = $dem->getRepository(WebPage::class)->getHomePage($webId);
$currentLang = $session->get('lang');
$homePageContent = '';
$webPageHeaderContent = '';
$webPageFooterContent = '';
foreach($web->getLanguages() as $lang) {
if ($lang->getLangKey() == $currentLang->getLangKey()) {
if(!empty($homePage)) {
$homePage->setLocale($lang->getLangKey());
$dem->refresh($homePage);
$homePageContent = $homePage->getWebPageContent();
}
if(!empty($webPageHeader)) {
$webPageHeader->setLocale($lang->getLangKey());
$dem->refresh($webPageHeader);
$webPageHeaderContent = $webPageHeader->getWebPageContent();
}
if(!empty($webPageFooter)) {
$webPageFooter->setLocale($lang->getLangKey());
$dem->refresh($webPageFooter);
$webPageFooterContent = $webPageFooter->getWebPageContent();
}
}
}
//print('<br>webPageHeaderContent in '.$currentLang->getLangKey().': '.$webPageHeaderContent);
// print('<br>homePageContent in '.$currentLang->getLangKey().': '.$homePageContent);
// print('<br>webPageFooterContent in '.$currentLang->getLangKey().': '.$webPageFooterContent);
$seoData = array();
$seoData['seoTitle'] = '';
$seoData['seoDescription'] = '';
/* we parse the page content for placeholders */
if(!empty($homePage)) {
$homePageContent = $this->parseContent($request, $homePageContent);
$homePage->setWebPageContent($homePageContent);
$seoData['seoTitle'] = $homePage->getSeoTitle();
$seoData['seoDescription'] = $homePage->getSeoDescription();
}
if(!empty($webPageHeader)) {
$webPageHeader->setWebPageContent($webPageHeaderContent);
}
if(!empty($webPageFooter)) {
$webPageFooter->setWebPageContent($webPageFooterContent);
}
// print('<hr>qqw homePage Content 2: '.$homePageContent.'<hr>');
// \Doctrine\Common\Util\Debug::dump($homePage);
/* we check if website exists */
if($web === null) {
$this->addFlash('error', 'Web with tis ID does not exists.');
return $this->redirectToRoute('webHome');
}
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($web->getWireFrameId());
// print('<hr>qqw wireframe: ');
// \Doctrine\Common\Util\Debug::dump($wireFrame);
$webMenuVertical = null;
$webMenuVerticalItemList = null;
/* we load left column - vertical menu for the current website */
if($wireFrame->getWireFrameName() == 'Website Classic') {
$webMenuVertical = $dem->getRepository(WebMenu::class)->getVerticalMenu($webId);
if(!empty($webMenuVertical)) {
$webMenuVerticalItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuVertical->getWebMenuId());
}
}
/*
print('<hr>qqw webMenuVertical: ');
\Doctrine\Common\Util\Debug::dump($webMenuVertical);
print('<hr>qqw webMenuVerticalItemList: ');
\Doctrine\Common\Util\Debug::dump($webMenuVerticalItemList);
*/
//print('<br>menu : ');
//\Doctrine\Common\Util\Debug::dump($webMenuTop);
//foreach ($webMenuTopItemList as $menuItem) {
//$menuItem->setLocale($session->get('lang'));
//$dem->refresh($menuItem);
//print('<br>menu item: '.$menuItem->getWebMenuItemName());
//}
/* we render data */
return $this->render('web.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'seoData' => $seoData,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'web' => $web,
'wireFrame' => $wireFrame,
'webPageHeader' => $webPageHeader,
'webPageFooter' => $webPageFooter,
'webPageLeftColumn' => $webPageLeftColumn,
'webPageRightColumn' => $webPageRightColumn,
'webMenuMain' => $webMenuMain,
'webMenuTop' => $webMenuTop,
'webMenuItemList' => $webMenuItemList,
'webMenuTopItemList' => $webMenuTopItemList,
'webMenuVertical' => $webMenuVertical,
'webMenuVerticalItemList' => $webMenuVerticalItemList,
'homePage' => $homePage,
)
);
}
/**
* @Route("/web/{webId}/page/{pageId}", name="page")
*/
public function pageAction(Request $request, $webId, $pageId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
//print('<br>QQW page ID: '.$pageId);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current web */
$web = $em->getRepository(Website::class)->getWebsite($webId);
/* we load header for the current website */
$webPageHeader = $dem->getRepository(WebPage::class)->getWebPageHeader($webId);
/* we load footer for the current website */
$webPageFooter = $dem->getRepository(WebPage::class)->getWebPageFooter($webId);
$webPageLeftColumn = $dem->getRepository(WebPage::class)->getWebPageLeftColumn($webId);
$webPageRightColumn = $dem->getRepository(WebPage::class)->getWebPageRightColumn($webId);
/* we load header for the current website */
$webMenuMain = $dem->getRepository(WebMenu::class)->getMainMenu($webId);
if(!empty($webMenuMain)) {
$webMenuItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuMain->getWebMenuId());
} else {
$webMenuItemList = array();
}
/* we load top menu for the current website */
$webMenuTop = $dem->getRepository(WebMenu::class)->getTopMenu($webId);
if(!empty($webMenuTop)) {
$webMenuTopItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuTop->getWebMenuId());
} else {
$webMenuTopItemList = array();
}
/* we load page for the current webpage */
$page = $dem->getRepository(WebPage::class)->getWebPage($pageId);
$currentLang = $session->get('lang');
/*
print('<br>qqw page id: '.$pageId);
\Doctrine\Common\Util\Debug::dump($page);
*/
$pageContent = '';
$webPageHeaderContent = '';
$webPageFooterContent = '';
foreach($web->getLanguages() as $lang) {
if ($lang->getLangKey() == $currentLang->getLangKey()) {
if(!empty($page)) {
$page->setLocale($lang->getLangKey());
$dem->refresh($page);
$pageContent = $page->getWebPageContent();
}
if(!empty($webPageHeader)) {
$webPageHeader->setLocale($lang->getLangKey());
$dem->refresh($webPageHeader);
$webPageHeaderContent = $webPageHeader->getWebPageContent();
}
if(!empty($webPageFooter)) {
$webPageFooter->setLocale($lang->getLangKey());
$dem->refresh($webPageFooter);
$webPageFooterContent = $webPageFooter->getWebPageContent();
}
}
}
/* we parse the page content for placeholders */
$pageContent = $this->parseContent($request, $pageContent);
$page->setWebPageContent($pageContent);
//print('<br>page content2: '.$pageContent);
if(!empty($webPageHeader)) {
$webPageHeader->setWebPageContent($webPageHeaderContent);
}
if(!empty($webPageFooter)) {
$webPageFooter->setWebPageContent($webPageFooterContent);
}
/* we check if website exists */
if($web === null) {
$this->addFlash('error', 'Web with tis ID does not exists.');
return $this->redirectToRoute('webHome');
}
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($web->getWireFrameId());
$webMenuVertical = null;
$webMenuVerticalItemList = null;
/* we load left column - vertical menu for the current website */
if($wireFrame->getWireFrameName() == 'Website Classic') {
$webMenuVertical = $dem->getRepository(WebMenu::class)->getVerticalMenu($webId);
if(!empty($webMenuVertical)) {
$webMenuVerticalItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuVertical->getWebMenuId());
}
}
/*
print('<br>qqw webMenuVertical: ');
\Doctrine\Common\Util\Debug::dump($webMenuVertical);
*/
/* we render data */
return $this->render('page.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'web' => $web,
'wireFrame' => $wireFrame,
'webPageHeader' => $webPageHeader,
'webPageFooter' => $webPageFooter,
'webPageLeftColumn' => $webPageLeftColumn,
'webPageRightColumn' => $webPageRightColumn,
'webMenuMain' => $webMenuMain,
'webMenuItemList' => $webMenuItemList,
'webMenuTop' => $webMenuTop,
'webMenuTopItemList' => $webMenuTopItemList,
'webMenuVertical' => $webMenuVertical,
'webMenuVerticalItemList' => $webMenuVerticalItemList,
'page' => $page,
)
);
}
/**
* @Route("/web/{webId}/galleries", name="webGalleries")
*/
public function webGalleriesAction(Request $request, $webId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
// print('<br>QQW web ID: '.$webId);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current web */
$web = $em->getRepository(Website::class)->getWebsite($webId);
/* we load header for the current website */
$webPageHeader = $dem->getRepository(WebPage::class)->getWebPageHeader($webId);
if(!empty($webPageHeader)) {
$webPageHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($webPageHeader);
}
/* we load footer for the current website */
$webPageFooter = $dem->getRepository(WebPage::class)->getWebPageFooter($webId);
if(!empty($webPageFooter)) {
$webPageFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($webPageFooter);
}
/* we load menu for the current website */
$webMenuMain = $dem->getRepository(WebMenu::class)->getMainMenu($webId);
if(!empty($webMenuMain)) {
$webMenuItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuMain->getWebMenuId());
} else {
$webMenuItemList = array();
}
/* we load top menu for the current website */
$webMenuTop = $dem->getRepository(WebMenu::class)->getTopMenu($webId);
if(!empty($webMenuTop)) {
$webMenuTopItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuTop->getWebMenuId());
} else {
$webMenuTopItemList = array();
}
/*
print('<br>qqw page id: '.$pageId);
\Doctrine\Common\Util\Debug::dump($page);
*/
/* we check if website exists */
if($web === null) {
$this->addFlash('error', 'Web with tis ID does not exists.');
return $this->redirectToRoute('webHome');
}
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($web->getWireFrameId());
$webMenuVertical = null;
$webMenuVerticalItemList = null;
/* we load left column - vertical menu for the current website */
if($wireFrame->getWireFrameName() == 'Website Classic') {
$webMenuVertical = $dem->getRepository(WebMenu::class)->getVerticalMenu($webId);
if(!empty($webMenuVertical)) {
$webMenuVerticalItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuVertical->getWebMenuId());
}
}
/* we get list of galleries */
$galleryList = $dem->getRepository(Gallery::class)->getGalleryListByUser($web->getUserId());
//print('<br>qqw web: ');
//\Doctrine\Common\Util\Debug::dump($web);
/* we render data */
return $this->render('galleries.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
//'mainMenu' => $this -> adminMainMenu($request),
'web' => $web,
'wireFrame' => $wireFrame,
'webPageHeader' => $webPageHeader,
'webPageFooter' => $webPageFooter,
'webMenuMain' => $webMenuMain,
'webMenuItemList' => $webMenuItemList,
'webMenuTop' => $webMenuTop,
'webMenuTopItemList' => $webMenuTopItemList,
'galleryList' => $galleryList,
'webMenuVertical' => $webMenuVertical,
'webMenuVerticalItemList' => $webMenuVerticalItemList,
)
);
}
/**
* @Route("/web/{webId}/gallery/{galleryId}", name="webGallery")
*/
public function webGalleryAction(Request $request, $webId, $galleryId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current web */
$web = $em->getRepository(Website::class)->getWebsite($webId);
/* we get user */
$userId = $web->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we load header for the current website */
$webPageHeader = $dem->getRepository(WebPage::class)->getWebPageHeader($webId);
if(!empty($webPageHeader)) {
$webPageHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($webPageHeader);
}
/* we load footer for the current website */
$webPageFooter = $dem->getRepository(WebPage::class)->getWebPageFooter($webId);
if(!empty($webPageFooter)) {
$webPageFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($webPageFooter);
}
/* we load header for the current website */
$webMenuMain = $dem->getRepository(WebMenu::class)->getMainMenu($webId);
if(!empty($webMenuMain)) {
$webMenuItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuMain->getWebMenuId());
} else {
$webMenuItemList = array();
}
/* we load top menu for the current website */
$webMenuTop = $dem->getRepository(WebMenu::class)->getTopMenu($webId);
if(!empty($webMenuTop)) {
$webMenuTopItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuTop->getWebMenuId());
} else {
$webMenuTopItemList = array();
}
if(!empty($request->get('backUrl'))) {
$backUrl = $request->get('backUrl');
} else {
$backUrl = null;
}
/*
print('<br>qqw page id: '.$pageId);
\Doctrine\Common\Util\Debug::dump($page);
*/
/* we check if website exists */
if($web === null) {
$this->addFlash('error', 'Web with tis ID does not exists.');
return $this->redirectToRoute('webHome');
}
$userDirs = $this->getUserFolderPaths($request);
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($web->getWireFrameId());
/* we get list of gallery */
$gallery = $dem->getRepository(Gallery::class)->getGallery($galleryId);
$galleryItemList = $dem->getRepository(GalleryItem::class)->getGalleryItemList($galleryId);
//print('<br>qqw gallery: ');
//\Doctrine\Common\Util\Debug::dump($galleryItemList);
/* we render data */
return $this->render('webGallery.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'web' => $web,
'user' => $user,
'userDirs' => $userDirs,
'wireFrame' => $wireFrame,
'webPageHeader' => $webPageHeader,
'webPageFooter' => $webPageFooter,
'webMenuMain' => $webMenuMain,
'webMenuItemList' => $webMenuItemList,
'webMenuTop' => $webMenuTop,
'webMenuTopItemList' => $webMenuTopItemList,
'gallery' => $gallery,
'galleryItemList' => $galleryItemList,
'backUrl' => $backUrl,
)
);
}
/**
* @Route("/webConfig", name="webConfig")
*/
public function webConfigAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load master entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
/* we get current website */
$web = $em->getRepository(Website::class)->getCurrentWebsite($currentUserId);
/* we get css designs */
$cssDesignCollection = $dem->getRepository(CssDesign::class)->getCssDesignList();
if(count($cssDesignCollection) == 0) {
print('we create new css file');
$cssDesign = new CssDesign;
$cssDesign->setCssDesignName($user->getUserName());
$cssDesign->setCssDesignFile($user->getUserName().".css");
/* we persist and save */
$dem->persist($cssDesign);
$dem->flush();
$this->addFlash('notice', $this->translator->trans('module.cssDesigner_created'));
return $this->redirectToRoute('webConfig');
}
/* we get wireframes */
$wireFrameCollection = $em->getRepository(WireFrame::class)->getWireFrameListByService(3);
/* we get languages */
$langCollection = $em->getRepository(Language::class)->getLanguageList();
/* we build form */
$formBuilder = $this->createFormBuilder($web);
$formBuilder->add('websiteName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('webpages.name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $web->getWebsiteName()),
'label_attr' => array('class' => 'form_field_label')
));
/* we add css designs list */
$cssDesigns = array();
$selectedCss = '';
foreach($cssDesignCollection as $cssDesign)
{
$cssDesignId = $cssDesign->getCssDesignId();
$cssDesigns[$cssDesign->getCssDesignName()] = $cssDesignId;
/* we look for selected css design of the e-shop */
if($cssDesign->getCssDesignFile() == $web->getWebsiteCss()) {
$selectedCss = $cssDesign->getCssDesignId();
}
}
$formBuilder->add('cssDesignId', ChoiceType::class, array(
'choices' => $cssDesigns,
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedCss
));
/* we add wireframe list */
$wireFrames = array();
$selectedWireFrame = '';
foreach($wireFrameCollection as $wireFrame)
{
$wireFrameId = $wireFrame->getWireFrameId();
$wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
/* we look for selected wireframe of the website */
if($wireFrame->getWireFrameId() == $web->getWireFrameId()) {
$selectedWireFrame = $wireFrame->getWireFrameId();
}
}
$formBuilder->add('wireFrameId', ChoiceType::class, array(
'choices' => $wireFrames,
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedWireFrame,
));
/* we add language list */
$languages = array();
foreach($langCollection as $lang)
{
$langId = $lang->getLangId();
$languages[$lang->getLangName()] = $lang->getLangId();
}
$selectedLanguages = array();
foreach($web->getLanguages() as $lang) {
$selectedLanguages[] = $lang->getLangId();
}
$formBuilder->add('languages', ChoiceType::class, array(
'choices' => $languages,
'label' => $this->translator->trans('system.languages'),
'required' => false,
'mapped' => false,
'multiple' => true,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedLanguages
));
$formBuilder->add('preferredLanguageId', ChoiceType::class, array(
'choices' => $languages,
'label' => $this->translator->trans('system.language_preferred'),
'required' => true,
'mapped' => false,
'multiple' => false,
'placeholder' => false,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $web->getPreferredLanguageId()
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.send'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
if ($form->isValid()) {
$formData = $form->getData();
/* we load eshop data from form into object */
$web->setWebsiteName($formData->getWebsiteName());
/* we remove old language associations */
foreach($web->getLanguages() as $lang) {
$web->removeLanguage($lang);
}
/* we load web languages */
if(!empty($form['languages']->getData())) {
foreach($form['languages']->getData() as $langId) {
$addLang = $em->getRepository(Language::class)->getLanguage($langId);
$web->addLanguage($addLang);
}
}
/* we set default language */
$web->setPreferredLanguageId($form['preferredLanguageId']->getData());
/* we set css design */
$cssDesign = $dem->getRepository(CssDesign::class)->getCssDesign($form['cssDesignId']->getData());
$web->setWebsiteCss($cssDesign->getCssDesignFile());
/* wireframe setting */
$web->setWireFrameId($form['wireFrameId']->getData());
/*
print('<br>qqw user exists: ');
\Doctrine\Common\Util\Debug::dump($user);
*/
/* we persist and save user */
$em->persist($web);
$em->flush();
$this->addFlash('notice', 'Website was updated.');
return $this->redirectToRoute('webConfig');
}
}
/* we render data */
return $this->render('webConfig.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'user' => $user,
)
);
}
/**
* @Route("/webPageNew", name="webPageNew")
*/
public function webPageNewAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load master entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
/* we get current website */
$web = $em->getRepository(Website::class)->getCurrentWebsite($currentUserId);
/* we build login form */
$webPage = new WebPage;
$formBuilder = $this->createFormBuilder($webPage);
$formBuilder->add('webPageName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('webpages.page_title'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
/* we add flag if it is eshop page */
if(!empty($request->query->get('eshopPage'))) {
$formBuilder->add('eshopPage', HiddenType::class, array(
'data' => 1,
'mapped' => false
));
} else {
$formBuilder->add('eshopPage', HiddenType::class, array(
'data' => 0,
'mapped' => false
));
}
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
if ($form->isValid()) {
$formData = $form->getData();
$webPage->setWebPageName($formData->getWebPageName());
if(!empty($form['eshopPage']->getData()) && ($form['eshopPage']->getData()==1)) {
/* we get current eshop */
$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
$webPage->setEshopId($eshop->getEshopId());
} else {
$webPage->setWebsiteId($web->getWebsiteId());
}
//$webPage->setUserId($session->get('user')->getUserId());
$webPage->setDateInserted(new \DateTime("now"));
$webPage->setDatePublished(new \DateTime("now"));
/* we persist and save */
$dem->persist($webPage);
$dem->flush();
$this->addFlash('notice', 'New web page was created.');
return $this->redirectToRoute('webPageEdit', array('webPageId' => $webPage->getWebPageId()));
}
}
/* we render data */
return $this->render('webPageNew.html.twig',
array( 'form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'user' => $user,
)
);
}
public function webCreate(Request $request, $webName = "Test web")
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
//print('qqw creating web...');
$web = new Website;
$web->setWebsiteName($webName);
$web->setUserId($session->get('user')->getUserId());
// wireframe setting
$web->setWireFrameId(1);
// we add language
$addLang = $em->getRepository(Language::class)->getLanguage(1);
$web->addLanguage($addLang);
// we set this web as current one
$em->getRepository(Website::class)->unsetCurrentWebsite($session->get('user')->getUserId());
$em->getRepository(Website::class)->setCurrentWebsite($session->get('user')->getUserId(), $web->getWebsiteId());
// we persist and save
$em->persist($web);
$em->flush();
// we insert data fixtures
$this->webDataFixtures($request);
$this->addFlash('notice', $this->translator->trans('web.created'));
}
/**
* we insert default data into e-shop from basicdemo account
*/
public function webDataFixtures(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$demo_em = $this->doctrine->getManager('eshop_demo_em');
print('qqw web data fixtures...');
$userId = $session->get('user')->getUserId();
/* we get current web */
$currentWeb = $em->getRepository(Website::class)->getCurrentWebsite($userId);
/* we get basicdemo web */
$demoUserId = 97; //demobasic user id
$demoweb = $em->getRepository(Website::class)->getCurrentWebsite($demoUserId);
if(empty($demoweb)) {
$this->addFlash('error', 'Demo base web - No fixture data.');
return;
}
print('<br>qqw current web id: '.$demoweb->getWebsiteId());
$demoPagesCollection = $demo_em->getRepository(WebPage::class)->getWebPageList();
//$cat->setLocale($session->get('lang')->getLangKey());
foreach($demoPagesCollection as $demoPage)
{
$pageId = $demoPage->getPageId();
print('<br>qqw demo page: '.$pageId);
\Doctrine\Common\Util\Debug::dump($demoPage);
//we update or create web page
$page = null;
if(empty($page)) {
$page = new WebPage;
}
$page->setWebPageName($demoPage->getWebPageName());
$page->setWebPageContent($demoPage->getWebPageContent());
$page->setWebsiteId($demoPage->getWebsiteId());
$page->setWebPageType($demoPage->getWebPageType());
$page->setEshopId($demoPage->getEshopId());
$page->setLocale($demoPage->getLocale());
$page->setWebPageDescription($demoPage->getWebPageDescription());
$page->setPriority($demoPage->getPriority());
$page->setImageFile($demoPage->getImageFile());
$page->setSeoTitle($demoPage->getSeoTitle());
$page->setSeoDescription($demoPage->getSeoDescription());
$page->setAuctionHallId($demoPage->getAuctionHallId());
// we persist and save page
$dem->persist($page);
$dem->flush();
}
}
/**
* @Route("/webPageEdit/{webPageId}", name="webPageEdit")
*/
public function webPageEditAction(Request $request, $webPageId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
// we check if any user is logged in
if(!$this->isLoggedUser($request)) {
return $this->redirectToRoute('login');
}
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
/* we get current website */
$web = $em->getRepository(Website::class)->getCurrentWebsite($currentUserId);
/* we get web page */
$webPage = $dem->getRepository(WebPage::class)->getWebPage($webPageId);
//print('<br>qqw web page: '.$webPageId);
//\Doctrine\Common\Util\Debug::dump($webPage);
$webPage->setLocale($session->get('lang')->getLangKey());
$dem->refresh($webPage);
/*
print('<br>qqw web page: '.$webPageId);
\Doctrine\Common\Util\Debug::dump($webPage);
*/
/* we build form */
$formBuilder = $this->createFormBuilder($webPage);
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
$formBuilder->add('webPageName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('webpages.page_title'),
'attr' => array('class' => 'text_form', 'size' => 55, 'value' => $webPage->getWebPageName()),
'label_attr' => array('class' => 'form_field_label')
));
/* for eshop - we display page content in various languages */
if(!empty($webPage->getEshopId()) && ($webPage->getEshopId() > 0)) {
//print("<br>qqw eshop Id: ".$webPage->getEshopId());
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($webPage->getEshopId());
// webPageContent
foreach($eshop->getLanguages() as $lang) {
if ($lang->getLangKey() == 'en') {
$key = 'en_us';
} elseif ($lang->getLangKey() == 'de') {
$key = 'de_de';
} elseif ($lang->getLangKey() == 'es') {
$key = 'es_es';
} elseif ($lang->getLangKey() == 'cs') {
$key = 'cs_cs';
} else {
$key = 'en_us';
}
//$webPage->setLocale('cs');
$webPage->setLocale($lang->getLangKey());
$dem->refresh($webPage);
$fieldLabel = $this->translator->trans('webpages.page_content').' ['.$lang->getLangKey().']';
$fieldValue = $webPage->getWebPageContent();
//print('<br>eshopPage locale: '.$lang->getLangKey());
$formBuilder->add('webPageContent_'.$lang->getLangKey(), TextareaType::class, array(
'required' => false,
'label' => $fieldLabel,
'attr' => array('class' => 'medium_textarea', 'size' => 35, 'value' => $fieldValue),
'label_attr' => array('class' => 'form_field_label'),
'data' => $fieldValue,
'mapped' => false
));
}
// SEO Content
// foreach($eshop->getLanguages() as $lang) {
//
// $webPage->setLocale($lang->getLangKey());
// $dem->refresh($webPage);
//
// $fieldLabel = $this->translator->trans('webpages.seo_title').' ['.$lang->getLangKey().']';
// $fieldValue = $webPage->getSeoTitle();
//
// $formBuilder->add('seoTitle_'.$lang->getLangKey(), TextType::class, array(
// 'required' => false,
// 'label' => $fieldLabel,
// 'attr' => array('class' => 'text_form', 'size' => 55, 'value' => $fieldValue),
// 'label_attr' => array('class' => 'form_field_label')
// ));
//
// $fieldLabel = $this->translator->trans('webpages.seo_description').' ['.$lang->getLangKey().']';
// $fieldValue = $webPage->getSeoDescription();
//
// $formBuilder->add('seoDescription_'.$lang->getLangKey(), TextareaType::class, array(
// 'required' => false,
// 'label' => $fieldLabel,
// 'attr' => array('class' => 'medium_textarea', 'cols' => 55, 'rows' => 4, 'value' => $fieldValue),
// 'label_attr' => array('class' => 'form_field_label'),
// 'data' => $fieldValue,
// ));
// }
// SEO Content
foreach($eshop->getLanguages() as $lang) {
$webPage->setLocale($lang->getLangKey());
$dem->refresh($webPage);
$fieldLabel = $this->translator->trans('webpages.seo_title').' ['.$lang->getLangKey().']';
$fieldValue = $webPage->getSeoTitle();
$formBuilder->add('seoTitle_'.$lang->getLangKey(), TextType::class, array(
'required' => false,
'label' => $fieldLabel,
'attr' => array('class' => 'text_form', 'size' => 55, 'value' => $fieldValue),
'label_attr' => array('class' => 'form_field_label'),
'mapped' => false
));
//print('<br>eshopPage locale 2: '.$lang->getLangKey());
$fieldLabel = $this->translator->trans('webpages.seo_description').' ['.$lang->getLangKey().']';
$fieldValue = $webPage->getSeoDescription();
$formBuilder->add('seoDescription_'.$lang->getLangKey(), TextareaType::class, array(
'required' => false,
'label' => $fieldLabel,
'attr' => array('class' => 'text_form', 'cols' => 55, 'rows' => 4, 'value' => $fieldValue),
'label_attr' => array('class' => 'form_field_label'),
'data' => $fieldValue,
'mapped' => false
));
}
} else {
/* website page */
/*
$formBuilder->add('webPageContent', CKEditorType::class, array(
'required' => false,
'label' => $this->translator->trans('webpages.page_content'),
'attr' => array('class' => 'textarea_form', 'cols' => 101, 'rows' => 11),
'label_attr' => array('class' => 'form_textarea_label2'),
'data' => $webPage->getWebPageContent(),
));
*/
// webPageContent
foreach($web->getLanguages() as $lang) {
$fieldLabel = $this->translator->trans('webpages.page_content').' ['.$lang->getLangKey().']';
$webPage->setLocale($lang->getLangKey());
$dem->refresh($webPage);
$fieldValue = $webPage->getWebPageContent();
//CKEditorType::class
//TextareaType
//print("<br>qqw webpages.page_content: ".$fieldValue);
//@todo - CKEditorType does not render
//CKEditorType::class
$formBuilder->add('webPageContent_'.$lang->getLangKey(), CodeEditorType::class, array(
'required' => false,
'label' => $fieldLabel,
'attr' => array('class' => 'medium_textarea', 'size' => 35, 'value' => $fieldValue),
'label_attr' => array('class' => 'form_field_label'),
'data' => $fieldValue,
//'config' => array('toolbar' => 'full'),
'mapped' => false
));
}
// SEO Content
foreach($web->getLanguages() as $lang) {
$webPage->setLocale($lang->getLangKey());
$dem->refresh($webPage);
$fieldLabel = $this->translator->trans('webpages.seo_title').' ['.$lang->getLangKey().']';
$fieldValue = $webPage->getSeoTitle();
$formBuilder->add('seoTitle_'.$lang->getLangKey(), TextType::class, array(
'required' => false,
'label' => $fieldLabel,
'attr' => array('class' => 'text_form', 'size' => 55, 'value' => $fieldValue),
'label_attr' => array('class' => 'form_field_label'),
'mapped' => false
));
$fieldLabel = $this->translator->trans('webpages.seo_description').' ['.$lang->getLangKey().']';
$fieldValue = $webPage->getSeoDescription();
$formBuilder->add('seoDescription_'.$lang->getLangKey(), TextareaType::class, array(
'required' => false,
'label' => $fieldLabel,
'attr' => array('class' => 'text_form', 'cols' => 55, 'rows' => 4, 'value' => $fieldValue),
'label_attr' => array('class' => 'form_field_label'),
'data' => $fieldValue,
'mapped' => false
));
}
}
$imageLabel = $this->translator->trans('image.main');
if(!empty($webPage->getImageFile())) {
$imageLabel .= " [ ".$webPage->getImageFile()." ]";
}
$formBuilder->add('imageFile', FileType::class, array(
'required' => false,
'label' => $imageLabel,
'attr' => array('class' => 'text_form_file', 'size' => 22, 'value' => 'vvx'),
'label_attr' => array('class' => 'form_field_label2'),
'mapped' => false
));
$formBuilder->add('webPageDescription', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('webpages.page_description'),
'attr' => array('class' => 'textarea_form', 'cols' => 55, 'rows' => 4, 'value' => $webPage->getWebPageDescription()),
'label_attr' => array('class' => 'form_textarea_label'),
'data' => $webPage->getWebPageDescription(),
));
if(!empty($webPage->getDatePublished())) {
$sDatePublished = $webPage->getDatePublished()->format("Y-m-d H:i:s");
} else {
$sDatePublished = '';
}
$formBuilder->add('datePublished', DateTimeType::class, array(
'required' => false,
'label' => $this->translator->trans('webpages.date_published'),
'attr' => array('class' => 'text_form', 'size' => 22, 'value' => $sDatePublished),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('priority', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.priority'),
'attr' => array('class' => 'text_form', 'size' => 5, 'value' => $webPage->getPriority()),
'label_attr' => array('class' => 'form_field_label')
));
/* we add page types list */
$webPageTypes = array();
$selectedType = '';
foreach($webPage::PAGETYPE as $key=>$webPageType)
{
$webPageTypes[$this->translator->trans($key)] = $webPageType;
/* we look for selected web page type */
if($webPageType == $webPage->getWebPageType()) {
$selectedType = $webPageType;
}
}
// print('<br>webPageType selected: '.$selectedType);
// print('<br>getWebPageType: '.$webPage->getWebPageType());
$formBuilder->add('webPageType', ChoiceType::class, array(
'choices' => $webPageTypes,
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'data' => $selectedType
));
$formBuilder->add('save2', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
//print("<br>qqw POST");
//if ($form->isValid()) {
//print("<br>qqw POST 2");
$formData = $form->getData();
/* we load web page data from register form into object */
$webPage->setWebPageName($formData->getWebPageName());
/* for eshop - we save page content in various languages */
if(!empty($webPage->getEshopId()) && ($webPage->getEshopId() > 0)) {
//print("<br>qqw post eshop page ");
/* we get e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($webPage->getEshopId());
foreach($eshop->getLanguages() as $lang) {
if(!empty($form['webPageContent_' . $lang->getLangKey()])) {
$webPage->setWebPageContent($form['webPageContent_' . $lang->getLangKey()]->getData());
}
if(!empty($form['seoTitle_' . $lang->getLangKey()]->getData())) {
$webPage->setSeoTitle($form['seoTitle_' . $lang->getLangKey()]->getData());
}
if(!empty($form['seoDescription_' . $lang->getLangKey()]->getData())) {
$webPage->setSeoDescription($form['seoDescription_' . $lang->getLangKey()]->getData());
}
$webPage->setLocale($lang->getLangKey());
//$webPage->setTranslatableLocale($key);
//print('<br>persist locale: '.$lang->getLangKey());
//print('<br>page content: '.$form['webPageContent_' . $lang->getLangKey()]->getData());
$dem->persist($webPage);
$dem->flush();
}
// foreach($eshop->getLanguages() as $lang) {
// $webPage->setLocale($lang->getLangKey());
//
// if(!empty($form['webPageContent_'.$lang->getLangKey()])) {
// $webPage->setWebPageContent($form['webPageContent_'.$lang->getLangKey()]->getData());
// }
// if(!empty($form['seoTitle_'.$lang->getLangKey()])) {
// $webPage->setSeoTitle($form['seoTitle_'.$lang->getLangKey()]->getData());
// }
// if(!empty($form['seoDescription_'.$lang->getLangKey()])) {
// $webPage->setSeoDescription($form['seoDescription_'.$lang->getLangKey()]->getData());
// }
//
// $dem->persist($webPage);
// $dem->flush();
// }
} else {
//we setup web page page content
//print("<br>qqw post webpages page");
$webPage->setPriority($formData->getPriority());
foreach($web->getLanguages() as $lang) {
$webPage->setWebPageContent($form['webPageContent_'.$lang->getLangKey()]->getData());
$webPage->setSeoTitle($form['seoTitle_'.$lang->getLangKey()]->getData());
$webPage->setSeoDescription($form['seoDescription_'.$lang->getLangKey()]->getData());
$webPage->setLocale($lang->getLangKey());
//$webPage->setTranslatableLocale($key);
print('<br>persist locale: '.$key);
$dem->persist($webPage);
$dem->flush();
}
/* we handle image */
$image1 = $request->files->get('form')['imageFile'];
//print('<br>QQW image 1: ');
//\Doctrine\Common\Util\Debug::dump($image1);
/* we check user folder for user files */
if(!$this->isUserFolder($request)) {
$this->createUserFolder($request);
}
$userDirs = $this->getUserFolderPaths($request);
if(!empty($image1)) {
$fileName1 = md5(uniqid()).'.'.$image1->guessExtension();
$image1->move($userDirs['images'], $fileName1);
$webPage->setImageFile($fileName1);
}
}
$webPageType = $form['webPageType']->getData();
/* if homepage then we unlink old homepage(s) */
if($form['webPageType']->getData() == $webPage::PAGETYPE['PAGETYPE_HOMEPAGE']) {
/* for website */
if(!empty($webPage->getWebsiteId()) && ($webPage->getWebsiteId() > 0)) {
$dem->getRepository(WebPage::class)->emptyPageHome($web->getWebsiteId(), $webPage->getWebPageId());
}
/* for eshop */
if(!empty($webPage->getEshopId()) && ($webPage->getEshopId() > 0)) {
$dem->getRepository(WebPage::class)->emptyEshopHome($webPage->getEshopId(), $webPage->getWebPageId());
}
}
/* if header then we unlink old page header(s) */
if($form['webPageType']->getData() == $webPage::PAGETYPE['PAGETYPE_HEADER']) {
// for website
if(!empty($webPage->getWebsiteId()) && ($webPage->getWebsiteId() > 0)) {
print('<br>------------------------ setting PAGETYPE_HEADER: ');
$dem->getRepository(WebPage::class)->emptyPageHeader($web->getWebsiteId(), $webPage->getWebPageId());
}
// for eshop
if(!empty($webPage->getEshopId()) && ($webPage->getEshopId() > 0)) {
$dem->getRepository(WebPage::class)->emptyEshopHeader($webPage->getEshopId(), $webPage->getWebPageId());
}
}
/* if footer then we unlink old page footer(s) */
if($form['webPageType']->getData() == $webPage::PAGETYPE['PAGETYPE_FOOTER']) {
/* for website */
if(!empty($webPage->getWebsiteId()) && ($webPage->getWebsiteId() > 0)) {
$dem->getRepository(WebPage::class)->emptyPageFooter($web->getWebsiteId(), $webPage->getWebPageId());
}
/* for eshop */
if(!empty($webPage->getEshopId()) && ($webPage->getEshopId() > 0)) {
$dem->getRepository(WebPage::class)->emptyEshopFooter($webPage->getEshopId(), $webPage->getWebPageId());
}
}
/* if leftColumn then we unlink old leftColumn(s) */
if($form['webPageType']->getData() == $webPage::PAGETYPE['PAGETYPE_LEFT_COLUMN']) {
/* for website */
if(!empty($webPage->getWebsiteId()) && ($webPage->getWebsiteId() > 0)) {
$dem->getRepository(WebPage::class)->emptyLeftColumn($web->getWebsiteId(), $webPage->getWebPageId());
}
}
//print('<br>---------------------------- qqw PAGETYPE_HEADER: '.$webPage::PAGETYPE['PAGETYPE_HEADER']);
//print('<br>---------------------------- qqw PAGETYPE_COMMON: '.$webPage::PAGETYPE['PAGETYPE_COMMON']);
/* we set page type */
//print('<br>---------------------------- qqw set webPageType: '.(int)$form['webPageType']->getData());
//print('<br>---------------------------- qqw set webPageType 2: '.$webPageType);
$webPage->setWebPageType($webPageType);
//$this->addFlash('notice', 'webPageType::'.$form['webPageType']->getData());
$webPage->setDatePublished($formData->getDatePublished());
/* we persist and save */
$dem->persist($webPage);
$dem->flush();
$this->addFlash('notice', $this->translator->trans('webpages.updated'));
return $this->redirectToRoute('webPageEdit', array('webPageId' => $webPage->getWebPageId()));
//}
}
//phpinfo();
/* we render data */
return $this->render('webPageEdit.html.twig',
array('headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'webPage' => $webPage,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'user' => $user,
)
);
}
/**
* @Route("/webPageList", name="webPageList")
*/
public function webPageListAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get user */
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$userDirs = $this->getUserFolderPaths($request);
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($userId);
//$productList = $dem->getRepository('AppBundle:Product')->getProductList();
$webPageList = $dem->getRepository(WebPage::class)->getWebPageListByEshop($eshop->getEshopId());
//echo $request->attributes->get('_route');
//echo $request->getPathInfo();
/* we render data */
return $this->render('productListEdit.html.php',
array('headerData' => $this -> getPageHeader($request),
'productList' => $productList,
'productThumbs' => $productThumbs,
'userDirs' => $userDirs,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
)
);
}
/**
* @Route("/webPageRemove/{webPageId}", name="webPageRemove")
*/
public function webPageRemoveAction(Request $request, $webPageId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get user */
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we get current e-shop */
//$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($userId);
//$eshopCurrency = $em->getRepository('AppBundle:Currency')->getCurrency($eshop->getPreferredCurrencyId());
/* we get webPage */
$webPage = $dem->getRepository(WebPage::class)->getWebPage($webPageId);
/* we remove price levels */
//$priceLevelCollection = $dem->getRepository('AppBundle:PriceLevel')->getPriceLevelList();
/* we remove categories */
//$categoryCollection = $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
/* we remove product groups */
//$productGroupCollection = $dem->getRepository('AppBundle:ProductGroup')->getProductGroupList();
//die('<br>qqw removing product');
$dem->remove($webPage);
//$em->persist($user);
$dem->flush();
$this->addFlash('notice', 'Web page was removed.');
return $this->redirectToRoute('productListEdit');
}
/**
* @Route("/createHeader", name="createHeader")
*/
public function createHeaderAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current user */
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
$webPage = new WebPage;
$webPage->setWebPageName("Page Header");
if(!empty($request->query->get('eshopHeader'))) {
/* we set current eshop */
$currentEshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
$webPage->setEshopId($currentEshop->getEshopId());
} else {
/* we set current website */
$currentWeb = $em->getRepository(Website::class)->getCurrentWebsite($currentUserId);
$webPage->setWebsiteId($currentWeb->getWebsiteId());
}
$webPage->setWebPageType($webPage::PAGETYPE['PAGETYPE_HEADER']);
/* we persist and save */
$dem->persist($webPage);
$dem->flush();
$this->addFlash('notice', 'Header was created.');
return $this->redirectToRoute('webPageEdit', array('webPageId' => $webPage->getWebPageId()));
}
/**
* @Route("/createFooter", name="createFooter")
*/
public function createFooterAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current user */
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
$webPage = new WebPage;
$webPage->setWebPageName("Page Footer");
if(!empty($request->query->get('eshopFooter'))) {
/* we set current eshop */
$currentEshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
$webPage->setEshopId($currentEshop->getEshopId());
} else {
/* we set current website */
$currentWeb = $em->getRepository(Website::class)->getCurrentWebsite($currentUserId);
$webPage->setWebsiteId($currentWeb->getWebsiteId());
}
$webPage->setWebPageType($webPage::PAGETYPE['PAGETYPE_FOOTER']);
/* we persist and save */
$dem->persist($webPage);
$dem->flush();
$this->addFlash('notice', 'Footer was created.');
return $this->redirectToRoute('webPageEdit', array('webPageId' => $webPage->getWebPageId()));
}
/**
* @Route("/web/{webId}/register", name="webRegister")
*/
public function webRegisterAction(Request $request, $webId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current web */
$web = $em->getRepository(Website::class)->getWebsite($webId);
/* we check if web exists */
if($web === null) {
$this->addFlash('error', 'Web with tis ID does not exists.');
return $this->redirectToRoute('webHome');
}
/* we load header for the current website */
$webPageHeader = $dem->getRepository(WebPage::class)->getWebPageHeader($webId);
/* we load footer for the current website */
$webPageFooter = $dem->getRepository(WebPage::class)->getWebPageFooter($webId);
/* we load header for the current website */
$webMenuMain = $dem->getRepository(WebMenu::class)->getMainMenu($webId);
if(!empty($webMenuMain)) {
$webMenuItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuMain->getWebMenuId());
} else {
$webMenuItemList = array();
}
$user = $em->getRepository(User::class)->getUser($web->getUserId());
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($web->getWireFrameId());
/*
print('<hr>qqw wireframe: ');
\Doctrine\Common\Util\Debug::dump($wireFrame);
*/
$webMenuVertical = null;
$webMenuVerticalItemList = null;
/* we load left column - vertical menu for the current website */
if($wireFrame->getWireFrameName() == 'Website Classic') {
$webMenuVertical = $dem->getRepository(WebMenu::class)->getVerticalMenu($webId);
if(!empty($webMenuVertical)) {
$webMenuVerticalItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuVertical->getWebMenuId());
}
}
/* we prepare data for the form */
if(!empty($request->request->get('form')['company'])) {
$company = $request->request->get('form')['company'];
} else {
$company = '';
}
if(!empty($request->request->get('form')['email'])) {
$email = $request->request->get('form')['email'];
} else {
$email = '';
}
if(!empty($request->request->get('form')['telefon'])) {
$telefon = $request->request->get('form')['telefon'];
} else {
$telefon = '';
}
if(!empty($request->request->get('form')['address'])) {
$address = $request->request->get('form')['address'];
} else {
$address = '';
}
if(!empty($request->request->get('form')['username'])) {
$username = $request->request->get('form')['username'];
} else {
$username = '';
}
if(!empty($request->request->get('form')['password'])) {
$password = $request->request->get('form')['password'];
} else {
$password = '';
}
if(!empty($request->request->get('form')['password_retype'])) {
$password_retype = $request->request->get('form')['password_retype'];
} else {
$password_retype = '';
}
/* we build register form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('company', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.company'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $company),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('email', EmailType::class, array(
'required' => true,
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $email),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('telefon', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.telephone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $telefon),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('address', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('user.address'),
'attr' => array('class' => 'textarea_form', 'cols' => 30, 'rows' => 3, 'value' => $address),
'label_attr' => array('class' => 'form_textarea_label'),
));
$formBuilder->add('username', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('user.username'),
'empty_data' => '',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $username),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('password', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('password_retype', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password_retype'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password_retype),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.send'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
if ($form->isValid()) {
// perform some action, such as save the object to the database
//print('<br>qqw post form 2: ');
/* we check if this contact already exists */
$contactExist = $dem->getRepository('AppBundle:Contact')->getContactFromUsername($request->request->get('form')['username']);
/*
print('<br>qqw contact exists: ');
\Doctrine\Common\Util\Debug::dump($contactExist);
*/
if($contactExist === null) {
/* we check if the password fields are the same */
$password = $request->request->get('form')['password'];
$retypePassword = $request->request->get('form')['password_retype'];
if($password != '' && $password == $retypePassword) {
//print('<br>We create new contact');
$contact = new Contact;
$password = md5($request->request->get('form')['password']);
/* we load contact data from register form into contact object */
$contact->setCompanyName($request->request->get('form')['company']);
$contact->setContactUserName($request->request->get('form')['username']);
$contact->setEmail($request->request->get('form')['email']);
$contact->setAddress1($request->request->get('form')['address']);
$contact->setContactUserPassword($password);
/*
print('<br>qqw user exists: ');
\Doctrine\Common\Util\Debug::dump($contact);
*/
/* we persist and save contact */
$dem->persist($contact);
$dem->flush();
$this->addFlash('notice', 'New customer account was created.');
/* we load logged contact into session */
$session = $request->getSession();
$session->set('contact', $contact);
return $this->redirectToRoute('webHomeContact', array('webId' => $webId));
}
else {
$this->addFlash('error', 'Both password fields must be the same.');
}
}
else {
$this->addFlash('error', 'Account with this username already exists.');
}
}
}
/* we render data */
return $this->render('webRegister.html.php',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'web' => $web,
'user' => $user,
'wireFrame' => $wireFrame,
'webPageHeader' => $webPageHeader,
'webPageFooter' => $webPageFooter,
'webMenuVertical' => $webMenuVertical,
'webMenuVerticalItemList' => $webMenuVerticalItemList,
)
);
}
/**
* @Route("/web/{webId}/logout", name="webLogout")
*/
public function webLogoutAction(Request $request, $webId) {
/* we load session data */
parent::init($request);
/* we unload logged user session */
$session = $request->getSession();
$session->set('contact', null);
$this->addFlash('notice', 'User was logged out. ');
return $this->redirectToRoute('web', array('webId' => $webId));
}
/**
* @Route("/web/{webId}/login", name="webLogin")
*/
public function webLoginAction(Request $request, $webId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current web */
$web = $em->getRepository(Website::class)->getWebsite($webId);
/* we check if web exists */
if($web === null) {
$this->addFlash('error', 'Web with tis ID does not exists.');
return $this->redirectToRoute('webHome');
}
/* if there is a contact logged in then we redirect to contacts home page */
if(!empty($session->get('contact'))) {
return $this->redirectToRoute('webHomeContact', array('webId' => $webId));
}
/* we load header for the current website */
$webPageHeader = $dem->getRepository(WebPage::class)->getWebPageHeader($webId);
/* we load footer for the current website */
$webPageFooter = $dem->getRepository(WebPage::class)->getWebPageFooter($webId);
/* we load header for the current website */
$webMenuMain = $dem->getRepository(WebMenu::class)->getMainMenu($webId);
if(!empty($webMenuMain)) {
$webMenuItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuMain->getWebMenuId());
} else {
$webMenuItemList = array();
}
/* we load top menu for the current website */
$webMenuTop = $dem->getRepository(WebMenu::class)->getTopMenu($webId);
if(!empty($webMenuTop)) {
$webMenuTopItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuTop->getWebMenuId());
} else {
$webMenuTopItemList = array();
}
$user = $em->getRepository(User::class)->getUser($web->getUserId());
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($web->getWireFrameId());
/*
print('<hr>qqw wireframe: ');
\Doctrine\Common\Util\Debug::dump($wireFrame);
*/
$webMenuVertical = null;
$webMenuVerticalItemList = null;
/* we load left column - vertical menu for the current website */
if($wireFrame->getWireFrameName() == 'Website Classic') {
$webMenuVertical = $dem->getRepository(WebMenu::class)->getVerticalMenu($webId);
if(!empty($webMenuVertical)) {
$webMenuVerticalItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuVertical->getWebMenuId());
}
}
/* we build login form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('username', TextType::class, array(
'required' => true,
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('password', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('save', SubmitType::class, array('label' => 'Login',
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
if ($form->isValid()) {
// perform some action, such as save the object to the database
/* we check if this username exists */
$em = $this->doctrine->getManager();
$userName = $request->request->get('form')['username'];
$contactExist = $dem->getRepository('AppBundle:Contact')->getContactFromLogin($userName, $request->request->get('form')['password']);
/*
print('<br>qqw contact exists: '.$userName.' :: '.$request->request->get('form')['password']);
\Doctrine\Common\Util\Debug::dump($contactExist);
*/
if(!empty($contactExist)) {
/* we load logged contact into session */
$session = $request->getSession();
$session->set('contact', $contactExist);
/*
print('<hr>we set session contact: ');
\Doctrine\Common\Util\Debug::dump($session->get('contact'));
*/
$this->addFlash('notice', 'Welcome '.$userName.'. You are logged in.');
//return $this->redirectToRoute('eshopHomeContact');
if(isset($request->request->get('form')['returnRoute'])) {
return $this->redirectToRoute($request->request->get('form')['returnRoute'], array('webId' => $webId));
} else {
return $this->redirectToRoute('webHomeContact', array('webId' => $webId));
}
}
else {
$this->addFlash('error', 'Login error.');
}
}
}
/* we render data */
return $this->render('webLogin.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'web' => $web,
'user' => $user,
'wireFrame' => $wireFrame,
'webPageHeader' => $webPageHeader,
'webPageFooter' => $webPageFooter,
'webMenuVertical' => $webMenuVertical,
'webMenuVerticalItemList' => $webMenuVerticalItemList,
'webMenuMain' => $webMenuMain,
'webMenuItemList' => $webMenuItemList,
'webMenuTop' => $webMenuTop,
'webMenuTopItemList' => $webMenuTopItemList,
)
);
}
/**
* @Route("/web/{webId}/webHomeContact", name="webHomeContact")
*/
public function webHomeContactAction(Request $request, $webId) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current web */
$web = $em->getRepository(Website::class)->getWebsite($webId);
/* we check if web exists */
if($web === null) {
$this->addFlash('error', 'Web with tis ID does not exists.');
return $this->redirectToRoute('webHome');
}
/* we load header for the current website */
$webPageHeader = $dem->getRepository(WebPage::class)->getWebPageHeader($webId);
/* we load footer for the current website */
$webPageFooter = $dem->getRepository(WebPage::class)->getWebPageFooter($webId);
/* we load header for the current website */
$webMenuMain = $dem->getRepository(WebMenu::class)->getMainMenu($webId);
if(!empty($webMenuMain)) {
$webMenuItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuMain->getWebMenuId());
} else {
$webMenuItemList = array();
}
$user = $em->getRepository(User::class)->getUser($web->getUserId());
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($web->getWireFrameId());
/*
print('<hr>qqw wireframe: ');
\Doctrine\Common\Util\Debug::dump($wireFrame);
*/
$webMenuVertical = null;
$webMenuVerticalItemList = null;
/* we load left column - vertical menu for the current website */
if($wireFrame->getWireFrameName() == 'Website Classic') {
$webMenuVertical = $dem->getRepository(WebMenu::class)->getVerticalMenu($webId);
if(!empty($webMenuVertical)) {
$webMenuVerticalItemList = $dem->getRepository(WebMenuItem::class)->getWebMenuItemList($webMenuVertical->getWebMenuId());
}
}
$contactId = $session->get('contact')->getContactId();
$contact = $dem->getRepository('AppBundle:Contact')->getContact($contactId);
//print('<hr>qqw contact: '.$contactId);
//\Doctrine\Common\Util\Debug::dump($contact);
/* we render data */
return $this->render('webHomeContact.html.php',
array('headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'web' => $web,
'user' => $user,
'contact' => $contact,
'wireFrame' => $wireFrame,
'webPageHeader' => $webPageHeader,
'webPageFooter' => $webPageFooter,
'webMenuVertical' => $webMenuVertical,
'webMenuVerticalItemList' => $webMenuVerticalItemList,
)
);
}
public function adminMenu(Request $request)
{
$menuItems = array(
1 => array('link' => 'webpagesAdmin', 'langKey' => 'webpages.admin', 'routeName' => 'webpagesAdmin'),
2 => array('link' => 'webPageNew', 'langKey' => 'webpages.new_page', 'routeName' => 'webPageNew'),
3 => array('link' => 'webnew', 'langKey' => 'webpages.new_web', 'routeName' => 'webNew'),
4 => array('link' => 'webConfig', 'langKey' => 'webpages.config', 'routeName' => 'webConfig'),
);
return $menuItems;
}
}