src/Controller/EditContentController.php line 55

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\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Doctrine\DBAL\Connection;
  10. use App\Service\contentservice;
  11. use App\Service\generalservice;
  12. use App\Service\menuservice;
  13. use \FileUploader;
  14. use Symfony\Component\Security\Core\Security;
  15. class EditContentController extends AbstractController
  16. {
  17.     /**
  18.     * @var contentservice
  19.     */
  20.     /**
  21.     * @var generalservice
  22.     */
  23.     /**
  24.     * @var menuservice
  25.     */
  26.     
  27.     private $apiContent;
  28.     private $apiGeneral;
  29.     private $apiMenu;
  30.     public $rootDir;
  31.     public $security;
  32.     public function __construct(contentservice $contentservicegeneralservice $generalservice,menuservice $menuserviceKernelInterface $kernelSecurity $security)
  33.     {
  34.         $this->apiContent $contentservice;
  35.         $this->apiGeneral $generalservice;
  36.         $this->apiMenu $menuservice;
  37.         $this->rootDir $kernel->getProjectDir();
  38.         $this->security $security;
  39.     }
  40.     /**
  41.      * @Route("/editcontent/{id}", name="edit_content")
  42.      */
  43.     public function index($id)
  44.     {
  45.         $lUser $this->getUser();
  46.         $lUserID $lUser->getId();
  47.         $lModul explode(",",$lUser->getModul());
  48.         if (!in_array("Content"$lModul))
  49.         {
  50.             return $this->redirectToRoute('app_homepage');
  51.         }
  52.         $content $this->apiContent->getContentByID($id);
  53.        
  54.         $lLogsContent $this->apiContent->getLogsContent($id);
  55.         $lResponseLogs = new JsonResponse(array('data' => $lLogsContent));
  56.         file_put_contents('api/dataLogsContent_'.$id.'.json'$lResponseLogs->getContent());
  57.         $menu $this->apiMenu->generateMenu(0,$content[0]['language_id'], $id,$lUser->getCompany());
  58.         
  59.         file_put_contents("MENU.log"print_r($menutrue));
  60.         return $this->render('edit_content/edit_content.html.twig', [
  61.             'controller_name' => 'EditContentController',
  62.             'content' => $content,
  63.             'id' => $id,
  64.             'menu' => $menu
  65.         ]);
  66.     }
  67.     /**
  68.      * @Route("/content/refreshlogs", name="editcontent_refreshlogs")
  69.      */
  70.     public function editContentRefreshLogs(Request $request)
  71.     {        
  72.         $lcontent_id $_POST['content_id'];
  73.         
  74.         $lLogsContent $this->apiContent->getLogsContent($lcontent_id);
  75.         $lResponseLogs = new JsonResponse(array('data' => $lLogsContent));
  76.         file_put_contents('api/dataLogsContent_'.$lcontent_id.'.json'$lResponseLogs->getContent());
  77.         return new JsonResponse($lcontent_id);
  78.     }
  79.     /**
  80.      * @Route("/content/savecontent", name="editcontent_savecontent")
  81.      */
  82.     public function editContentSaveContent(Request $request)
  83.     {        
  84.         file_put_contents("DREVO.log""1" );
  85.         $lUser $this->getUser();
  86.         $lUserID $lUser->getId();
  87.         
  88.         $lcontent_id $_POST['content_id'];
  89.         $lcontent_title $_POST['content_title'];
  90.         $lcontent_notes $_POST['content_notes'];
  91.         $llanguage_id $_POST['language_id'];
  92.         $lengine_id $_POST['engine_id'];
  93.         $lcontent_image $_POST['content_image'];
  94.         $llog_decription $_POST['log_decription'];
  95.         $lTreemenu $_POST['treemenu'];
  96.         
  97.         $this->apiContent->content_id $lcontent_id;
  98.         $this->apiContent->content_title $lcontent_title;
  99.         $this->apiContent->content_notes $lcontent_notes;
  100.         $this->apiContent->language_id $llanguage_id;
  101.         $this->apiContent->engine_id $lengine_id;
  102.         $this->apiContent->content_image $lcontent_image;
  103.         $this->apiContent->treemenu $lTreemenu;
  104.     
  105.         $this->apiContent->saveContent();
  106.         $this->apiGeneral->ClearLog();
  107.         $this->apiGeneral->content_id $lcontent_id;
  108.         $this->apiGeneral->action_id 3;
  109.         $this->apiGeneral->log_description $llog_decription;
  110.         $this->apiGeneral->user_id $lUserID;
  111.         $this->apiGeneral->AddLog();
  112.         
  113.         return new JsonResponse(array('data' => "ok"));
  114.     }
  115.     /**
  116.      * @Route("/content/showform", name="editcontent_showform")
  117.      */
  118.     public function editContentShowForm(Request $request)
  119.     {   
  120.         $lcontent_id $_POST['content_id'];
  121.         
  122.         $this->apiContent->content_id $lcontent_id;
  123.         $lForm $this->apiContent->showForm();
  124.         
  125.         return new JsonResponse($lForm);
  126.     }
  127.     /**
  128.      * @Route("/content/getpreloadedphotos", name="editcontent_getpreloadedphotos")
  129.      */
  130.     public function GetPreloadedPhotos(Request $request)
  131.     {
  132.         $lcontent_id $_POST['content_id'];
  133.     
  134.         $this->apiContent->content_id $lcontent_id;
  135.         $lPhotos $this->apiContent->getPreloadedPhotos($lcontent_id);
  136.         
  137.         return new Response(json_encode($lPhotos));
  138.     }
  139.     /**
  140.      * @Route("/content/getpreloadeddocs", name="editcontent_getpreloadeddocs")
  141.      */
  142.     public function GetPreloadedDocs(Request $request)
  143.     {
  144.         $lcontent_id $_POST['content_id'];
  145.     
  146.         $this->apiContent->content_id $lcontent_id;
  147.         $lDocs $this->apiContent->getPreloadedDocs($lcontent_id);
  148.         return new Response(json_encode($lDocs));
  149.     }
  150.     /**
  151.      * @Route("/content/uploadimage", name="editcontent_uploadimage")
  152.      */
  153.     public function editContentUploadImage()
  154.     {
  155.         $folder '';
  156.         //dobimo mapo v kateri folder naj naložimo sliko
  157.         $user $this->security->getUser();
  158.         $folder $user->getFolder();
  159.         
  160.         if ($user->getFolder() == 'mki')
  161.         {
  162.             $folder 'strah';
  163.         }
  164.         
  165.         
  166.         //test
  167.         $lcontent_id $_POST['content_id'];
  168.         
  169.         $FileUploader = new FileUploader('content_image', array(
  170.             'limit' => null,
  171.             'fileMaxSize' => null,
  172.             'extensions' => null,
  173.             'uploadDir' => $this->rootDir .'/public/uploads/' $folder .'/',
  174.             'title' => 'name'
  175.         ));
  176.         // call to upload the files
  177.         $data $FileUploader->upload();
  178.         $lfilefrom $data['files'][0]['file'];
  179.         $path_parts pathinfo($lfilefrom);
  180.         $ldirname =  $path_parts['dirname'];
  181.         $lbasename $path_parts['basename'];
  182.         $lextension =  $path_parts['extension'];
  183.         $lfilename =  $path_parts['filename'];
  184.         $from $this->rootDir .'/public/uploads/' $folder .'/' $lfilename '.'$lextension;
  185.         $to $this->rootDir .'/public/uploads/' $folder .'/' '1000-' .$lfilename .'.'.$lextension;
  186.         $to800 $this->rootDir .'/public/uploads/' $folder .'/' '800-' .$lfilename .'.'.$lextension;
  187.         
  188.         copy($from$to);
  189.         copy($from$to800);
  190.         //copy($this->rootDir .'/public/uploads/' . $folder .'/','/home/telefonika/domains/telefonika.si/public_html/admin_backend/uploads/zff_images/' . $lfile300);
  191.         //copy($lfilefrom,'/home/telefonika/domains/telefonika.si/public_html/admin_backend/uploads/zff_images/' . $lfile350);
  192.     
  193.         return new JsonResponse(array($data));
  194.     }
  195.     /**
  196.      * @Route("/content/getpreloadedimage", name="editcontent_getpreloadedimage")
  197.      */
  198.     public function editContentGetPreloadedImage(Request $request)
  199.     {
  200.         $lcontent_id $request->get('id');
  201.     
  202.         $this->apiContent->content_id $lcontent_id;
  203.         $lImage $this->apiContent->getPreloadedImage();
  204.         return new JsonResponse($lImage);
  205.     }
  206.     /**
  207.      * @Route("/content/savefield", name="editcontent_savefield")
  208.      */
  209.     public function editContentSaveField(Request $request)
  210.     {        
  211.         $lUser $this->getUser();
  212.         $lUserID $lUser->getId();
  213.         
  214.         $lcontent_id $_POST['content_id'];
  215.         $lcontentform_id $_POST['contentform_id'];
  216.         $lcontentform_value $_POST['contentform_value'];
  217.         $loldvalue $_POST['oldvalue'];
  218.         if ($loldvalue != "")
  219.         {
  220.             $loldvalue '(stara vrednost: '.$loldvalue.')';
  221.         }
  222.         $lTreemenu $_POST['treemenu'];
  223.         
  224.         
  225.         $this->apiContent->content_id $lcontent_id;
  226.         $this->apiContent->contentform_id $lcontentform_id;
  227.         $this->apiContent->contentform_value $lcontentform_value;
  228.         $this->apiContent->treemenu $lTreemenu;
  229.         $this->apiContent->saveField();
  230.         
  231.         $this->apiGeneral->ClearLog();
  232.         $this->apiGeneral->content_id $lcontent_id;
  233.         $this->apiGeneral->action_id 4;
  234.         $this->apiGeneral->log_description $lcontentform_value;
  235.         $this->apiGeneral->user_id $lUserID;
  236.         $this->apiGeneral->AddLog();
  237.         return new JsonResponse(array('data' => "Borut"));
  238.     }
  239.     /**
  240.      * @Route("/content/publishcontent", name="editcontent_publishcontent")
  241.      */
  242.     public function editContentPublishContent(Request $request)
  243.     {        
  244.         $luser $this->getUser()->getId();
  245.         $lcontent_id $_POST['content_id'];
  246.         
  247.         $this->apiContent->content_id $lcontent_id;
  248.         $lok $this->apiContent->publishContent();
  249.         return new JsonResponse($lok);
  250.     }
  251.     /**
  252.      * @Route("/content/savetinymce", name="editcontent_savetinymce")
  253.      */
  254.     public function editContensavetinymce(Request $request)
  255.     {        
  256.         $content_id $_POST['content_id'];
  257.         $content_tinymce $_POST['content_tinymce'];
  258.         
  259.         $this->apiContent->content_id $content_id;
  260.         $this->apiContent->content_tinymce $content_tinymce;
  261.         $lok $this->apiContent->savetinymce();
  262.         return new JsonResponse($lok);
  263.     }
  264.     /**
  265.      * @Route("/content/uploadphotos", name="editcontent_uploadphotos")
  266.      */
  267.     public function uploadPhotos(Request $request)
  268.     {
  269.         $lcontent_id $_POST['content_id'];
  270.         
  271.         $folder '';
  272.         //dobimo mapo v kateri folder naj naložimo sliko
  273.         $user $this->security->getUser();
  274.         $folder $user->getFolder();
  275.         
  276.         if ($user->getFolder() == 'mki')
  277.         {
  278.             $folder 'strah';
  279.         }
  280.         
  281.         
  282.         
  283.         //$folder = $this->security->getUser()->getFolder();
  284.     
  285.         // initialize FileUploader
  286.         $FileUploader = new FileUploader('datotekaMultipleInput', array(
  287.             'limit' => 1,
  288.             'fileMaxSize' => 20,
  289.             'extensions' => array('image/*''video/*''audio/*''pdf'),
  290.             'uploadDir' => $this->rootDir '/public/uploads/' $folder '/',
  291.             'required' => true,
  292.             'title' => 'name',
  293.             'editor' => array(
  294.                 'maxWidth' => 1980,
  295.                 'maxHeight' => 1980,
  296.                 'crop' => false,
  297.                 'quality' => 90
  298.             )
  299.         ));
  300.         $upload $FileUploader->upload();
  301.         if (count($upload['files']) == 1) {
  302.             $item $upload['files'][0];
  303.             
  304.             $title $item['name'];
  305.             $type $item['type'];
  306.             $size $item['size'];
  307.             $file $this->rootDir '/public/uploads/' $folder '/' $item['name'];
  308.             $fileName $item['name'];
  309.             
  310.             $this->apiContent->content_id $lcontent_id;
  311.             $this->apiContent->photo_name $fileName;
  312.             $this->apiContent->photo_file $fileName;
  313.             $this->apiContent->photo_type $type;
  314.             $this->apiContent->photo_size $size;
  315.             $lLastInsertID $this->apiContent->writePhotoDB();
  316.             
  317.             
  318.             if ($lLastInsertID 0) {
  319.                 $upload['files'][0] = array(
  320.                     'title' => $item['title'],
  321.                     'name' => $item['name'],
  322.                     'size' => $item['size'],
  323.                     'size2' => $item['size2'],
  324.                     'url' => $file,
  325.                     'id' => $lLastInsertID
  326.                 );
  327.             } else {
  328.                 if (is_file($this->rootDir '/public/uploads/' $folder '/' .$item['file']))
  329.                     @unlink($this->rootDir '/public/uploads/' $folder '/' .$item['file']);
  330.                 unset($upload['files'][0]);
  331.                 $upload['hasWarnings'] = true;
  332.                 $upload['warnings'][] = 'Prišlo je do napake.';
  333.             }
  334.         }
  335.         
  336.         echo json_encode($upload);
  337.         exit;
  338.         
  339.         
  340.         //----------------------------------
  341.         $this->apiContent->content_id $lcontent_id;
  342.         $lPhotos $this->apiContent->getPreloadedPhotos($lcontent_id);
  343.         
  344.         return new Response(json_encode($lPhotos));
  345.     }
  346.     /**
  347.      * @Route("/content/sortphotos", name="editcontent_sortphotos")
  348.      */
  349.     public function sortPhotos(Request $request)
  350.     {
  351.         $lcontent_id $_POST['content_id'];
  352.         $this->apiContent->content_id $lcontent_id;
  353.         $this->apiContent->list $_POST['listsort'];
  354.         $this->apiContent->sortPhotos();
  355.         
  356.         
  357.         exit;
  358.     }
  359.     
  360. }