From 8f2e412b606e26dd18db4e52f6a4a0d1654f7490 Mon Sep 17 00:00:00 2001 From: afornerot Date: Tue, 22 Sep 2020 10:15:57 +0200 Subject: [PATCH] prefence user --- .../CoreBundle/Controller/FileController.php | 89 ++++++++++++------- .../CoreBundle/Entity/Registration.php | 2 +- .../src/Cadoles/CoreBundle/Entity/User.php | 31 ++++++- .../Resources/views/File/list.html.twig | 4 +- .../Controller/FrameController.php | 78 +++++++++++----- 5 files changed, 149 insertions(+), 55 deletions(-) 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 b2af0bdc..62df8355 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php @@ -28,40 +28,67 @@ class FileController extends Controller $sort=$request->get("sort"); $defaultview=$request->get("defaultview"); - // Récupérer en session le dernier subdirectory visité - $sessionsubdirectory = $this->get('session')->get('sessionsubdirectory'); - if(!is_array($sessionsubdirectory)) $sessionsubdirectory=[]; + // Récupérer les préférences utilisateur + $toupdate=false; + $preference=$this->getUser()->getPreference(); + if(is_null($preference)) $preference=[]; - if($clear) { - if(array_key_exists($directory,$sessionsubdirectory)) unset($sessionsubdirectory[$directory]); - $this->get('session')->set('sessionsubdirectory',$sessionsubdirectory); + // Préférence subdirectory + if(!array_key_exists("widgetsubdirectory",$preference)) { + $toupdate=true; + $preference["widgetsubdirectory"]=[]; + } + if((!array_key_exists($directory,$preference["widgetsubdirectory"]))) { + $toupdate=true; + $preference["widgetsubdirectory"][$directory]=null; + } + if($clear&&!is_null($preference["widgetsubdirectory"][$directory])) { + $toupdate=true; + $preference["widgetsubdirectory"][$directory]=null; } else { - if(!$subdirectory) { - if(array_key_exists($directory,$sessionsubdirectory)) $subdirectory=$sessionsubdirectory[$directory]; - } - else { - $sessionsubdirectory[$directory] = $subdirectory; - $this->get('session')->set('sessionsubdirectory',$sessionsubdirectory); + if(!$subdirectory) $subdirectory = $preference["widgetsubdirectory"][$directory]; + elseif($subdirectory!=$preference["widgetsubdirectory"][$directory]) { + $toupdate=true; + $preference["widgetsubdirectory"][$directory] = $subdirectory; } } - // Récupérer en session le mode de visualisation - $sessionviewdirectory = $this->get('session')->get('sessionviewdirectory'); - if(!is_array($sessionviewdirectory)) $sessionviewdirectory=[$directory=>$defaultview]; - if(!array_key_exists($directory,$sessionviewdirectory)) $sessionviewdirectory[$directory]=$defaultview; - if($view) - $sessionviewdirectory[$directory] = $view; - $this->get('session')->set('sessionviewdirectory',$sessionviewdirectory); - - // Récupérer en session le trie - $sessionviewsort = $this->get('session')->get('sessionviewsort'); - if(!is_array($sessionviewsort)) $sessionviewsort=[$sort=>"name"]; - if(!array_key_exists($directory,$sessionviewsort)) $sessionviewsort[$directory]="name"; - if($sort) - $sessionviewsort[$directory] = $sort; - $this->get('session')->set('sessionviewsort',$sessionviewsort); + // Préférence mode de visualisation + if(!array_key_exists("widgetviewdirectory",$preference)) { + $toupdate=true; + $preference["widgetviewdirectory"]=[]; + } + if((!array_key_exists($directory,$preference["widgetviewdirectory"]))) { + $toupdate=true; + $preference["widgetviewdirectory"][$directory]=$defaultview; + } + if($view&&$preference["widgetviewdirectory"][$directory]!=$view) { + $toupdate=true; + $preference["widgetviewdirectory"][$directory]=$view; + } + // Prérence trie + if(!array_key_exists("widgetsortdirectory",$preference)) { + $toupdate=true; + $preference["widgetsortdirectory"]=[]; + } + if((!array_key_exists($directory,$preference["widgetsortdirectory"]))) { + $toupdate=true; + $preference["widgetsortdirectory"][$directory]="name"; + } + if($sort&&$preference["widgetsortdirectory"][$directory]!=$sort) { + $toupdate=true; + $preference["widgetsortdirectory"][$directory]=$sort; + } + + // Mise à jour des préferences + if($toupdate) { + $em = $this->getDoctrine()->getManager(); + $this->getUser()->setPreference($preference); + $em->persist($this->getUser()); + $em->flush(); + } // Construire le chemin réel $iddirectory=explode("-",$directory)[1]; @@ -122,10 +149,10 @@ class FileController extends Controller } // Trie du tableu - $sort = array_column($files, $sessionviewsort[$directory]); + $sort = array_column($files, $preference["widgetsortdirectory"][$directory]); array_multisort($sort, SORT_ASC, $files); - $sort = array_column($dirs, $sessionviewsort[$directory]); + $sort = array_column($dirs, $preference["widgetsortdirectory"][$directory]); array_multisort($sort, SORT_ASC, $dirs); return $this->render('CadolesCoreBundle:File:list.html.twig',[ @@ -142,8 +169,8 @@ class FileController extends Controller 'files' => $files, 'canupdate' => $canupdate, 'canadd' => $canupdate, - 'view' => $sessionviewdirectory[$directory], - 'sort' => $sessionviewsort[$directory], + 'view' => $preference["widgetviewdirectory"][$directory], + 'sort' => $preference["widgetsortdirectory"][$directory], ]); } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php index a19080ea..fd347fa8 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php @@ -129,7 +129,7 @@ class Registration implements UserInterface, \Serializable private $niveau01other; /** - * @ORM\Column(name="description", type="text", nullable=true) + * @ORM\Column(name="motivation", type="text", nullable=true) */ private $motivation; diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php index 6d01d7e6..477a12bd 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php @@ -179,10 +179,15 @@ class User implements UserInterface, \Serializable private $niveau01other; /** - * @ORM\Column(name="description", type="text", nullable=true) + * @ORM\Column(name="motivation", type="text", nullable=true) */ private $motivation; + /** + * @ORM\Column(name="preference", type="array", nullable=true) + */ + private $preference; + /** * @ORM\ManyToOne(targetEntity="Country", inversedBy="users") * @ORM\JoinColumn(nullable=true) @@ -1952,4 +1957,28 @@ class User implements UserInterface, \Serializable { return $this->motivation; } + + /** + * Set preference + * + * @param array $preference + * + * @return User + */ + public function setPreference($preference) + { + $this->preference = $preference; + + return $this; + } + + /** + * Get preference + * + * @return array + */ + public function getPreference() + { + return $this->preference; + } } 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 6daa5c81..37baffca 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 @@ -73,9 +73,9 @@ {% endif %} {% if sort=="name" %} - + Nom {% else %} - + Date {% endif %} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/FrameController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/FrameController.php index 3ecb370c..99fe4a4a 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/FrameController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/FrameController.php @@ -26,33 +26,70 @@ class FrameController extends Controller $subdirectory=$request->get("subdirectory"); $clear=$request->get("clear"); $view=$request->get("view"); + $sort=$request->get("sort"); $defaultview=$request->get("defaultview"); - // Récupérer en session le dernier subdirectory visité - $sessionsubdirectory = $this->get('session')->get('sessionsubdirectory'); - if(!is_array($sessionsubdirectory)) $sessionsubdirectory=[]; + // Récupérer les préférences utilisateur + $toupdate=false; + $preference=$this->getUser()->getPreference(); + if(is_null($preference)) $preference=[]; - if($clear) { - if(array_key_exists($directory,$sessionsubdirectory)) unset($sessionsubdirectory[$directory]); - $this->get('session')->set('sessionsubdirectory',$sessionsubdirectory); + // Préférence subdirectory + if(!array_key_exists("widgetsubdirectory",$preference)) { + $toupdate=true; + $preference["widgetsubdirectory"]=[]; + } + if((!array_key_exists($directory,$preference["widgetsubdirectory"]))) { + $toupdate=true; + $preference["widgetsubdirectory"][$directory]=null; + } + if($clear&&!is_null($preference["widgetsubdirectory"][$directory])) { + $toupdate=true; + $preference["widgetsubdirectory"][$directory]=null; } else { - if(!$subdirectory) { - if(array_key_exists($directory,$sessionsubdirectory)) $subdirectory=$sessionsubdirectory[$directory]; - } - else { - $sessionsubdirectory[$directory] = $subdirectory; - $this->get('session')->set('sessionsubdirectory',$sessionsubdirectory); + if(!$subdirectory) $subdirectory = $preference["widgetsubdirectory"][$directory]; + elseif($subdirectory!=$preference["widgetsubdirectory"][$directory]) { + $toupdate=true; + $preference["widgetsubdirectory"][$directory] = $subdirectory; } } - // Récupérer en session le mode de visualisation - $sessionviewdirectory = $this->get('session')->get('sessionviewdirectory'); - if(!is_array($sessionviewdirectory)) $sessionviewdirectory=[$directory=>$defaultview]; - if(!array_key_exists($directory,$sessionviewdirectory)) $sessionviewdirectory[$directory]=$defaultview; - if($view) - $sessionviewdirectory[$directory] = $view; - $this->get('session')->set('sessionviewdirectory',$sessionviewdirectory); + // Préférence mode de visualisation + if(!array_key_exists("widgetviewdirectory",$preference)) { + $toupdate=true; + $preference["widgetviewdirectory"]=[]; + } + if((!array_key_exists($directory,$preference["widgetviewdirectory"]))) { + $toupdate=true; + $preference["widgetviewdirectory"][$directory]=$defaultview; + } + if($view&&$preference["widgetviewdirectory"][$directory]!=$view) { + $toupdate=true; + $preference["widgetviewdirectory"][$directory]=$view; + } + + // Prérence trie + if(!array_key_exists("widgetsortdirectory",$preference)) { + $toupdate=true; + $preference["widgetsortdirectory"]=[]; + } + if((!array_key_exists($directory,$preference["widgetsortdirectory"]))) { + $toupdate=true; + $preference["widgetsortdirectory"][$directory]="name"; + } + if($sort&&$preference["widgetsortdirectory"][$directory]!=$sort) { + $toupdate=true; + $preference["widgetsortdirectory"][$directory]=$sort; + } + + // Mise à jour des préferences + if($toupdate) { + $em = $this->getDoctrine()->getManager(); + $this->getUser()->setPreference($preference); + $em->persist($this->getUser()); + $em->flush(); + } // Initialiser le service only $onlyservice = $this->container->get('cadoles.portal.service.only'); @@ -84,7 +121,8 @@ class FrameController extends Controller 'subdirectory' => $subdirectory, 'files' => $files, 'canupdate' => $canupdate, - 'view' => $sessionviewdirectory[$directory], + 'view' => $preference["widgetviewdirectory"][$directory], + 'sort' => $preference["widgetsortdirectory"][$directory], 'tasks' => $tasks, 'apponly' => $apponly ]);