<?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\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Validator\Constraints\DateTime;
use App\Entity\Eshop;
use App\Entity\EshopLink;
use App\Entity\Service;
use App\Entity\Contact;
use App\Entity\ContactGroup;
use App\Entity\CustomList;
use App\Entity\CustomListItem;
use App\Entity\Address;
use App\Entity\User;
use App\Entity\UserStory;
use App\Entity\Module;
use App\Entity\Consent;
use App\Entity\PriceLevel;
use App\Entity\Order;
use App\Entity\TradeLead;
use Symfony\Contracts\Translation\TranslatorInterface;
class KnowledgeBaseController extends DefaultController
{
protected KernelInterface $appKernel;
protected ManagerRegistry $doctrine;
protected TranslatorInterface $translator;
public function __construct(KernelInterface $appKernel,
ManagerRegistry $doctrine,
TranslatorInterface $translator)
{
$this->appKernel = $appKernel;
$this->doctrine = $doctrine;
$this->translator = $translator;
}
/**
* @Route("/knowledgebase", name="knowledgebase")
*/
public function indexAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
/* we load list of modules for connector service */
$service = $em->getRepository(Service::class)->getService(2);
/* we get current user */
if (!empty($session->get('user'))) {
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
$userModuleList = $user->getModules();
} else {
$userModuleList = [];
}
/* we render data */
return $this->render('knowledgebase.html.twig',
array('headerData' => $this -> getPageHeader($request),
'moduleList' => $service->getModules(),
'userModuleList' => $userModuleList,
'service' => $service,
)
);
}
/**
* @Route("/knowledgebaseAdmin", name="knowledgebaseAdmin")
*/
public function knowledgebaseAdminAction(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);
/* we load service */
$service = $em->getRepository(Service::class)->getService(2);
//we check if user has UserStory module and get recent form responses
$module = $em->getRepository(Module::class)->getModule(24);
$isModule = $em->getRepository(User::class)->userHasModule($user, $module);
$taskList = null;
if($isModule) {
$dateStart = date("Y-m-d",strtotime('monday this week'));
$dateEnd = date("Y-m-d",strtotime('sunday this week'));
$taskList = $dem->getRepository(UserStory::class)->getUserStoryStartBetweenDatesList($dateStart, $dateEnd);
}
/* we render data */
return $this->render('knowledgebaseAdmin.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'moduleList' => $service->getModules(),
'userModuleList' => $user->getModules(),
'user' => $user,
'menu' => $this -> adminMenu($request),
'taskList' => $taskList,
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/contactnew", name="contactNew")
*/
public function contactNewAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$em = $this->doctrine->getManager();
/* we get current user */
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
$contact = new Contact();
/* we build login form */
$formBuilder = $this->createFormBuilder($contact);
$formBuilder->add('firstName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.first_name'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('lastName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.last_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');
$formData = $form->getData();
print('<br>qqw saving data');
\Doctrine\Common\Util\Debug::dump($formData);
$address = new Address();
$deliveryAddress = new Address();
print('<br>qqw firstName form: '.$formData->getFirstName());
print('<br>qqw firstName object: '.$contact->getFirstName());
$contact->setFirstName($formData->getFirstName());
$contact->setLastName($formData->getLastName());
//$contact->setAddress($address);
//$contact->setDeliveryAddress($deliveryAddress);
/* we persist and save */
//$dem->persist($address);
//$dem->persist($deliveryAddress);
$dem->persist($contact);
$dem->flush();
$this->addFlash('notice', $this->translator->trans('eshop.contact_created'));
return $this->redirectToRoute('contactEdit', array('contactId' => $contact->getContactId()));
}
}
/* we render data */
return $this->render('contactNew.html.twig',
array( 'form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'user' => $user,
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/contacts", name="contacts")
*/
public function contactsAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we check if an user is logged in */
if(empty($session->get('user'))) {
return $this->redirectToRoute('login');
}
/* we load users entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* removing contact */
if(!empty($request->query->get('removeContact'))) {
//print('<br>qqw removing Contact 33: '.$request->query->get('removeContact'));
try {
$isRemovable = true;
$resultMessage = '';
$contactId = $request->query->get('removeContact');
$contact = $dem->getRepository(Contact::class)->getContact($contactId);
//$contact = $dem->getRepository(Contact::class)
//removes contacts consents
if (!empty($contact->getConsents())) {
foreach ($contact->getConsents() as $consent) {
//print('<hr>consent: ');
//\Doctrine\Common\Util\Debug::dump($consent);
$contact->removeConsent($consent);
$dem->persist($contact);
$dem->flush();
}
}
//check orders
$orderList = $dem->getRepository(Order::class)->getOrderListByCustomer($contact,'orderId','DESC');
if (!empty($orderList)) {
foreach ($orderList as $order) {
//print('<hr>order: '.$order->getOrderId());
$resultMessage .= $order->getOrderId().', ';
$isRemovable = false;
}
}
if ($isRemovable) {
$contact = $dem->getRepository(Contact::class)->removeContact($request->query->get('removeContact'));
$this->addFlash('notice', $this->translator->trans('eshop.contact_removed'));
} else {
$this->addFlash('error', 'Contact not removed. There are associated orders: '.$resultMessage);
}
} catch(\Doctrine\DBAL\DBALException $e) {
$this->addFlash('error', "This contact has connected services (orders etc.), so it can't be removed.");
}
}
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$contactList = $dem->getRepository(Contact::class)->getContactList();
$contactGroupList = $dem->getRepository(ContactGroup::class)->getContactGroupList();
/* we render data */
return $this->render('contacts.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'contactList' => $contactList,
'contactGroupList' => $contactGroupList,
'menu' => $this -> adminMenu($request),
'user' => $user,
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/contactedit/{contactId}", name="contactEdit")
*/
public function contactEditAction(Request $request, $contactId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we check if an 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');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$contact = $dem->getRepository(Contact::class)->getContact($contactId);
//$contactExists = $em->getRepository(Contact::class)->findOneBy(['contactId' => $contactId]);
//->findOneBy(array('order_id' => $orderId));
//print('<hr>qqw x contact id 1: '.$contactId.': ');
//\Doctrine\Common\Util\Debug::dump($contact);
//print('<hr>qqw x contact id 2: '.$contactId.': ');
//\Doctrine\Common\Util\Debug::dump($contactExists);
/* we get collection of contact groups */
$contactGroupList = $dem->getRepository(ContactGroup::class)->getContactGroupList();
/* we get collection of consents */
$consents = $dem->getRepository(Consent::class)->getConsentList();
/* we build edit form */
$formBuilder = $this->createFormBuilder($contact);
$formBuilder->add('firstName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.first_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getFirstName()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('middleName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.middle_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getMiddleName()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('lastName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.last_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getLastName()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('companyName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.company_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getCompanyName()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('email', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.email'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getEmail()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('email2', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.email').' 2',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getEmail2()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('email3', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.email').' 3',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getEmail3()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('phone', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getPhone()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('phone2', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.phone').' 2',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getPhone2()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('phone3', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.phone').' 3',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getPhone3()),
'label_attr' => array('class' => 'form_field_label')
));
/* we set addresses */
if(empty($contact->getAddress())) {
$address = new Address;
$contact->setAddress($address);
}
$formBuilder->add('addressStreet', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.street'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getAddress()->getStreet()),
'label_attr' => array('class' => 'form_field_label_top'),
'mapped' => false
));
$formBuilder->add('addressStreetNumber', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.street_number'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $contact->getAddress()->getStreetNumber()),
'label_attr' => array('class' => 'form_field_label'),
'mapped' => false
));
$formBuilder->add('addressZipCode', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.zip_code'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $contact->getAddress()->getZipCode()),
'label_attr' => array('class' => 'form_field_label'),
'mapped' => false
));
$formBuilder->add('addressCity', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.city'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getAddress()->getCity()),
'label_attr' => array('class' => 'form_field_label'),
'mapped' => false
));
$formBuilder->add('addressCountry', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.country'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getAddress()->getCountry()),
'label_attr' => array('class' => 'form_field_label_bottom'),
'mapped' => false
));
/* we set delivery address */
if(empty($contact->getDeliveryAddress())) {
$deliveryAddress = new Address;
$contact->setDeliveryAddress($deliveryAddress);
}
$formBuilder->add('deliveryAddressStreet', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.street_delivery'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getDeliveryAddress()->getStreet()),
'label_attr' => array('class' => 'form_field_label'),
'mapped' => false
));
$formBuilder->add('deliveryAddressStreetNumber', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.street_number_delivery'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $contact->getDeliveryAddress()->getStreetNumber()),
'label_attr' => array('class' => 'form_field_label'),
'mapped' => false
));
$formBuilder->add('deliveryAddressZipCode', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.zip_code_delivery'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $contact->getDeliveryAddress()->getZipCode()),
'label_attr' => array('class' => 'form_field_label'),
'mapped' => false
));
$formBuilder->add('deliveryAddressCity', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.city_delivery'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getDeliveryAddress()->getCity()),
'label_attr' => array('class' => 'form_field_label'),
'mapped' => false
));
$formBuilder->add('deliveryAddressCountry', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('address.country_delivery'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getDeliveryAddress()->getCountry()),
'label_attr' => array('class' => 'form_field_label_bottom'),
'mapped' => false
));
/*
$formBuilder->add('address', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.address').' 1',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getAddress1()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('address2', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.address').' 2',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getAddress2()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('invoiceAddress', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('module.invoice_address').' 1',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getInvoiceAddress1()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('invoiceAddress2', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('module.invoice_address').' 2',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getInvoiceAddress2()),
'label_attr' => array('class' => 'form_field_label')
));
*/
$formBuilder->add('businessId', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.business_number'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getBusinessId()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('DICId', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.DIC_number'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getDICId()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('ERPKey', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.erp_key'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getERPKey()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('notes', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('system.notes'),
'attr' => array('class' => 'textarea_form', 'cols' => 55, 'rows' => 4, 'value' => $contact->getNotes()),
'label_attr' => array('class' => 'form_textarea_label'),
'data' => $contact->getNotes(),
));
$formBuilder->add('contactUserName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.user_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getContactUserName()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('contactUserPassword', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.password'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getContactUserPassword()),
'label_attr' => array('class' => 'form_field_label')
));
/* we add all contact groups */
$contactGroups = array();
foreach($contactGroupList as $contactGroup)
{
$contactGroups[$contactGroup->getContactGroupName()] = $contactGroup->getContactGroupId();
}
// print('<br>All ContactGroups: ');
// print_r($contactGroups);
$selectedContactGroups = array();
// print('<br>------------------- ContactGroups 0: ');
// \Doctrine\Common\Util\Debug::dump($contact->getContactGroups());
if (!empty($contact->getContactGroups())) {
foreach($contact->getContactGroups() as $contactGroup) {
if(!empty($contactGroup)) {
$selectedContactGroups[] = $contactGroup->getContactGroupId();
}
}
}
// print('<br>ContactGroups: ');
// \Doctrine\Common\Util\Debug::dump($contact->getContactGroups());
//print_r($contact->getContactGroups());
$formBuilder->add('contactGroups', ChoiceType::class, array(
'choices' => $contactGroups,
'required' => false,
'mapped' => false,
'multiple' => true,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedContactGroups
));
/* we add all consents */
$consentList = array();
foreach($consents as $consent)
{
$consent->setLocale($session->get('lang')->getLangKey());
$dem->refresh($consent);
$consentList[$consent->getConsentName()] = $consent->getConsentId();
}
// print('<br>------------------- all consents: ');
// \Doctrine\Common\Util\Debug::dump($consentList);
$selectedConsents = array();
if (!empty($contact->getConsents())) {
foreach ($contact->getConsents() as $consent) {
if (!empty($consent)) {
$selectedConsents[] = $consent->getConsentId();
}
}
}
$formBuilder->add('consents', ChoiceType::class, array(
'choices' => $consentList,
'required' => false,
'mapped' => false,
'multiple' => true,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedConsents
));
//isModule Price Levels
$module = $em->getRepository(Module::class)->getModule(22);
$isPriceLevelModule = $em->getRepository(User::class)->userHasModule($user, $module);
$consentList = null;
if($isPriceLevelModule) {
//print('<br>qqw is module Price Levels');
$priceLevels = $dem->getRepository(PriceLevel::class)->getPriceLevelList();
/* we add all price levels */
$priceLevelList = array();
foreach($priceLevels as $priceLevel)
{
$priceLevel->setLocale($session->get('lang')->getLangKey());
$dem->refresh($priceLevel);
$priceLevelList[$priceLevel->getPriceLevelName()] = $priceLevel->getPriceLevelId();
}
$selectedPriceLevels = array();
$selectedPriceLevel = 1;
if(!empty($contact->getPriceLevel())) {
// print('<br>contactPriceLevel: ');
// \Doctrine\Common\Util\Debug::dump($contact->getPriceLevel());
//print_r($contact->getPriceLevel());
//$selectedPriceLevels[] = $contact->getPriceLevel()->getPriceLevelId();
$selectedPriceLevel = $contact->getPriceLevel()->getPriceLevelId();
}
$formBuilder->add('priceLevel', ChoiceType::class, array(
'choices' => $priceLevelList,
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedPriceLevel
));
}
$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
//print('<br>qqw post form 2: ');
$formData = $form->getData();
/* we load data from form into contact object */
$contact->setFirstName($formData->getFirstName());
$contact->setMiddleName($formData->getMiddleName());
$contact->setLastName($formData->getLastName());
$contact->setCompanyName($formData->getCompanyName());
$contact->setEmail($formData->getEmail());
$contact->setEmail2($formData->getEmail2());
$contact->setEmail3($formData->getEmail3());
$contact->setPhone($formData->getPhone());
$contact->setPhone2($formData->getPhone2());
$contact->setPhone3($formData->getPhone3());
$address = $contact->getAddress();
$address->setStreet($form['addressStreet']->getData());
$address->setStreetNumber($form['addressStreetNumber']->getData());
$address->setCity($form['addressCity']->getData());
$address->setZipCode($form['addressZipCode']->getData());
$address->setCountry($form['addressCountry']->getData());
//$contact->setAddress($address);
$deliveryAddress = $contact->getDeliveryAddress();
$deliveryAddress->setStreet($form['deliveryAddressStreet']->getData());
$deliveryAddress->setStreetNumber($form['deliveryAddressStreetNumber']->getData());
$deliveryAddress->setCity($form['deliveryAddressCity']->getData());
$deliveryAddress->setZipCode($form['deliveryAddressZipCode']->getData());
$deliveryAddress->setCountry($form['deliveryAddressCountry']->getData());
//$contact->setDeliveryAddress($deliveryAddress);
$contact->setBusinessId($formData->getBusinessId());
$contact->setDICId($formData->getDICId());
$contact->setNotes($formData->getNotes());
$contact->setContactUserName($formData->getContactUserName());
// if the password is md5 hash already we do not hash
$cuPsw = $formData->getContactUserPassword();
if(strlen($cuPsw) == 32 && ctype_xdigit($cuPsw)) {
$password = $cuPsw;
} else {
$password = md5($cuPsw);
}
$contact->setContactUserPassword($password);
// we remove old contact groups
if(!empty($contact->getContactGroups())) {
foreach ($contact->getContactGroups() as $group) {
print('<br>Group: ');
$contact->removeContactGroup($group);
//$dem->refresh($product);
//$dem->persist($cat);
}
}
// we save contact groups
$formContactGroups = $form['contactGroups']->getData();
if(is_array($formContactGroups)) {
foreach($formContactGroups as $contactGroupId) {
//print('');
$group = $dem->getRepository(ContactGroup::class)->getContactGroup($contactGroupId);
$contact->addContactGroup($group);
}
}
// we save selected price level
if($isPriceLevelModule && !empty($form['priceLevel']->getData())) {
print('<br>PLId : '.$form['priceLevel']->getData());
$priceLevel = $dem->getRepository(PriceLevel::class)->getPriceLevel($form['priceLevel']->getData());
$contact->setPriceLevel($priceLevel);
//print('<br>QQW selected price level: ');
//\Doctrine\Common\Util\Debug::dump($priceLevel);
}
// we remove old consents
if(!empty($contact->getConsents())) {
foreach ($contact->getConsents() as $consent) {
print('<br>Consent: ');
$contact->removeConsent($consent);
}
}
// we save consents
$formConsents = $form['consents']->getData();
if(is_array($formConsents)) {
foreach($formConsents as $consentId) {
$consent = $dem->getRepository(Consent::class)->getConsent($consentId);
$contact->addConsent($consent);
}
}
/* we persist and save */
$em->persist($contact);
$dem->flush();
$this->addFlash('notice', $this->translator->trans('eshop.contact_updated'));
return $this->redirectToRoute('contactEdit', array('contactId' => $contact->getContactId()));
}
}
/* we render data */
return $this->render('contactEdit.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'user' => $user,
'contact' => $contact,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/contactGroupNew", name="contactGroupNew")
*/
public function contactGroupNewAction(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);
$contactGroup = new ContactGroup();
/* we build login form */
$formBuilder = $this->createFormBuilder($contactGroup);
$formBuilder->add('contactGroupName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.contact_group_name'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
//form.button.save
$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');
$formData = $form->getData();
$contactGroup = new ContactGroup;
$contactGroup->setContactGroupName($formData->getContactGroupName());
/* we persist and save */
$dem->persist($contactGroup);
$dem->flush();
$this->addFlash('notice', 'New contact group was created.');
return $this->redirectToRoute('contactGroupEdit', array('contactGroupId' => $contactGroup->getContactGroupId()));
}
}
/* we render data */
return $this->render('contactGroupNew.html.twig',
array( 'form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'user' => $user,
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/contactGroupEdit/{contactGroupId}", name="contactGroupEdit")
*/
public function contactGroupEditAction(Request $request, $contactGroupId)
{
/* 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);
/* we get product parameter group */
$contactGroup = $dem->getRepository(ContactGroup::class)->getContactGroup($contactGroupId);
$userDirs = $this->getUserFolderPaths($request);
/*
print('<br>QQW categoryCollection: ');
\Doctrine\Common\Util\Debug::dump($categoryCollection);
*/
/* we build edit form */
$formBuilder = $this->createFormBuilder($contactGroup);
$formBuilder->add('contactGroupName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.contact_group_name'),
'attr' => array('class' => 'text_form', 'size' => 22, 'value' => $contactGroup->getContactGroupName()),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('contactGroupBoard', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.contact_group_board'),
'attr' => array('class' => 'textarea_form', 'cols' => 77, 'rows' => 7, 'value' => $contactGroup->getContactGroupBoard()),
'label_attr' => array('class' => 'form_field_label'),
'data' => $contactGroup->getContactGroupBoard(),
));
$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') {
//$form->bindRequest($request);
if ($form->isValid()) {
// perform some action, such as save the object to the database
$formData = $form->getData();
$contactGroup->setContactGroupName($formData->getContactGroupName());
$contactGroup->setContactGroupBoard($formData->getContactGroupBoard());
/* we persist and save */
$dem->persist($contactGroup);
$dem->flush();
$this->addFlash('notice', 'Contact group was updated.');
return $this->redirectToRoute('contactGroupEdit', array('contactGroupId' => $contactGroup->getContactGroupId()));
}
}
/* we render data */
return $this->render('contactGroupEdit.html.twig',
array('headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'contactGroup' => $contactGroup,
'userDirs' => $userDirs,
'menu' => $this -> adminMenu($request),
'user' => $user,
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/contactGroupRemove/{contactGroupId}", name="contactGroupRemove")
*/
public function contactGroupRemoveAction(Request $request, $contactGroupId)
{
/* 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);
/* we get product parameter group */
$contactGroup = $dem->getRepository(ContactGroup::class)->getContactGroup($contactGroupId);
//we remove association from contacts
$contactList = $dem->getRepository(Contact::class)->getContactList();
foreach($contactList as $contact) {
$contactGroupList = $contact->getContactGroups();
foreach($contactGroupList as $group) {
if ($group->getContactGroupId() == $contactGroupId) {
//print('<br>contact: '.$contact->getContactId());
$contact->removeContactGroup($group);
}
}
}
//we remove ContactGroup object
$dem->remove($contactGroup);
$dem->flush();
$this->addFlash('notice', 'Contact group was removed.');
return $this->redirectToRoute('contacts');
}
/**
* @Route("/lists", name="lists")
*/
public function listsAction(Request $request)
{
/* 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');
/* we get user */
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we check if user is logged in */
if(empty($session->get('user'))) {
return $this->redirectToRoute('login');
}
/* we get file name and paths */
$userDirs = $this->getUserFolderPaths($request);
$customLists = $dem->getRepository(CustomList::class)->getCustomLists();
/* we build search form */
$formBuilder = $this->createFormBuilder();
$searchString = null;
$searchResult = null;
$formBuilder->add('searchString', TextType::class, array(
'required' => true,
'label' => ' ',
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label22'),
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('system.search'),
'attr' => array('class' => 'inlineButton')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
if ($form->isValid()) {
$searchString = $request->request->get('form')['searchString'];
$searchResult['listItems'] = $dem->getRepository(CustomListItem::class)->getCustomListItemBySearch(trim($searchString));
$this->addFlash('notice', 'Searched string:'.$searchString);
}
}
/* we render data */
return $this->render('lists.html.twig',
array( 'form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request),
'customLists' => $customLists,
'menu' => $this -> adminMenu($request),
'userDirs' => $userDirs,
'searchResult' => $searchResult,
'searchString' => $searchString,
'user' => $user,
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/listnew", name="listNew")
*/
public function listNewAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$em = $this->doctrine->getManager();
/* we get user */
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we build login form */
$list = new CustomList();
$formBuilder = $this->createFormBuilder($list);
$formBuilder->add('listName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.list_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');
$formData = $form->getData();
print('<br>qqw saving data');
\Doctrine\Common\Util\Debug::dump($formData);
$list->setListName($formData->getListName());
/* we persist and save */
$dem->persist($list);
$dem->flush();
$this->addFlash('notice', 'New list was created.');
return $this->redirectToRoute('listEdit', array('listId' => $list->getListId()));
}
}
/* we render data */
return $this->render('listNew.html.twig',
array( 'form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'user' => $user,
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/listedit/{listId}", name="listEdit")
*/
public function listEditAction(Request $request, $listId)
{
/* 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 users entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* removing list item */
if(!empty($request->query->get('removeListItem'))) {
$listItem = $dem->getRepository(CustomListItem::class)->removeCustomListItem($request->query->get('removeListItem'));
$this->addFlash('notice', 'List item was removed.');
}
if(!empty($request->query->get('saveXml'))) {
//print('<br>qqw saving xml');
$this->saveListXML($request, $listId);
$this->addFlash('notice', 'List was exported to XML.');
}
$list = $dem->getRepository(CustomList::class)->getCustomList($listId);
$listItems = $dem->getRepository(CustomListItem::class)->getCustomListItems($listId);
/* we get file name and paths */
$userDirs = $this->getUserFolderPaths($request);
/*
print('<br>QQW list ID: '.$listId);
\Doctrine\Common\Util\Debug::dump($list);
*/
/* we build form for new items */
$listItem = new CustomListItem();
$formNewItemsBuilder = $this->createFormBuilder($listItem);
$formNewItemsBuilder->add('listItemName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.new_list_item'),
'attr' => array('class' => 'text_form_file2', 'size' => 35, 'value' => ''),
'label_attr' => array('class' => 'form_field_label'),
));
$formNewItemsBuilder->add('listItemShortDescription', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.list_short_description'),
'attr' => array('class' => 'text_form_file2', 'size' => 35, 'value' => ''),
'label_attr' => array('class' => 'form_field_label'),
));
$formNewItemsBuilder->add('listItemLongDescription', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.list_item_long_description'),
'attr' => array('class' => 'textarea_form', 'cols' => 50, 'rows' => 3, 'value' => ''),
'label_attr' => array('class' => 'form_textarea_label'),
));
$formNewItemsBuilder->add('clickURL', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.link_url'),
'attr' => array('class' => 'text_form_file2', 'size' => 35, 'value' => ''),
'label_attr' => array('class' => 'form_field_label'),
));
$formNewItemsBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('knowledgebase.create_list_item'),
'attr' => array('class' => 'butt_big')));
/* we build edit form */
$formBuilder = $this->createFormBuilder($list);
$formBuilder->add('listName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.list_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $list->getListName()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('linkURL', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.link_url'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $list->getLinkURL()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('xmlFile', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.xml_file'),
'attr' => array('class' => 'text_form', 'size' => 25, 'value' => $list->getXmlFile()),
'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')));
if ($request->getMethod() == 'POST') {
$formNewItems = $formNewItemsBuilder->getForm();
$formNewItems->handleRequest($request);
if ($formNewItems->isValid()) {
$formNewItemsData = $formNewItems->getData();
/* we load users entity manager */
//$dem = $this->doctrine->getManager('dynamic_em');
$listItem->setListItemName($formNewItemsData->getListItemName());
$listItem->setListItemShortDescription($formNewItemsData->getListItemShortDescription());
$listItem->setListItemLongDescription($formNewItemsData->getListItemLongDescription());
$listItem->setClickURL($formNewItemsData->getClickURL());
$listItem->setListId($listId);
/* we persist and save */
$dem->persist($listItem);
$dem->flush();
$this->addFlash('notice', 'New Item was Created');
return $this->redirectToRoute('listEdit', array('listId' => $listId));
}
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$formData = $form->getData();
/* we load data from form into contact object */
$list->setListName($formData->getListName());
$list->setXmlFile($formData->getXmlFile());
$list->setLinkURL($formData->getLinkURL());
/* we persist and save */
//$em->persist($contact);
$dem->flush();
$this->addFlash('notice', 'List was updated.');
return $this->redirectToRoute('listEdit', array('listId' => $list->getListId()));
}
}
/* we render data */
return $this->render('listEdit.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'formNewItems' => $formNewItemsBuilder->getForm()->createView(),
'form' => $formBuilder->getForm()->createView(),
'list' => $list,
'listItems' => $listItems,
'userDirs' => $userDirs,
'user' => $user,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
public function saveListXML(Request $request, $listId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load users entity manager */
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
//print('<br>user id: '.$userId);
//die('<br>qqw 22 user id: ');
$list = $dem->getRepository(CustomList::class)->getCustomList($listId);
$listItems = $dem->getRepository(CustomListItem::class)->getCustomListItems($listId);
if(!$this->isUserFolder($request)) {
$this->createUserFolder($request);
}
/* we get file name and paths */
$userDirs = $this->getUserFolderPaths($request);
if(!empty($list->getXmlFile())) {
$fileName = $list->getXmlFile();
} else {
$fileName = "list_".$listId.".xml";
}
/*
print('<br>QQW list ID: '.$listId);
\Doctrine\Common\Util\Debug::dump($list);
*/
$xmlDocument = new \DOMDocument('1.0', 'UTF-8');
$style = "
list { display: block; padding-left: 10px; }
listItem {
display: block;
}
listItem:hover {
display: block;
background-color: #EFEFEF;
}
.listItemTitle {
display: inline-block;
/* width: 300px; */
width: 45%;
height: 22px;
padding: 1px;
border: #DDD solid 1px;
background-color: #EFEFEF;
}
listItemShortDescription {
display: inline-block;
/* width: 300px; */
width: 45%;
height: 22px;
padding: 1px;
border: #DDD solid 1px;
/* background-color: #EFEFEF; */
}
listTitle {
font-family : Arial, Helvetica, sans-serif;
display: block;
font-size : 22px;
font-weight : bold;
padding-top: 5px;
padding-bottom: 5px;
height: 22px;
}
listItemAttribute1 {
font-family : Arial, Helvetica, sans-serif;
display: block;
font-size : 22px;
font-weight : bold;
padding-top: 5px;
padding-bottom: 5px;
height: 22px;
}
listItemAttribute2 {
font-family : Arial, Helvetica, sans-serif;
display: block;
font-size : 22px;
font-weight : bold;
padding-top: 5px;
padding-bottom: 5px;
height: 22px;
}
";
$css = $xmlDocument->createProcessingInstruction("xml-stylesheet", "type=\"text/css\" href=\"https://www.vrcommerce.cz/css/list1.css\"");
//$css = $xmlDocument->createProcessingInstruction("xml-stylesheet", "type=\"text/css\" href=\"#style\"");
$xmlDocument->appendChild($css);
$rootElement = $xmlDocument->createElement('list');
$titleTag = $xmlDocument->createElement('listTitle', $list->getListName());
//$titleTag->setAttribute("class", "listTitle");
//$titleTag->setAttribute("style", "background-color: #EFEFEF;");
$rootElement->appendChild($titleTag);
//$styleTag = $xmlDocument->createElement('style', $style);
//$styleTag->setAttribute("type", "text/css");
//$styleTag->setAttribute("id", "style");
//<style type = "text/css">
//$rootElement->appendChild($styleTag);
$listItemsTag = $xmlDocument->createElement('listItems');
foreach($listItems as $listItem) {
$listItemsTag = $xmlDocument->createElement('listItem');
$listItemsTitleTag = $xmlDocument->createElement('listItemTitle', $listItem->getListItemName());
$listItemsShortDescriptionTag = $xmlDocument->createElement('listItemShortDescription', $listItem->getListItemShortDescription());
$listItemsTag->appendChild($listItemsTitleTag);
$listItemsTag->appendChild($listItemsShortDescriptionTag);
$listItemsLongDescriptionTag = $xmlDocument->createElement('listItemLongDescription');
$listItemsLongDescriptionTag->appendChild($xmlDocument->createCDATASection(html_entity_decode(strip_tags($listItem->getListItemLongDescription()))));
$listItemsTag->appendChild($listItemsLongDescriptionTag);
$listItemsAttribute1Tag = $xmlDocument->createElement('listItemAttribute1', $listItem->getFreeProperty1());
$listItemsAttribute2Tag = $xmlDocument->createElement('listItemAttribute2', $listItem->getFreeProperty2());
$listItemsTag->appendChild($listItemsAttribute1Tag);
$listItemsTag->appendChild($listItemsAttribute2Tag);
$rootElement->appendChild($listItemsTag);
}
$xmlDocument->appendChild($rootElement);
$xmlDocument->saveXML();
$xmlDocument->save($userDirs['user'].'/'.$fileName);
$list->setXmlFile($fileName);
$dem->persist($list);
$dem->flush();
/*
$response = new Response($xmlDocument->saveXML());
$response->headers->set('Content-Type', 'xml');
*/
//return $response;
/* we render data */
/*
return $this->render('listXML.html.php',
array( 'headerData' => $this -> getPageHeader($request),
'list' => $list,
'listItems' => $listItems,
)
);
*/
}
/**
* @Route("/listitemedit/{listItemId}", name="listItemEdit")
*/
public function listItemEditAction(Request $request, $listItemId)
{
/* 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 users entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$listItem = $dem->getRepository(CustomListItem::class)->getCustomListItem($listItemId);
$list = $dem->getRepository(CustomList::class)->getCustomList($listItem->getListId());
/*
print('<br>QQW list ID: '.$listId);
\Doctrine\Common\Util\Debug::dump($list);
*/
/* we build edit form */
$formBuilder = $this->createFormBuilder($listItem);
$formBuilder->add('listItemName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.list_item_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $listItem->getListItemName()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('listItemShortDescription', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.list_item_short_description'),
'attr' => array('class' => 'textarea_form', 'cols' => 55, 'rows' => 4, 'value' => $listItem->getListItemShortDescription()),
'label_attr' => array('class' => 'form_textarea_label'),
'data' => $listItem->getListItemShortDescription(),
));
$formBuilder->add('clickURL', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.link_url'),
'attr' => array('class' => 'text_form', 'size' => 53, 'value' => $listItem->getClickURL()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('listItemLongDescription', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.list_item_long_description'),
'attr' => array('class' => 'textarea_form', 'cols' => 101, 'rows' => 5, 'value' => $listItem->getListItemLongDescription()),
'label_attr' => array('class' => 'form_textarea_label'),
'data' => $listItem->getListItemLongDescription(),
));
$formBuilder->add('freeProperty1', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.list_item_free_property1'),
'attr' => array('class' => 'text_form', 'size' => 53, 'value' => $listItem->getFreeProperty1()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('freeProperty2', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('knowledgebase.list_item_free_property2'),
'attr' => array('class' => 'text_form', 'size' => 53, 'value' => $listItem->getFreeProperty2()),
'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
//print('<br>qqw post form 2: ');
$formData = $form->getData();
/* we load data from form into contact object */
$listItem->setListItemName($formData->getListItemName());
$listItem->setListItemShortDescription($formData->getListItemShortDescription());
$listItem->setListItemLongDescription($formData->getListItemLongDescription());
$listItem->setClickURL($formData->getClickURL());
$listItem->setFreeProperty1($formData->getFreeProperty1());
$listItem->setFreeProperty2($formData->getFreeProperty2());
/* we persist and save */
//$em->persist($contact);
$dem->flush();
$this->addFlash('notice', 'List item was updated.');
return $this->redirectToRoute('listEdit', array('listId' => $listItem->getListId()));
}
}
/* we render data */
return $this->render('listItemEdit.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'list' => $list,
'listItem' => $listItem,
'menu' => $this -> adminMenu($request),
'user' => $user,
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/tradeLead", name="tradeLead")
*/
public function tradeLeadAction(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');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* removing tradelead */
if(!empty($request->query->get('removeLead'))) {
$tradeLead = $dem->getRepository(TradeLead::class)->findOneBy(['tradeLeadId' => $request->query->get('removeLead')]);
if(!empty($tradeLead)) {
try {
$dem->remove($tradeLead);
//$em->persist($tradeLead);
$dem->flush();
//$tradeLead = $dem->getRepository(TradeLead::class)->removeTradeLead($request->query->get('removeLead'));
$this->addFlash('notice', 'Trade Lead was removed.');
} catch(\Doctrine\DBAL\DBALException $e) {
$this->addFlash('error', "This Trade Lead has connected services (orders etc.), so it can't be removed.");
}
}
}
/* import tradelead */
if(!empty($request->query->get('importLeads'))) {
print('<br>qqw import leads');
ini_set('max_execution_time', 1800);
set_time_limit(1800);
$mem = $this->doctrine->getManager('marketplace_em');
$marketplaceConn = $mem->getConnection('marketplace_conn');
$sql = "SELECT * FROM eshops e INNER JOIN eshops_description ed ON e.id_shop = ed.id_shop AND ed.title != ''";
$stmt = $marketplaceConn->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll();
foreach($result as $row) {
print('<hr>row: ');
\Doctrine\Common\Util\Debug::dump($row);
$tradeLead = $dem->getRepository(TradeLead::class)->findOneBy(array('externalId' => $row['id_shop']));
if(empty($tradeLead)) {
$tradeLead = new TradeLead;
}
$tradeLead->setTitle($row['title']);
$tradeLead->setDescription($row['description']);
$tradeLead->setNotes($row['notes']);
$tradeLead->setEmail($row['email']);
$tradeLead->setStatus($row['status']);
$tradeLead->setContactPersonEmail($row['email_director']);
$tradeLead->setLinkUrl($row['url']);
$tradeLead->setExternalId($row['id_shop']);
print('<br>tradeLead: ');
\Doctrine\Common\Util\Debug::dump($tradeLead);
/* we persist and save */
$dem->persist($tradeLead);
$dem->flush();
}
}
$tradeLeadList = $dem->getRepository(TradeLead::class)->findAll();
/* we render data */
return $this->render('tradeLeads.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'tradeLeadList' => $tradeLeadList,
'menu' => $this -> adminMenu($request),
'user' => $user,
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/tradeLeadExec", name="tradeLeadExec")
*/
public function tradeLeadExecAction(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 user */
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$userDirs = $this->getUserFolderPaths($request);
$selectedTradeLeads = array();
if(!empty($request->request->get('selectedTradeLeads'))) {
//print(' tradeleads POSTED');
$selectedTradeLeads = $request->request->get('selectedTradeLeads');
$leadList = json_encode($selectedTradeLeads);
//\Doctrine\Common\Util\Debug::dump($request->request->get('selectedTradeLeads'));
}
if(!empty($request->request->get('form')['leadList'])) {
$leadList = $request->request->get('form')['leadList'];
}
$emailSubject = '';
if(!empty($request->request->get('form')['emailSubject'])) {
$emailSubject = $request->request->get('form')['emailSubject'];
}
$emailBodyHtml = '';
if(!empty($request->request->get('form')['emailBodyHtml'])) {
$emailBodyHtml = $request->request->get('form')['emailBodyHtml'];
}
//Doctrine\Common\Util\Debug::dump($request->request->get('selectedTradeLeads'));
//$tradeLeadList = $dem->getRepository(TradeLead::class)->findAll();
/* we build edit form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('emailSubject', TextType::class, array(
'required' => false,
'label' => 'email subject',
'attr' => array('class' => 'text_form', 'size' => 70, 'value' => $emailSubject),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('emailBodyHtml', CKEditorType::class, array(
'required' => false,
'label' => 'html email',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $emailBodyHtml),
'label_attr' => array('class' => 'form_field_label'),
'data' => $emailBodyHtml,
));
$formBuilder->add('leadList', HiddenType::class, array(
'data' => $leadList,
));
$formBuilder->add('save', SubmitType::class, array('label' => 'Execute Action',
'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>tradeleads ids json: ');
//print_r($request->request->get('form')['selectedTradeLeads']);
$leadIdList = json_decode($request->request->get('form')['leadList']);
foreach($leadIdList as $leadId) {
$tradeLead = $dem->getRepository(TradeLead::class)->findOneBy(array('tradeLeadId' => $leadId));
print('<hr>executing on lead: '.$tradeLead->getTitle().' , id: '.$leadId);
//Doctrine\Common\Util\Debug::dump($tradeLead);
//print_r($tradeLead);
$now = new \DateTime();
$nowDate = $now->format('Y-m-d H:i:s');
if(!empty($tradeLead->getEmail())) {
$to = $tradeLead->getEmail();
$subject = $emailSubject;
$message = $emailBodyHtml;
$name = $user->getCompany();
$from = $user->getEmail();
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: {$name} <{$from}>\r\n";
$headers .= "Reply-To: <{$from}>\r\n";
$headers .= "Subject: {$subject}\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
/* we send email to e-shop admin */
if(@mail($to, $subject, $message, $headers)) {
$message = '['.$nowDate.'] Email `'.$emailSubject.'` was sent to: '.$to;
print('<br>'.$message);
$tradeLead->setNotes($tradeLead->getNotes()."\n".$message);
} else {
print('<br>Email was not sent to: '.$to);
}
}
if(!empty($tradeLead->getContactPersonEmail())) {
$to = $tradeLead->getContactPersonEmail();
$subject = $emailSubject;
$message = $emailBodyHtml;
$name = $user->getCompany();
$from = $user->getEmail();
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: {$name} <{$from}>\r\n";
$headers .= "Reply-To: <{$from}>\r\n";
$headers .= "Subject: {$subject}\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
/* we send email to e-shop admin */
if(@mail($to, $subject, $message, $headers)) {
$message = '['.$nowDate.'] Email `'.$emailSubject.'` was sent to: '.$to;
print('<br>'.$message);
$tradeLead->setNotes($tradeLead->getNotes()."\n".$message);
} else {
print('<br>Email was not sent to: '.$to);
}
}
$dem->persist($tradeLead);
$dem->flush();
}
//Doctrine\Common\Util\Debug::dump($request->request->get('form')['emailSubject']);
$this->addFlash('notice', 'Trade Lead Action was executed.');
}
}
/* we render data */
return $this->render('tradeLeadExec.html.php',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'selectedTradeLeads' => $selectedTradeLeads,
'leadList' => $leadList,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/tradeleadedit/{tradeLeadId}", name="tradeLeadEdit")
*/
public function tradeLeadEditAction(Request $request, $tradeLeadId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$tradeLead = $dem->getRepository(TradeLead::class)->findOneBy(array('tradeLeadId' => $tradeLeadId));
/* removing tradelead */
if(!empty($request->query->get('createEshopLink'))) {
print('<br>createEshopLink ...');
$eshopLink = new EshopLink;
$eshopLink->setEshopLinkName($tradeLead->getTitle());
$eshopLink->setEshopLinkUrl($tradeLead->getLinkUrl());
$eshopLink->addLanguage($session->get('lang'));
$em->persist($eshopLink);
$em->flush();
$this->addFlash('notice', 'New Eshop Link was created.');
}
/* we build edit form */
$formBuilder = $this->createFormBuilder($tradeLead);
$formBuilder->add('title', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('marketplace.trade_lead_title'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getTitle()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('company', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.middle_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getCompany()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('email', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.last_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getEmail()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('linkUrl', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.middle_name'),
'attr' => array('class' => 'text_form', 'size' => 91, 'value' => $tradeLead->getLinkUrl()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('description', TextareaType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.list_item_short_description'),
'attr' => array('class' => 'textarea_form', 'cols' => 90, 'rows' => 10, 'value' => $tradeLead->getDescription()),
'label_attr' => array('class' => 'form_textarea_label'),
'data' => $tradeLead->getDescription(),
));
$formBuilder->add('notes', TextareaType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.list_item_short_description'),
'attr' => array('class' => 'textarea_form', 'cols' => 90, 'rows' => 10, 'value' => $tradeLead->getNotes()),
'label_attr' => array('class' => 'form_textarea_label'),
'data' => $tradeLead->getNotes(),
));
$formBuilder->add('contactPerson', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.company_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getContactPerson()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('contactPersonEmail', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.email'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getContactPersonEmail()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('telephone', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.email'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getTelephone()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('address', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 91, 'value' => $tradeLead->getAddress()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('invoiceAddress', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getInvoiceAddress()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('responsibleAdminUserId', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getResponsibleAdminUserId()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('dateResponsibilityGiven', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getDateResponsibilityGiven()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('status', TextType::class, array(
'required' => false,
//label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getStatus()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('serverId', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getServerId()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('areaId', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getAreaId()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('preferredSectionId', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getPreferredSectionId()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('preferredSectionId2', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getPreferredSectionId2()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('avatarUrl', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getAvatarUrl()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('logoUrl', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getLogoUrl()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('bankAccount', TextType::class, array(
'required' => false,
//'label' => $this->translator->trans('knowledgebase.phone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $tradeLead->getBankAccount()),
'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()) {
$formData = $form->getData();
/* we load data from form into TradeLead object */
$tradeLead->setTitle($formData->getTitle());
$tradeLead->setCompany($formData->getCompany());
$tradeLead->setEmail($formData->getEmail());
$tradeLead->setLinkUrl($formData->getLinkUrl());
$tradeLead->setContactPerson($formData->getContactPerson());
$tradeLead->setContactPersonEmail($formData->getContactPerson());
$tradeLead->setTelephone($formData->getTelephone());
$tradeLead->setNotes($formData->getNotes());
$tradeLead->setDescription($formData->getDescription());
$tradeLead->setAddress($formData->getAddress());
$tradeLead->setInvoiceAddress($formData->getInvoiceAddress());
$tradeLead->setResponsibleAdminUserId($formData->getResponsibleAdminUserId());
//$tradeLead->setDateResponsibilityGiven($request->request->get('form')['dateResponsibilityGiven']);
$tradeLead->setStatus($formData->getStatus());
$tradeLead->setServerId($formData->getServerId());
$tradeLead->setAreaId($formData->getAreaId());
$tradeLead->setPreferredSectionId($formData->getPreferredSectionId());
$tradeLead->setPreferredSectionId2($formData->getPreferredSectionId2());
$tradeLead->setAvatarUrl($formData->getAvatarUrl());
$tradeLead->setLogoUrl($formData->getLogoUrl());
$tradeLead->setBankAccount($formData->getBankAccount());
/* we persist and save */
$dem->persist($tradeLead);
$dem->flush();
$this->addFlash('notice', 'Trade Lead was updated.');
return $this->redirectToRoute('tradeLeadEdit', array('tradeLeadId' => $tradeLead->getTradeLeadId()));
}
}
/* we render data */
return $this->render('tradeLeadEdit.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'tradeLead' => $tradeLead,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'user' => $user
)
);
}
/**
* @Route("/tradeLeadNew", name="tradeLeadNew")
*/
public function tradeLeadNewAction(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');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we build login form */
$tradeLead = new TradeLead();
$formBuilder = $this->createFormBuilder($tradeLead);
$formBuilder->add('title', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('marketplace.trade_lead_title'),
'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');
$formData = $form->getData();
$tradeLead->setTitle($formData->getTitle());
/* we persist and save */
$dem->persist($tradeLead);
$dem->flush();
$this->addFlash('notice', 'New Trade lead was created.');
return $this->redirectToRoute('tradeLeadEdit', array('tradeLeadId' => $tradeLead->getTradeLeadId()));
}
}
/* we render data */
return $this->render('tradeLeadNew.html.twig',
array( 'form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'user' => $user
)
);
}
public function adminMenu(Request $request)
{
$menuItems = array(
1 => array('link' => 'knowledgebaseAdmin', 'langKey' => 'knowledgebase.admin', 'routeName' => 'knowledgebaseAdmin'),
2 => array('link' => 'contacts', 'langKey' => 'knowledgebase.contacts', 'routeName' => 'contacts'),
3 => array('link' => 'contactnew', 'langKey' => 'knowledgebase.new_contact', 'routeName' => 'contactNew'),
4 => array('link' => 'tasks', 'langKey' => 'knowledgebase.tasks', 'routeName' => 'tasks'),
5 => array('link' => 'tasknew', 'langKey' => 'knowledgebase.new_task', 'routeName' => 'taskNew'),
6 => array('link' => 'lists', 'langKey' => 'knowledgebase.lists', 'routeName' => 'lists'),
7 => array('link' => 'listnew', 'langKey' => 'knowledgebase.new_list', 'routeName' => 'listNew'),
);
return $menuItems;
}
}