src/Controller/DodajMenuController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpKernel\KernelInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use App\Service\menuservice;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\Security\Core\Security;
  11. use FileUploader;
  12. class DodajMenuController extends AbstractController
  13. {
  14.     /**
  15.     * @var menuservice
  16.     */
  17.     private $apiMenu;
  18.     public $rootDir;
  19.     public $security;
  20.     public function __construct(menuservice $menuserviceKernelInterface $kernelSecurity $security)
  21.     {
  22.         $this->apiMenu $menuservice;
  23.         $this->rootDir $kernel->getProjectDir();
  24.         $this->security $security;
  25.     }
  26.     
  27.     
  28.     /**
  29.      * @Route("/dodaj/menu/{id}/{lang}", name="app_dodaj_menu")
  30.      */
  31.     public function index($id$lang): Response
  32.     {
  33.         
  34.         $user $this->security->getUser();
  35.         
  36.         file_put_contents("security.log"print_r($user->getFolder(), true));
  37.         
  38.         return $this->render('dodaj_menu/index.html.twig', [
  39.             'controller_name' => 'DodajMenuController',
  40.             'menu_parent_g' => $id,
  41.             'menu_lang_g' => $lang
  42.         ]);
  43.     }
  44.     /**
  45.      * @Route("/dodajmenucall", name="dodajmenucall")
  46.      */
  47.     public function dodajmenucall(): Response
  48.     {
  49.         $menu_title $_POST['menu_title'];
  50.         $menu_content $_POST['menu_content'];
  51.         $menu_parent $_POST['menu_parent'];
  52.         $menu_top $_POST['menu_top'];
  53.         $menu_footer $_POST['menu_footer'];
  54.         $language_id $_POST['menu_lang'];
  55.         $menu_visible $_POST['menu_visible'];
  56.         
  57.         try{
  58.             $menu_image $_POST['menu_image'];
  59.         }
  60.         catch(\Exception $e){
  61.             $menu_image "";
  62.         }
  63.         if ($menu_top == 'true')
  64.         {
  65.             $menu_top '1';
  66.         }
  67.         else
  68.         {
  69.             $menu_top '0';
  70.         }
  71.         if ($menu_footer == 'true')
  72.         {
  73.             $menu_footer '1';
  74.         }
  75.         else
  76.         {
  77.             $menu_footer '0';
  78.         }
  79.         file_put_contents("menuvisible.log"$menu_visible);
  80.         if ($menu_visible == 'true')
  81.         {
  82.             $menu_visible '1';
  83.         }
  84.         else
  85.         {
  86.             $menu_visible '0';
  87.         }
  88.         $this->apiMenu->insertMenu($menu_title$menu_content$menu_parent$language_id$menu_top$menu_footer$menu_image$menu_visible);
  89.         return new JsonResponse(array('data' => "Borut"));
  90.     }
  91.     /**
  92.      * @Route("/dodajmenuuploadimage", name="dodajmenuuploadimagecall")
  93.      */
  94.     public function addMenuUploadImage()
  95.     {
  96.         
  97.         $folder '';
  98.         //dobimo mapo v kateri folder naj naložimo sliko
  99.         $user $this->security->getUser();
  100.         
  101.         $folder $user->getFolder();
  102.         
  103.         $ltrgovina_id $_POST['menu_id'];
  104.         if ($user->getFolder() == 'mki')
  105.         {
  106.             $folder 'strah';
  107.         }
  108.         
  109.         /*$FileUploader = new FileUploader('datotekaInput', array(
  110.             'limit' => null,
  111.             'fileMaxSize' => null,
  112.             'extensions' => null,
  113.             'uploadDir' => $this->rootDir .'/uploads/' . $user->getFolder() .'/',
  114.             'title' => 'name'
  115.         ));*/
  116.         file_put_contents("datoteka.log"$this->rootDir .'/public/uploads/' $folder .'/');
  117.         $FileUploader = new FileUploader('datotekaInput', array(
  118.             'limit' => null,
  119.             'fileMaxSize' => null,
  120.             'extensions' => null,
  121.             'uploadDir' => $this->rootDir .'/public/uploads/' $folder .'/',
  122.             'title' => 'name'
  123.         ));
  124.         
  125.         // call to upload the files
  126.         $data $FileUploader->upload();
  127.         /*file_put_contents("status.log", "4");
  128.         file_put_contents("uploader.log", print_r($data, true));
  129.         file_put_contents("uploaderfile.log", print_r($data['files'][0]['file'], true));*/
  130.         file_put_contents("datotekareturn.log"print_r($datatrue));
  131.         $lfilefrom $data['files'][0]['file'];
  132.         $path_parts pathinfo($lfilefrom);
  133.         $ldirname =  $path_parts['dirname'];
  134.         $lbasename $path_parts['basename'];
  135.         $lextension =  $path_parts['extension'];
  136.         $lfilename =  $path_parts['filename'];
  137.         $lfilenamemd5 md5($lfilename);
  138.         /*
  139.         $lfile800 = '800-' . $lfilenamemd5. '.' .$lextension;
  140.         $lfile300 = '300-' . $lfilenamemd5. '.' .$lextension;
  141.         $lfile350 = '350-' . $lfilenamemd5. '.' .$lextension;
  142.         copy($lfilefrom,'/home/telefonika/domains/telefonika.si/public_html/admin_backend/uploads/zff_images/' . $lfile800);
  143.         copy($lfilefrom,'/home/telefonika/domains/telefonika.si/public_html/admin_backend/uploads/zff_images/' . $lfile300);
  144.         copy($lfilefrom,'/home/telefonika/domains/telefonika.si/public_html/admin_backend/uploads/zff_images/' . $lfile350);
  145.         
  146.        
  147.         
  148.         $data['files'][0]['name'] = $lfilenamemd5 . '.' . $lextension;
  149.         file_put_contents("uploaderfile1.log", print_r($data, true));
  150.         
  151.          */
  152.         $from $this->rootDir .'/public/uploads/' $folder .'/' $lfilename '.'$lextension;
  153.         $to $this->rootDir .'/public/uploads/' $folder .'/' '1000-' .$lfilename .'.'.$lextension;
  154.         $to800 $this->rootDir .'/public/uploads/' $folder .'/' '800-' .$lfilename .'.'.$lextension;
  155.         
  156.         copy($from$to);
  157.         copy($from$to800);
  158.         return new JsonResponse(array($data));
  159.     }
  160. }