diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php index 848f8cc5..8c691f0d 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php @@ -109,7 +109,7 @@ class FileController extends Controller if($fs->exists($fulldirectory)) { $finder = new Finder(); - $finder->depth('== 0')->sortByName()->in($fulldirectory)->exclude('thumb')->exclude('thumbmini'); + $finder->depth('== 0')->sortByName()->in($fulldirectory)->exclude('thumb')->exclude('thumbmini')->exclude('__trash'); foreach ($finder as $file) { if(is_dir($file)) { @@ -148,6 +148,10 @@ class FileController extends Controller } } + // Flag poubelle + $fgtrash=false; + if(stripos($subdirectory,"_trash")==1) $fgtrash=true; + // Trie du tableu $sort = array_column($files, $preference["widgetsortdirectory"][$directory]); array_multisort($sort, SORT_ASC, $files); @@ -171,6 +175,7 @@ class FileController extends Controller 'canadd' => $canupdate, 'view' => $preference["widgetviewdirectory"][$directory], 'sort' => $preference["widgetsortdirectory"][$directory], + 'fgtrash' => $fgtrash, ]); } @@ -206,7 +211,7 @@ class FileController extends Controller if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); - if($data["subdirectory"]=="thumb"||$data["subdirectory"]=="thumbmini") { + if($data["subdirectory"]=="thumb"||$data["subdirectory"]=="thumbmini"||$data["subdirectory"]=="__trash") { $form->addError(new FormError('Nom de répertoire réservé, merci de choisir un autre nom de répertoire')); $this->get('session')->getFlashBag()->clear(); $request->getSession()->getFlashBag()->add("error", 'Nom de répertoire réservé, merci de choisir un autre nom de répertoire'); @@ -234,6 +239,142 @@ class FileController extends Controller ]); } + public function trashAction(Request $request,$access="config") + { + // S'assurer que c'est un appel ajax + if (!$request->isXmlHttpRequest()) { + return new JsonResponse(array('message' => 'Interdit'), 400); + } + + $output=array(); + $directory=$request->request->get('directory'); + + // Récupération du répertoire source et le nom du fichier + $racine=$this->get('kernel')->getRootDir()."/../uploads/file"; + $directory=$request->request->get('directory'); + $dirsource =$request->request->get('subdirectory'); + $namesource =$request->request->get('filename'); + + $this->getPermission($access,$directory); + $fs = new Filesystem(); + + // Déplacer le fichier + $urlsource=$racine."/".$directory."/".$dirsource."/".$namesource; + $urldestination=$racine."/".$directory."/__trash/".$dirsource."/".$namesource; + $fs->mkdir($racine."/".$directory."/__trash/".$dirsource); + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + + } + + // Déplacer le thumb + $fs->mkdir($racine."/".$directory."/__trash/".$dirsource."/thumb"); + $urlsource=$racine."/".$directory."/".$dirsource."/thumb/".$namesource; + $urldestination=$racine."/".$directory."/__trash/".$dirsource."/thumb/".$namesource; + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + // Déplacer le thumbmini + $fs->mkdir($racine."/".$directory."/__trash/".$dirsource."/thumbmini"); + $urlsource=$racine."/".$directory."/".$dirsource."/thumbmini/".$namesource; + $urldestination=$racine."/".$directory."/__trash/".$dirsource."/thumbmini/".$namesource; + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + $response = new Response(json_encode($output)); + $response->headers->set('Content-Type', 'application/json'); + return $response; + } + + public function restaureAction(Request $request,$access="config") + { + // S'assurer que c'est un appel ajax + if (!$request->isXmlHttpRequest()) { + return new JsonResponse(array('message' => 'Interdit'), 400); + } + + $output=array(); + $directory=$request->request->get('directory'); + + // Récupération du répertoire source et le nom du fichier + $racine=$this->get('kernel')->getRootDir()."/../uploads/file"; + $directory=$request->request->get('directory'); + $dirsource =$request->request->get('subdirectory'); + $namesource =$request->request->get('filename'); + + $this->getPermission($access,$directory); + $fs = new Filesystem(); + + // Déplacer le fichier + $dirdestination=str_replace("__trash/","",$dirsource); + $urlsource=$racine."/".$directory."/".$dirsource."/".$namesource; + $urldestination=str_replace("__trash/","/",$urlsource); + $fs->mkdir($racine."/".$directory."/".$dirdestination); + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + // Déplacer le thumb + $urlsource=$racine."/".$directory."/".$dirsource."/thumb/".$namesource; + $urldestination=str_replace("__trash/","/",$urlsource); + $fs->mkdir($racine."/".$directory."/".$dirdestination."/thumb"); + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + // Déplacer le thumbmini + $urlsource=$racine."/".$directory."/".$dirsource."/thumbmini/".$namesource; + $urldestination=str_replace("__trash/","/",$urlsource); + $fs->mkdir($racine."/".$directory."/".$dirdestination."/thumbmini"); + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + $response = new Response(json_encode($output)); + $response->headers->set('Content-Type', 'application/json'); + return $response; + } + + public function purgetrashAction($directory,Request $request,$access="config") + { + $output=array(); + + $this->getPermission($access,$directory); + $fs = new Filesystem(); + $url=$this->get('kernel')->getRootDir()."/../uploads/file/".$directory."/__trash"; + if($fs->exists($url)) { + $fs->remove($url); + } + + return $this->redirectToRoute('cadoles_core_'.$access.'_file_list',['directory'=>$directory]); + } + public function deleteAction(Request $request,$access="config") { // S'assurer que c'est un appel ajax @@ -267,7 +408,7 @@ class FileController extends Controller } $output=array(); - $directory=$request->request->get('directory');+ + $directory=$request->request->get('directory'); // Récupération du répertoire source et le nom du fichier $racine=$this->get('kernel')->getRootDir()."/../uploads/file"; @@ -276,7 +417,6 @@ class FileController extends Controller $dirdestination =$request->request->get('dirdestination'); $namedestination =$request->request->get('namedestination'); - $destid=$request->request->get('destid'); $this->getPermission($access,$directory); $fs = new Filesystem(); @@ -285,7 +425,12 @@ class FileController extends Controller $urlsource=$racine."/".$dirsource."/".$namesource; $urldestination=$racine."/".$dirdestination."/".$namedestination; if($fs->exists($urlsource)) { - $fs->rename($urlsource,$urldestination); + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else + $fs->rename($urlsource,$urldestination, true); } // Déplacer le thumb @@ -293,7 +438,12 @@ class FileController extends Controller $urlsource=$racine."/".$dirsource."/thumb/".$namesource; $urldestination=$racine."/".$dirdestination."/thumb/".$namedestination; if($fs->exists($urlsource)) { - $fs->rename($urlsource,$urldestination); + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else + $fs->rename($urlsource,$urldestination, true); } // Déplacer le thumbmini @@ -301,7 +451,12 @@ class FileController extends Controller $urlsource=$racine."/".$dirsource."/thumbmini/".$namesource; $urldestination=$racine."/".$dirdestination."/thumbmini/".$namedestination; if($fs->exists($urlsource)) { - $fs->rename($urlsource,$urldestination); + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else + $fs->rename($urlsource,$urldestination, true); } $response = new Response(json_encode($output)); @@ -309,6 +464,7 @@ class FileController extends Controller return $response; } + public function viewAction($directory,$filename,Request $request,$access="config") { $this->getPermission($access,$directory); diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml index 0511a6ba..5843eabd 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml @@ -74,6 +74,18 @@ cadoles_core_config_file_subdirectory: path: /config/file/subdirectory/{id}/{type} defaults: { _controller: CadolesCoreBundle:File:subdirectory, access: config } +cadoles_core_config_file_trash: + path: /config/file/trash/ + defaults: { _controller: CadolesCoreBundle:File:trash, access: config } + +cadoles_core_config_file_restaure: + path: /config/file/restaure/ + defaults: { _controller: CadolesCoreBundle:File:restaure, access: config } + +cadoles_core_config_file_purgetrash: + path: /config/file/purgetrash/{directory} + defaults: { _controller: CadolesCoreBundle:File:purgetrash, access: config } + cadoles_core_config_file_delete: path: /config/file/delete/ defaults: { _controller: CadolesCoreBundle:File:delete, access: config } @@ -107,6 +119,18 @@ cadoles_core_user_file_subdirectory: path: /user/file/subdirectory/{id}/{type} defaults: { _controller: CadolesCoreBundle:File:subdirectory, access: user } +cadoles_core_user_file_trash: + path: /user/file/trash/ + defaults: { _controller: CadolesCoreBundle:File:trash, access: user } + +cadoles_core_user_file_restaure: + path: /user/file/restaure/ + defaults: { _controller: CadolesCoreBundle:File:restaure, access: user } + +cadoles_core_user_file_purgetrash: + path: /user/file/purgetrash/{directory} + defaults: { _controller: CadolesCoreBundle:File:purgetrash, access: user } + cadoles_core_user_file_delete: path: /user/file/delete defaults: { _controller: CadolesCoreBundle:File:delete, access: user } @@ -128,6 +152,7 @@ cadoles_core_user_file_show: defaults: { _controller: CadolesCoreBundle:File:show, access: user } + #== Ajax ================================================================================================================= cadoles_core_ajax_country_list: path: /ajax/country/list diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css index 29c54e2a..3d446a49 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css @@ -381,6 +381,15 @@ a.item-update { z-index: 1000; } + +a.item-restaure { + display: none; + position: absolute; + right: 25px; + top: 2px; + z-index: 1000; +} + a.item-delete { display: none; position: absolute; diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig index 419bba1e..da291b1e 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig @@ -41,7 +41,7 @@