src/Controller/FaqController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use symfony\Component\Routing\Annotation\Route;
  7. use Pimcore\Model\DataObject;
  8. use Pimcore\Model\Asset\Service;
  9. use Pimcore\Model\DataObject\Service as DoService;
  10. use Carbon\Carbon;
  11. class FaqController extends FrontendController
  12. {
  13.     public function generateAssetFolder($folderName){
  14.         $yr date("Y");
  15.         $mt date("M");
  16.         $dy date("d");
  17.         $path "/".$folderName."/".$yr."/".$mt."/".$dy;
  18.         // $createAssetFolder = DoService::createFolderByPath("/Prod");die;
  19.         // $object = DataObject::getByPath("/Product");
  20.         $object \Pimcore\Model\Asset::getByPath($path);
  21.         if(!$object){
  22.             $path1 "/".$folderName."/".$yr."/".$mt;
  23.             $object1 \Pimcore\Model\Asset::getByPath($path1);
  24.             if(!$object1){
  25.                 $path2 "/".$folderName."/".$yr;
  26.                 $object2 \Pimcore\Model\Asset::getByPath($path2);                
  27.                 if(!$object2){
  28.                     $path3 "/".$folderName;
  29.                     $object3 \Pimcore\Model\Asset::getByPath($path3);                
  30.                     if(!$object3){
  31.                         $createAssetFolder Service::createFolderByPath($path3);
  32.                         $createAssetFolder Service::createFolderByPath($path2);
  33.                         $createAssetFolder Service::createFolderByPath($path1);
  34.                         $createAssetFolder Service::createFolderByPath($path);
  35.                         $objParentId $createAssetFolder->getId();
  36.                     }else {
  37.                         $createAssetFolder Service::createFolderByPath($path2);
  38.                         $createAssetFolder Service::createFolderByPath($path1);
  39.                         $createAssetFolder Service::createFolderByPath($path);
  40.                         $objParentId $createAssetFolder->getId();
  41.                     }
  42.                 }else {
  43.                     $createAssetFolder Service::createFolderByPath($path1);
  44.                     $createAssetFolder Service::createFolderByPath($path);
  45.                     $objParentId $createAssetFolder->getId();
  46.                 }
  47.             } else {
  48.                 $createAssetFolder Service::createFolderByPath($path);
  49.                 $objParentId $createAssetFolder->getId();
  50.             }
  51.         } else
  52.         $objParentId $object->getId();
  53.         return $objParentId;
  54.     }
  55.     public function generateObjFolder($folderName){
  56.         $yr date("Y");
  57.         $mt date("M");
  58.         $dy date("d");
  59.         $path "/".$folderName."/".$yr."/".$mt."/".$dy;
  60.         $object DataObject::getByPath($path);
  61.         if(!$object){
  62.             $path1 "/".$folderName."/".$yr."/".$mt;
  63.             $object1 DataObject::getByPath($path1);
  64.             if(!$object1){
  65.                 $path2 "/".$folderName."/".$yr;
  66.                 $object2 DataObject::getByPath($path2);                
  67.                 if(!$object2){
  68.                     $path3 "/".$folderName;
  69.                     $object3 DataObject::getByPath($path3);                
  70.                     if(!$object3){
  71.                         $createAssetFolder DoService::createFolderByPath($path3);
  72.                         $createAssetFolder DoService::createFolderByPath($path2);
  73.                         $createAssetFolder DoService::createFolderByPath($path1);
  74.                         $createAssetFolder DoService::createFolderByPath($path);
  75.                         $objParentId $createAssetFolder->getId();
  76.                     }else {
  77.                         $createAssetFolder DoService::createFolderByPath($path2);
  78.                         $createAssetFolder DoService::createFolderByPath($path1);
  79.                         $createAssetFolder DoService::createFolderByPath($path);
  80.                         $objParentId $createAssetFolder->getId();
  81.                     }
  82.                 }else {
  83.                     $createAssetFolder DoService::createFolderByPath($path1);
  84.                     $createAssetFolder DoService::createFolderByPath($path);
  85.                     $objParentId $createAssetFolder->getId();
  86.                 }
  87.             } else {
  88.                 $createAssetFolder DoService::createFolderByPath($path);
  89.                 $objParentId $createAssetFolder->getId();
  90.             }
  91.         } else
  92.         $objParentId $object->getId();
  93.         return $objParentId;
  94.     }
  95.     /**
  96.      * @param Request $request
  97.      * 
  98.      * @Route("/createItcFaq")
  99.      * 
  100.      * @return Response
  101.      * 
  102.      */
  103.     public function createItcFaqAction(Request $request): Response
  104.     {
  105.         
  106.         $faqId $request->get('faqId');
  107.         $locationcode $request->get('locationcode');
  108.         $fqaQuestion $request->get('faqQuestion');
  109.         $faqAnswer $request->get('faqAnswer');
  110.         $faqType $request->get('faqType');
  111.         $createAssetFolder DoService::createFolderByPath('FAQ');
  112.         $objParentId $createAssetFolder->getId();
  113.         
  114.         if(!empty($faqId)){
  115.             $location_code_array DataObject\Locations::getById($locationcode);
  116.             $holidayObjectName $faqId;
  117.             //--------- Check data -------------//
  118.             $msg='';
  119.             $checkDataList DataObject\ItcAddFaq::getList();
  120.             if ($checkDataList->getClass()->getFieldDefinition('faqId')->isFilterable()) {
  121.                 $checkDataList->filterByfaqId($faqId'=');
  122.             }
  123.             
  124.             $checkDataList->load();
  125.             if(count($checkDataList) > 0){
  126.                 $msg .= $faqId.',';
  127.             }
  128.             //--------- End of Check data -------------//
  129.             $succ_msg='';
  130.             if($msg == '')
  131.             {
  132.                 //Create a new object
  133.                 $newObject = new DataObject\ItcAddFaq(); 
  134.                 $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($holidayObjectName'object'));
  135.                 $newObject->setParentId($objParentId);
  136.                 $newObject->setfaqId($faqId);
  137.                 $newObject->setlocation_code($location_code_array->getlocation_name());  
  138.                 $newObject->setfaqQuestion($fqaQuestion);
  139.                 $newObject->setfaqAnswer($faqAnswer);
  140.                 $newObject->setfaqType($faqType);
  141.                 $newObject->setPublished(true);
  142.                 $newObject->save();
  143.                 $succ_msg 'Faq Created Successfully';
  144.             }
  145.             if($msg != '')
  146.             $msg substr($msg0, -1)." Faq(s) added already";
  147.             $succ_msg_data = ($msg && $succ_msg)?$msg.', '.$succ_msg:(($msg)?$msg:($succ_msg?$succ_msg:''));
  148.             $this->addFlash('success'$succ_msg_data);
  149.             $locationsList DataObject\Locations::getList();
  150.             $locationsList->load();
  151.             
  152.             $entries = new DataObject\ItcAddFaq\Listing();
  153.             return $this->render('faq/listing-faq.html.twig',['data' => $entries,'locationsList' => $locationsList ]);
  154.     
  155.         }else{
  156.             $entries = new DataObject\ItcAddFaq\Listing();
  157.             $locationsList DataObject\Locations::getList();
  158.             $locationsList->load();
  159.             return $this->render('faq/create-faq.html.twig',['data' => $entries,'locationsList' => $locationsList ]);
  160.         }
  161.          
  162.     }
  163.     /**
  164.      * @param Request $request
  165.      * 
  166.      * @Route("/itcfaqListingAction")
  167.      * 
  168.      * @return Response
  169.      * 
  170.      */
  171.     public function itcfaqListingAction(Request $request): Response
  172.     {
  173.         
  174.         
  175.         $locationsList DataObject\ItcAddFaq::getList();
  176.         $locationsList->load();
  177.         return $this->render('faq/listing-faq.html.twig',['data' => $locationsList,'locationsList' => $locationsList ]);
  178.    
  179.     }
  180.     /**
  181.      * @param Request $request
  182.      * 
  183.      * @Route("/editItcFaq/{id}")
  184.      * 
  185.      * @return Response
  186.      * 
  187.      */ 
  188.     public function editItcFaqAction($id) { 
  189.          
  190.         $entries DataObject\ItcAddFaq::getById($id); 
  191.         $locationsLists DataObject\Locations::getList();
  192.         $locationsLists->load();
  193.         $location_codes $entries->getlocation_code();
  194.         $locationsList = new DataObject\Locations\Listing();
  195.         $locationsList->setCondition("location_name = :name", ["name" => $location_codes]);
  196.         $locationsList->load();
  197.         foreach($locationsList as $locations){
  198.             $selected '';
  199.             if(!empty($hol_locs) && $hol_locs
  200.             $selected ' selected';
  201.             $locations->selected $selected;
  202.         }
  203.         $faqTypes = ['General''Loyalty'];
  204.         $faqTypes_list = [];
  205.         foreach($faqTypes as $faqType_info)
  206.         {
  207.             $selected=($entries->getfaqType() != '' && $entries->getfaqType() == $faqType_info)?'selected':'';
  208.             $faqTypes_list[] = ['faqType'=>$faqType_info,'s'=>$selected];
  209.         }
  210.         return $this->render('faq/edit-faq.html.twig'compact('entries','locationsList','locationsLists','faqTypes_list')); 
  211.     }
  212.     /**
  213.      * @param Request $request
  214.      * 
  215.      * @Route("/updateItcFaq")
  216.      * 
  217.      * @return Response
  218.      * 
  219.      */
  220.     public function updateItcFaqAction(Request $request): Response
  221.     {
  222.         $idfaq $request->get('idfaq');
  223.         $faqId $request->get('faqId');
  224.         $locationcode $request->get('locationcode');
  225.         $fqaQuestion $request->get('faqQuestion');
  226.         $faqAnswer $request->get('faqAnswer');
  227.         $faqType $request->get('faqType');
  228.         //--------- Check data -------------//
  229.         $msg='';
  230.         $checkDataList DataObject\ItcAddFaq::getList();
  231.         if ($checkDataList->getClass()->getFieldDefinition('faqId')->isFilterable()) {
  232.             $checkDataList->filterByfaqId($faqId'=');
  233.         }
  234.         
  235.         $checkDataList->load();
  236.         if(count($checkDataList) > 0){
  237.             foreach($checkDataList as $checkData)
  238.             {
  239.                 if($checkData->getId() != $idfaq)
  240.                     $msg .= $faqId.',';
  241.             }
  242.         }
  243.         //--------- End of Check data -------------//
  244.         $succ_msg='';
  245.         if($msg == '')
  246.         {
  247.             $locationsList DataObject\Locations::getList();
  248.             $locationsList->load();
  249.             $location_code_array DataObject\Locations::getById($locationcode);
  250.             //Create a new object
  251.             $newObject DataObject\ItcAddFaq::getById($idfaq); 
  252.             $newObject->setfaqId($faqId);
  253.             $newObject->setlocation_code($location_code_array->getlocation_name());  
  254.             $newObject->setfaqQuestion($fqaQuestion);
  255.             $newObject->setfaqAnswer($faqAnswer);
  256.             $newObject->setfaqType($faqType);
  257.             $newObject->setPublished(true);
  258.             $newObject->save();
  259.             $succ_msg 'Faq Updated Successfully';
  260.         }
  261.         if($msg != '')
  262.         $msg substr($msg0, -1)." Faq(s) added already";
  263.         $succ_msg_data = ($msg && $succ_msg)?$msg.', '.$succ_msg:(($msg)?$msg:($succ_msg?$succ_msg:''));
  264.         $this->addFlash('success'$succ_msg_data);
  265.         $list = new DataObject\ItcAddFaq\Listing();
  266.         return $this->render('faq/listing-faq.html.twig',['data' => $list ]);
  267.     
  268.     }
  269.     /**
  270.      * @param Request $request
  271.      * 
  272.      * @Route("/deleteItcFaq/{id}")
  273.      * 
  274.      * @return Response
  275.      * 
  276.      */
  277.     public function deleteItcFaqAction($id
  278.     { 
  279.        
  280.         $entries DataObject\ItcAddFaq::getById($id); 
  281.         $delete $entries->delete();
  282.         if($delete){
  283.             $list = new DataObject\ItcAddFaq\Listing();
  284.         }else{
  285.             $list = new DataObject\ItcAddFaq\Listing();
  286.         }
  287.         $locationsList DataObject\Locations::getList();
  288.         $locationsList->load();
  289.         return $this->render('faq/listing-faq.html.twig',['data' => $list ]);
  290.         
  291.     }
  292.     /**
  293.      * @param Request $request
  294.      * 
  295.      * @Route("/faqApi",methods={"POST"})
  296.      * 
  297.      * @return Response
  298.      * 
  299.      */
  300.     public function faqApiAction(Request $request)
  301.     { 
  302.        
  303.        $createAssetFolder DoService::createFolderByPath('Location');
  304.        $objParentId $createAssetFolder->getId();
  305.        $locationcode = (!empty($request->get('location_code')))?$request->get('location_code'):'';
  306.     //    $faqType = (!empty($request->get('type')))?$request->get('type'):'';
  307.         $loc_name $loc_code '';
  308.        $faqType = (!empty($request->get('type')) && $request->get('type') == 'All')?'':((!empty($request->get('type')) && $request->get('type') != 'All')?$request->get('type'):'General');
  309.        $entries = new DataObject\ItcAddFaq\Listing();
  310.        if($faqType != '')
  311.        $entries->setCondition("faqType = :faqType", ["faqType" => $faqType]);
  312.        $entries->load();
  313.        $data = array();
  314.        foreach($entries as $key => $entrie){
  315.         if($locationcode != ''){
  316.             $location = new DataObject\Locations\Listing();
  317.             $location->setCondition("location_name = :name", ["name" => $locationcode]);
  318.             $location->load();
  319.             $loc_name '';
  320.             $loc_code '';
  321.             foreach($location as $location_code){
  322.                 
  323.                 $loc_name $location_code->getlocation_name();
  324.                 $loc_code $location_code->getlocation_code();
  325.             
  326.             }
  327.         }
  328.          if($loc_name == '' && $loc_code == '' && $entrie->getlocation_code()){
  329.             $locationInfo DataObject\Locations::getBylocation_name($entrie->getlocation_code(), 1);
  330.              
  331.             $loc_name $locationInfo->getlocation_name();
  332.             $loc_code $locationInfo->getlocation_code();
  333.          }
  334.          $data[] = array("faqId" => $entrie->getfaqId(),
  335.                  "location_code" => $loc_code,
  336.                  "location_name" => $loc_name,
  337.                  "faqQuestion" => $entrie->getfaqQuestion(),
  338.                  "faqAnswer" => $entrie->getfaqAnswer(),
  339.                  "Type" => $entrie->getfaqType(),
  340.          );
  341.        }
  342.        return $this->json(["success" => true"data" => $data]);
  343.        
  344.     }
  345.     
  346. }