src/Service/contentservice.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use Symfony\Component\HttpKernel\KernelInterface;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Doctrine\DBAL\Connection;
  8. use Psr\Log\LoggerInterface;
  9. use FileUploader;
  10. use Doctrine\DBAL\DBALException;
  11. use Symfony\Component\Security\Core\Security;
  12. class contentservice
  13. {
  14.     public $content_image;
  15.     public $security;
  16.     public function __construct(Connection $connectionLoggerInterface $loggerKernelInterface $kernelSecurity $security)
  17.     {
  18.         $this->dbconnection $connection;
  19.         $this->logger $logger;
  20.         $this->security $security;
  21.         
  22.         
  23.         $user $this->security->getUser();
  24.         //$userID = $user->getId();
  25.         //$companyID = $user->getCompany();
  26.         //$folder = $user->getFolder();
  27.         
  28.         //file_put_contents("session1.log", "/var/www/nota/public/moxiemanager/companies/". $folder ."/files/");
  29.         //file_put_contents("session2.log", print_r($_SESSION, true));
  30.         //$_SESSION['filesystem.rootpath']="/var/www/nota/public/moxiemanager/companies/". $folder ."/files/";
  31.         try
  32.         {
  33.             $this->rootDir $kernel->getProjectDir();
  34.             $this->logger->info($this->rootDir);
  35.         }
  36.         catch(Exception $e)
  37.         {
  38.             $this->logger->info($e);
  39.         }
  40.     }
  41.     private function friendlyName($Aname) {
  42.         $crke = array('Č''Š''Ž''č''š''ž''ć''Ć''%''_'';''€');
  43.         $zamenjava = array('C''S''Z''c''s''z''c''C''-procentov''-''-''EUR');
  44.         $name str_replace($crke$zamenjava$Aname);
  45.         preg_match_all('/\w+/'strtolower($name), $m);
  46.         return implode('-'$m[0]);
  47.     }
  48.     public function getAllContent($Amaterial_id,$AUserCompany)
  49.     {
  50.         $lContenti = array();
  51.         $lquery "select *, concat(u.user_name,' ',u.user_surname) as created
  52.                     from contents c, users u, engines e, objecttypes t, objects o, languages l, materials m, catalogues g where 
  53.                     c.engine_id = e.engine_id and t.objecttype_id = e.objecttype_id and o.material_id = m.material_id and t.catalogue_id = g.catalogue_id and
  54.                     o.object_id = t.object_id and c.user_id = u.user_id and c.language_id = l.language_id and m.material_id = ".$Amaterial_id " and c.company_id = " $AUserCompany;
  55.         $lSql $this->dbconnection->fetchAllAssociative($lquery);
  56.         
  57.         foreach ($lSql as $content)
  58.         {   
  59.             $ldateraw $content['content_date'];
  60.             $ldate date('d.m.Y'strtotime($ldateraw));
  61.             
  62.             $lstatusdescriptive ="";
  63.             if ($content['content_status'] =="0")
  64.             {
  65.                 $lstatusdescriptive "izbrisana";
  66.             }
  67.             else if ($content['content_status'] =="1")
  68.             {
  69.                 $lstatusdescriptive "v pripravi";
  70.             }
  71.             else if ($content['content_status'] =="2")
  72.             {
  73.                 $lstatusdescriptive "objavljena";
  74.             }
  75.             $lContenti[] = array('content_id' => $content['content_id'], 
  76.                             'content_date' => $ldate,
  77.                             'content_title' => $content['content_title'],
  78.                             'content_dateraw' => $ldateraw,
  79.                             'content_status' => $content['content_status'],
  80.                             'content_status_descriptive' => $lstatusdescriptive,
  81.                             'content_notes' => $content['content_notes'],
  82.                             'language_title' => $content['language_title'],
  83.                             'catalogue_title' => $content['catalogue_title'],
  84.                             'breadcrumbs' => "content/".$this->friendlyName($content['content_title']),
  85.                             'user_id' => $content['user_id'],
  86.                             'created' => $content['created']
  87.                         );          
  88.         }
  89.         return $lContenti;
  90.     }
  91.     public function getContentByID($Acontent_id)
  92.     {
  93.         $lContent = array();
  94.         $lquery "select *, concat(u.user_name,' ',u.user_surname) as created
  95.                     from contents c, users u, engines e, objecttypes t, objects o, languages l, materials m, catalogues g where 
  96.                     c.engine_id = e.engine_id and t.objecttype_id = e.objecttype_id and o.material_id = m.material_id and t.catalogue_id = g.catalogue_id and
  97.                     o.object_id = t.object_id and c.user_id = u.user_id and c.language_id = l.language_id and c.content_id = ".$Acontent_id;
  98.         $lSql $this->dbconnection->fetchAllAssociative($lquery);
  99.         
  100.         foreach ($lSql as $content)
  101.         {   
  102.             $ldate date'd.m.Y'strtotime($content['content_date']) );
  103.             $lquery "SELECT count(*) as fields from contentforms where content_id = ".$Acontent_id;
  104.             $lfields 0;
  105.             $lSql $this->dbconnection->fetchAllAssociative($lquery);
  106.             foreach ($lSql as $fields)
  107.             {   
  108.                 $lfields $fields['fields'];
  109.             }
  110.             $lContent[] = array('content_id' => $content['content_id'], 
  111.                             'content_title' => $content['content_title'],
  112.                             'content_date' => $ldate,
  113.                             'engine_id' => $content['engine_id'],
  114.                             'catalogue_title' => $content['catalogue_title'],
  115.                             'content_status' => $content['content_status'],
  116.                             'content_notes' => $content['content_notes'],
  117.                             'user_id' => $content['user_id'],
  118.                             'created' => $content['created'],  
  119.                             'language_id' => $content['language_id'], 
  120.                             'content_image' => $content['content_image'],                        
  121.                             'fields' => $lfields
  122.                         );
  123.         }
  124.         return $lContent;
  125.     }
  126.     public function getPreloadedPhotos($AcontentID)
  127.     {
  128.         $lPhotos = array();
  129.         $preloadedFiles = array();
  130.         $folder $this->security->getUser()->getFolder();
  131.         $lquery "select * from photos WHERE content_id = " $AcontentID;
  132.         $lSql $this->dbconnection->fetchAllAssociative($lquery);
  133.         
  134.         foreach ($lSql as $photo)
  135.         {   
  136.             $lPhotos[] = array('photo_id' => $photo['photo_id'], 
  137.                             'photo_name' => $photo['photo_name'],
  138.                             'photo_description' => $photo['photo_description'],
  139.                             'photo_file' => $photo['photo_file'],
  140.                             'photo_dateadded' => $photo['photo_dateadded'],
  141.                             'photo_ordernum' => $photo['photo_ordernum'],
  142.                             'photo_type' => $photo['photo_type'],  
  143.                             'photo_size' => $photo['photo_size']
  144.                         );
  145.                         $preloadedFiles[] = array(
  146.                             'name' => $photo['photo_file'],
  147.                             'type' => $photo['photo_type'],
  148.                             'size' => $photo['photo_size'],
  149.                             'file' => $this->rootDir '/public/uploads/' $folder '/' .  $photo['photo_file'],
  150.                             'data' => array(
  151.                                 'readerForce' => true,
  152.                                 'thumbnail' => $this->rootDir '/public/uploads/' $folder '/' .  $photo['photo_file'], 
  153.                                 'url' => $this->rootDir '/public/uploads/' $folder '/' .  $photo['photo_file'],
  154.                                 'date' => $photo['photo_dateadded'],
  155.                                 'isMain' => 0,
  156.                                 'listProps' => array(
  157.                                     'id' => $photo['photo_id'],
  158.                                 )
  159.                             ),
  160.                         );
  161.         }
  162.         
  163.         return $preloadedFiles;
  164.     }
  165.     public function getPreloadedDocs($AcontentID)
  166.     {
  167.         $lPhotos = array();
  168.         $lquery "select * from docs WHERE content_id = " $AcontentID;
  169.         $lSql $this->dbconnection->fetchAllAssociative($lquery);
  170.         
  171.         foreach ($lSql as $doc)
  172.         {   
  173.             $lPhotos[] = array('doc_id' => $doc['doc_id'], 
  174.                             'doc_name' => $doc['doc_name'],
  175.                             'doc_description' => $doc['photo_doc_descriptiondescription'],
  176.                             'doc_file' => $doc['doc_file'],
  177.                             'doc_dateadded' => $doc['doc_dateadded'],
  178.                             'doc_ordernum' => $doc['doc_ordernum'],
  179.                             'doc_type' => $doc['doc_type'],  
  180.                             'doc_size' => $doc['doc_size']
  181.                         );
  182.         }
  183.         return $lPhotos;
  184.     }
  185.     public function addContent()
  186.     {
  187.         $lcontent_id 0;
  188.         $lToday date('Y-m-d  H:i');
  189.         
  190.         $SqlInsert "INSERT INTO contents (content_date,engine_id,user_id,content_status,company_id,language_id) VALUES (?,?,?,?,?,?)";
  191.         $stmt $this->dbconnection->prepare($SqlInsert);
  192.         $stmt->bindValue(1,  $lToday);
  193.         $stmt->bindValue(2,  $this->engine_id);
  194.         $stmt->bindValue(3,  $this->user_id);
  195.         $stmt->bindValue(4,  1);
  196.         $stmt->bindValue(5,  $this->company_id);
  197.         $stmt->bindValue(6,  1);
  198.         
  199.         try
  200.         {
  201.             $stmt->execute();
  202.             $lcontent_id $this->dbconnection->lastInsertId();
  203.         }
  204.         catch(DBALException $e)
  205.         { 
  206.             file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  207.         }
  208.         return $lcontent_id;
  209.     }
  210.     public function deleteMenuContents($AContentID$AMenuID)
  211.     {
  212.         $lSQLStatus false;
  213.         
  214.         $lSqlDeleteMenuContents "DELETE FROM menucontents WHERE content_id = ? AND menu_id = ?";
  215.         file_put_contents("errorTest.log"$AMenuID);
  216.         $stmt $this->dbconnection->prepare($lSqlDeleteMenuContents);
  217.         $stmt->bindValue(1$AContentID);
  218.         $stmt->bindValue(2$AMenuID);
  219.         file_put_contents("errorTest.log","OK");
  220.         try
  221.         {
  222.             $stmt->execute();
  223.             $lSQLStatus true;
  224.         }
  225.         catch(DBALException $e)
  226.         { 
  227.             $lSQLStatus false;
  228.             file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  229.         }
  230.         return $lSQLStatus;
  231.     }
  232.     public function insertMenuContents($AContentID$AMenuID)
  233.     {
  234.         $lSQLStatus false;
  235.         
  236.         $lSqlInsertMenuContents "INSERT INTO menucontents (content_id, menu_id) VALUES (?,?)";
  237.         $stmt $this->dbconnection->prepare($lSqlInsertMenuContents);
  238.         $stmt->bindValue(1$AContentID);
  239.         $stmt->bindValue(2$AMenuID);
  240.         try
  241.         {
  242.             $stmt->execute();
  243.             $lSQLStatus true;
  244.         }
  245.         catch(DBALException $e)
  246.         { 
  247.             $lSQLStatus false;
  248.             file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  249.         }
  250.         return $lSQLStatus;
  251.     }
  252.     public function saveContent()
  253.     {
  254.         $lSqlUpdate "UPDATE contents set engine_id = ?, content_title = ?, content_notes = ?, content_image = ?, language_id = ? WHERE content_id = ?";
  255.         $stmt $this->dbconnection->prepare($lSqlUpdate);
  256.         $stmt->bindValue(1$this->engine_id);
  257.         $stmt->bindValue(2$this->content_title);
  258.         $stmt->bindValue(3$this->content_notes);
  259.         $stmt->bindValue(4$this->content_image);
  260.         $stmt->bindValue(5$this->language_id);
  261.         $stmt->bindValue(6$this->content_id);
  262.         file_put_contents("tree1.log"print_r($this->treemenutrue) );
  263.         foreach($this->treemenu as $node)
  264.         {
  265.             $this->deleteMenuContents($this->content_id$node['id']);
  266.             
  267.             if ($node['state']['selected'] == 'true')
  268.             {
  269.                 
  270.                 $this->insertMenuContents($this->content_id$node['id']);
  271.                 file_put_contents("tree1-.log"$node['id'] . ":" $node['state']['selected'] . PHP_EOLFILE_APPEND);
  272.             }
  273.             
  274.             
  275.             //grem skozi drevo in pogledam katera vozlišča so označena. tista zapišem v tabelo menucontents 
  276.             /*if ($node['id'] = $this->content_id)
  277.             {
  278.                 file_put_contents("tree1-.log", print_r($node['id'] . ":" . $node['state']['selected'], true), FILE_APPEND );
  279.             }*/
  280.         }
  281.         try
  282.         {
  283.             $stmt->execute();
  284.             $lok true;
  285.         }
  286.         catch(DBALException $e)
  287.         { 
  288.             $lok false;
  289.             file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  290.         }
  291.         return $lok;
  292.     }
  293.     public function savetinymce()
  294.     {
  295.         $contentform_id 0;
  296.         $lok false;
  297.         //najprej dobimo contentform id da lahko udejtamo tabelo
  298.         //prequery - domino iz bate za katero vrsto vsebine gre?
  299.         $lprequery "select * from contentforms c, enginefields e WHERE c.content_id = " $this->content_id " and c.enginefield_id = e.enginefield_id and e.enginefield_key = 'contents'";
  300.         $lSqlpre $this->dbconnection->fetchAllAssociative($lprequery);
  301.         
  302.         foreach ($lSqlpre as $res)
  303.         {   
  304.             $preid $res['enginefield_id'];
  305.         }
  306.         //***************************************************** */
  307.         
  308.         $lquery "select * from contentforms WHERE content_id = " $this->content_id ." and enginefield_id = " $preid ;
  309.         $lSql $this->dbconnection->fetchAllAssociative($lquery);
  310.         
  311.         foreach ($lSql as $res)
  312.         {   
  313.             $contentform_id $res['contentform_id'];
  314.         }
  315.         
  316.         $lSqlUpdate "UPDATE contentforms set contentform_value = ? WHERE content_id = ? and contentform_id = ?";
  317.         
  318.         if ($contentform_id != 0)
  319.         {
  320.             $stmt $this->dbconnection->prepare($lSqlUpdate);
  321.             $stmt->bindValue(1$this->content_tinymce);
  322.             $stmt->bindValue(2$this->content_id);
  323.             $stmt->bindValue(3$contentform_id);
  324.             file_put_contents("tiny.log""UPDATE contentforms set contentform_value = $this->content_tinymce WHERE content_id = $this->content_id and enginefield_id =$contentform_id");
  325.             try
  326.             {
  327.                 $stmt->execute();
  328.                 $lok true;
  329.             }
  330.             catch(\DBALException $e)
  331.             { 
  332.                 $lok false;
  333.                 file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  334.             }
  335.         }
  336.         return $lok;
  337.     }
  338.     public function deleteContent()
  339.     {
  340.         $lSqlUpdate "UPDATE contents set content_status = 0 WHERE content_id = ?";
  341.         $stmt $this->dbconnection->prepare($lSqlUpdate);
  342.         $stmt->bindValue(1$this->content_id);
  343.         try
  344.         {
  345.             $stmt->execute();
  346.             $lok true;
  347.         }
  348.         catch(DBALException $e)
  349.         { 
  350.             $lok false;
  351.             file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  352.         }
  353.         return $lok;
  354.     }
  355.     public function getLogsContent($Acontent_id)
  356.     {
  357.         $logArray = array();
  358.         
  359.         $lquery "SELECT * FROM logs l, actions a, users u WHERE a.action_id = l.action_id and u.user_id = l.user_id and l.content_id =" $Acontent_id;
  360.         $lSql $this->dbconnection->fetchAllAssociative($lquery);
  361.         
  362.         foreach ($lSql as $log)
  363.         {
  364.             $logArray[] = array('log_datetime' => $log['log_datetime'],
  365.                             'user_name' => $log['user_name'],
  366.                             'user_surname' => $log['user_surname'],
  367.                             'action_title' => $log['action_title'],
  368.                             'log_description' => $log['log_description'],                            
  369.                         );
  370.         }
  371.         
  372.         return $logArray;
  373.     }
  374.     public function createForm()
  375.     {
  376.         $lok true;
  377.         $fields = array();
  378.             
  379.         $lquery "SELECT * FROM enginefields where engine_id = ".$this->engine_id;
  380.             
  381.         $lSqlEngineFields $this->dbconnection->fetchAllAssociative($lquery);
  382.             
  383.         foreach ($lSqlEngineFields as $EngineField)
  384.         {   
  385.             $lqueryInsert "INSERT INTO contentforms (content_id,enginefield_id) VALUES (?,?)";
  386.             
  387.             $stmt $this->dbconnection->prepare($lqueryInsert);
  388.             $stmt->bindValue(1,  $this->content_id);
  389.             $stmt->bindValue(2,  $EngineField['enginefield_id']);
  390.             try
  391.             {
  392.                 $stmt->execute();
  393.             }
  394.             catch(DBALException $e)
  395.             { 
  396.                 $lok false;
  397.                 file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  398.             }
  399.             $fields[] = array('field_id' => $EngineField['enginefield_id']);
  400.         }
  401.         return $fields;
  402.     }
  403.     public function showForm()
  404.     {
  405.         $fields = array();       
  406.         
  407.         $lquery "SELECT * FROM contentforms c, enginefields e where 
  408.                     c.enginefield_id = e.enginefield_id and 
  409.                     c.content_id = ".$this->content_id." order by e.enginefield_number";
  410.             
  411.         $lSqlEnginefields $this->dbconnection->fetchAllAssociative($lquery);
  412.   
  413.         $lanchor "#";
  414.         foreach ($lSqlEnginefields as $EngineField)
  415.         {   
  416.             $lvrednost $EngineField['contentform_value'];
  417.             
  418.             if ($EngineField['contentform_value'] == "" && $lanchor != 'prazna')
  419.             {
  420.                 $lanchor "prazna";
  421.             }
  422.             else
  423.             {
  424.                 $lanchor "#";
  425.             }
  426.             
  427.             $fields[] = array('contentform_id' => $EngineField['contentform_id'],
  428.                                 'contentform_value' => $EngineField['contentform_value'],
  429.                                 'enginefield_instruction' => $EngineField['enginefield_instruction'],
  430.                                 'enginefield_datatype' => $EngineField['enginefield_datatype'],
  431.                                 'enginefield_key' => $EngineField['enginefield_key'],
  432.                                 'enginefield_value' => $EngineField['enginefield_value'],
  433.                                 'enginefield_label' => $EngineField['enginefield_label'],
  434.                                 'enginefield_objecttype' => $EngineField['enginefield_objecttype'],
  435.                                 'enginefield_number' => $EngineField['enginefield_number'],
  436.                                 'anchor' => $lanchor
  437.             );
  438.         }
  439.         
  440.         return $fields;
  441.     }
  442.     public function getPreloadedImage()
  443.     {
  444.         $folder '';
  445.         //dobimo mapo v kateri folder naj naložimo sliko
  446.         $user $this->security->getUser();
  447.         $folder $user->getFolder();
  448.         if ($user->getFolder() == 'mki')
  449.         {
  450.             $folder 'strah';
  451.         }
  452.         
  453.         
  454.         
  455.         
  456.         
  457.         $uploadDir $this->rootDir .'/public/uploads/' $folder .'/';
  458.         $uploadDirReturn $this->rootDir .'/public/uploads/' $folder .'/';
  459.         //$folder = $this->security->getUser()->getFolder();
  460.         
  461.         
  462.         $preloadedFiles = array();
  463.         $lSql $this->dbconnection->fetchAllAssociative("SELECT content_image from contents where content_id = " $this->content_id);
  464.         foreach ($lSql as $image)
  465.         {
  466.             if ( $image['content_image'] != null
  467.             {
  468.                 file_put_contents("preloadcontentimage1.log"$this->rootDir '/public/uploads' $folder '/' $image['content_image']);
  469.                 $preloadedFiles[] = array(
  470.                     "name" => $image['content_image'],
  471.                     "type" => mime_content_type($this->rootDir '/public/uploads/' $folder '/' $image['content_image']),
  472.                     "size" => filesize($this->rootDir '/public/uploads/' $folder '/' $image['content_image']),
  473.                     "file" => '/uploads/' $folder '/' $image['content_image'],
  474.                     "local" => $this->rootDir '/public/uploads/' $folder '/' $image['content_image'], // same as in form_upload.php
  475.                     "data" => array(
  476.                         "url" => $this->rootDir '/public/uploads/' $folder '/' $image['content_image'], // (optional)
  477.                         "thumbnail" => file_exists($this->rootDir '/public/uploads/' $folder '/' $image['content_image']) ? $uploadDirReturn 'thumbs/' $image['content_image'] : null// (optional)
  478.                         "readerForce" => true // (optional) prevent browser cache
  479.                     ),
  480.                 );
  481.             }
  482.         }
  483.         return $preloadedFiles;
  484.     }
  485.     public function saveField()
  486.     {       
  487.         $lSqlUpdate "UPDATE contentforms set contentform_value = ? where contentform_id= ?";
  488.         $stmt $this->dbconnection->prepare($lSqlUpdate);
  489.         $stmt->bindValue(1$this->contentform_value);
  490.         $stmt->bindValue(2$this->contentform_id);
  491.         try
  492.         {
  493.             $stmt->execute();
  494.             $lok true;
  495.         }
  496.         catch(DBALException $e)
  497.         { 
  498.             $lok false;
  499.             file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  500.         }
  501.         
  502.         
  503.         foreach($this->treemenu as $node)
  504.         {
  505.             $this->deleteMenuContents($this->content_id$node['id']);
  506.             
  507.             if ($node['state']['selected'] == 'true')
  508.             {
  509.                 $this->insertMenuContents($this->content_id$node['id']);
  510.             }
  511.         }
  512.         return $lok;
  513.     }
  514.     public function publishContent()
  515.     {
  516.         
  517.         $lSqlUpdate "UPDATE contents set content_status = 2 WHERE content_id = ?";
  518.         $stmt $this->dbconnection->prepare($lSqlUpdate);
  519.         $stmt->bindValue(1,$this->content_id);
  520.         try
  521.         {
  522.             $lok true;
  523.             $stmt->execute();
  524.         }
  525.         catch(DBALException $e)
  526.         { 
  527.             $lok false;
  528.             file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  529.         }
  530.         return $lok;
  531.     }
  532.     public function writePhotoDB()
  533.     {
  534.         $maxOrdernum 0;
  535.         
  536.         $lSql $this->dbconnection->fetchAllAssociative("SELECT MAX(photo_ordernum) AS photo_ordernum FROM photos WHERE content_id = $this->content_id");
  537.         foreach ($lSql as $result)
  538.         {
  539.             $maxOrdernum $result['photo_ordernum'] +1;
  540.         }
  541.         $sqlInsertPhoto "INSERT INTO photos (content_id, photo_name, photo_file, photo_dateadded, photo_ordernum, photo_type, photo_size) VALUES (?,?,?,NOW(),?,?,?)";
  542.         $stmt $this->dbconnection->prepare($sqlInsertPhoto);
  543.         $stmt->bindValue(1,$this->content_id);
  544.         $stmt->bindValue(2,$this->photo_name);
  545.         $stmt->bindValue(3,$this->photo_file);
  546.         
  547.         $stmt->bindValue(4,$maxOrdernum);
  548.         $stmt->bindValue(5,$this->photo_type);
  549.         $stmt->bindValue(6,$this->photo_size);
  550.         try
  551.         {
  552.             $lok true;
  553.             $stmt->execute();
  554.         }
  555.         catch(DBALException $e)
  556.         { 
  557.             $lok false;
  558.             file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  559.         }
  560.         return $this->dbconnection->lastInsertId();
  561.             
  562.     }
  563.     public function sortPhotos()
  564.     {
  565.         
  566.         $listsort json_decode($this->listtrue);   
  567.         $index 0;
  568.         foreach($listsort as $val
  569.         {
  570.             if (!isset($val['id']) || !isset($val['name']) || !isset($val['index']))
  571.             {
  572.                 break;
  573.             }
  574.                         
  575.             $photo_id $val['id'];
  576.             $sqlSortPhotos "UPDATE photos SET photo_ordernum = ? WHERE photo_id = ? and content_id = ?";
  577.             $stmt $this->dbconnection->prepare($sqlSortPhotos);
  578.             $stmt->bindValue(1,$index);
  579.             $stmt->bindValue(2,$photo_id);
  580.             $stmt->bindValue(3,$this->content_id);
  581.             $argJson '{"workOrderNum":"' .$ldelovninalogispir_sifra  '","monolit1":"'$lkoda_monolita1 '","monolit2":"'$lkoda_monolita2 '","monolit3":"'$lkoda_monolita3 '","monolit4":"'$lkoda_monolita4 '","kalup1":"'$lkoda_ohisja1 '","kalup2":"'$lkoda_ohisja2 '","kalup3":"'$lkoda_ohisja1 '","kalup4":"' $lkoda_ohisja4 '"}';
  582.             $argJsonArray = array("workOrderNum" => "$ldelovninalogispir_sifra"
  583.                              "monolit1" => "$lkoda_monolita1",
  584.                              "monolit2" => "$lkoda_monolita2",
  585.                              "monolit3" => "$lkoda_monolita3",
  586.                             "monolit4" => "$lkoda_monolita4",
  587.                             "kalup1" => "$lkoda_ohisja1",
  588.                             "kalup2" => "$lkoda_ohisja1",
  589.                             "kalup3" => "$lkoda_ohisja1",
  590.                             "kalup4" => "$lkoda_ohisja1");
  591.             $argJson json_encode($argJsonArray);
  592.             try
  593.             {
  594.                 $lok true;
  595.                 $stmt->execute();
  596.             }
  597.             catch(DBALException $e)
  598.             { 
  599.                 $lok false;
  600.                 file_put_contents("error.log",$e->getMessage().PHP_EOL,FILE_APPEND);
  601.             }
  602.                 
  603.             $index++;
  604.         }
  605.         
  606.         
  607.         return $this->dbconnection->lastInsertId();
  608.             
  609.     }
  610. }