prefence user

This commit is contained in:
afornerot 2020-09-22 10:15:57 +02:00
parent ea2af3b861
commit 8f2e412b60
5 changed files with 149 additions and 55 deletions

View File

@ -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);
// 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;
}
// 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é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],
]);
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -73,9 +73,9 @@
<a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'clear':true,'sort':action }) }}" type="button" class="btn btn-primary">
{% endif %}
{% if sort=="name" %}
<i class="fas fa-sort-alpha-down"></i>
<i class="fas fa-long-arrow-alt-down"></i> Nom
{% else %}
<i class="fas fa-sort-numeric-down"></i>
<i class="fas fa-long-arrow-alt-down"></i> Date
{% endif %}
</a>
</div>

View File

@ -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
]);