This commit is contained in:
afornerot 2024-11-03 18:32:47 +01:00
parent 71eb7db988
commit 8d2970959c
4 changed files with 42 additions and 229 deletions

View File

@ -269,7 +269,7 @@ app_link_delete:
#== Slide =====================================================================================================
app_slide:
path: /slide
path: /slide/{userpseudo}
defaults: { _controller: App\Controller\SlideController:slide }
#== Home USer==================================================================================================

View File

@ -17,229 +17,30 @@ class SlideController extends AbstractController
private $render = "Illustration/";
private $entity = "App:Illustration";
public function slide(Request $request)
public function slide($userpseudo,Request $request)
{
$em = $this->getDoctrine()->getManager();
$datas = $em->getRepository($this->entity)->findAll();
$user=$em->getRepository("App:User")->findOneBy(["slug"=>$userpseudo]);
if(!$user) return $this->redirectToRoute("app_home");
$qb = $em ->createQueryBuilder()
->select('i')
->from("App:Illustration", 'i')
->from("App:Category", 'c')
->from("App:User",'u')
->Where('c=i.category')
->andWhere('u=c.user')
->andWhere('u.slug=:userpseudo')
->setParameter('userpseudo',$userpseudo)
->orderBy('i.submittime','DESC');
$illustrations=$qb->getQuery()->getResult();
return $this->render($this->render.'slide.html.twig',[
$this->data."s" => $datas,
$this->data."s" => $illustrations,
"useheader" => false,
"usesidebar" => false,
"usemonocolor" => true,
"user" => $user,
]);
}
public function view($idcat,$id,Request $request)
{
$em = $this->getDoctrine()->getManager();
$data=$em->getRepository($this->entity)->find($id);
$datanext=$this->getDataAllNext($idcat,$id);
$dataprev=$this->getDataAllPrev($idcat,$id);
$pathinfo=pathinfo($data->getIllustration());
if(!$data) return $this->redirectToRoute('app_home');
return $this->render($this->render.'view.html.twig', array(
$this->data => $data,
"prev" => $dataprev,
"next" => $datanext,
"pathinfo" => $pathinfo,
"usemonocolor" => true,
));
}
public function submit($by, Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$data = new Entity();
// Création du formulaire
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur erreur
$this->getErrorForm(null,$form,$request,$data,"submit");
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
$data->setSubmittime(new \DateTime());
$em->persist($data);
$em->flush();
// Retour à la liste
if($by=="console")
return $this->redirectToRoute($this->route);
else
return $this->redirectToRoute("app_home");
}
// Affichage du formulaire
return $this->render($this->render.'edit.html.twig', [
'useheader' => true,
'usesidebar' => false,
$this->data => $data,
'mode' => 'submit',
'form' => $form->createView(),
'by' => $by,
]);
}
public function update($id,$by,Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$data=$em->getRepository($this->entity)->find($id);
// Création du formulaire
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur erreur
$this->getErrorForm($id,$form,$request,$data,"update");
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
$em->persist($data);
$em->flush();
// Retour à l'illustration
if($by=="console")
return $this->redirectToRoute($this->route);
else
return $this->redirectToRoute($this->route.'_view',array("idcat"=>$data->getCategory()->getId(),"id"=> $id));
}
// Affichage du formulaire
return $this->render($this->render.'edit.html.twig', [
'useheader' => true,
'usesidebar' => false,
$this->data => $data,
'mode' => 'update',
'form' => $form->createView(),
'by' => $by,
]);
}
public function delete($id,$by,Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$data=$em->getRepository($this->entity)->find($id);
// Controle avant suppression
$error=false;
if($id<0) $error=true;
if($error)
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
else {
$em->remove($data);
$em->flush();
// Retour à la liste
if($by=="console")
return $this->redirectToRoute($this->route);
else
return $this->redirectToRoute("app_home");
}
}
public function upload()
{
return $this->render($this->render.'upload.html.twig');
}
protected function getDataAllNext($idcat,$id)
{
$em = $this->getDoctrine()->getManager();
$data = $em->createQueryBuilder()
->select('e')
->from($this->entity, 'e')
->where('e.id>:id')
->andWhere('e.category=:idcat')
->getQuery()
->setParameter("id", $id)
->setParameter("idcat", $idcat)
->setMaxResults(1)
->getResult();
// Si pas de suivant on recherche le premier
if(!$data) {
$data = $em->createQueryBuilder()
->select('e')
->from($this->entity, 'e')
->Where('e.category=:idcat')
->getQuery()
->setParameter("idcat", $idcat)
->setMaxResults(1)
->getResult();
}
return $data;
}
protected function getDataAllPrev($idcat,$id)
{
$em = $this->getDoctrine()->getManager();
$data = $em->createQueryBuilder()
->select('e')
->from($this->entity, 'e')
->where('e.id<:id')
->andWhere('e.category=:idcat')
->orderBy('e.id','DESC')
->getQuery()
->setParameter("id", $id)
->setParameter("idcat", $idcat)
->setMaxResults(1)
->getResult();
// Si pas de précedent on recherche le dernier
if(!$data) {
$data = $em->createQueryBuilder()
->select('e')
->from($this->entity, 'e')
->Where('e.category=:idcat')
->orderBy('e.id','DESC')
->getQuery()
->setParameter("idcat", $idcat)
->setMaxResults(1)
->getResult();
}
return $data;
}
protected function getErrorForm($id,$form,$request,$data,$mode) {
if ($form->get('submit')->isClicked()&&$mode=="delete") {
}
if ($form->get('submit')->isClicked() && $mode=="submit") {
}
if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) {
}
if ($form->get('submit')->isClicked() && !$form->isValid()) {
$this->get('session')->getFlashBag()->clear();
$errors = $form->getErrors();
foreach( $errors as $error ) {
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
}
}
}
}

View File

@ -189,6 +189,7 @@
<a href="{{ config.youtube }}" target="_blank" title="Youtube"><i class="fab fa-youtube fa-2x"></i></a>
{% endif %}
<a href="{{ path("app_feeduser",{userpseudo:user.slug}) }}" target="_blank" title="RSS"><i class="fa fa-rss-square fa-2x"></i></a>
<a href="{{ path("app_slide",{userpseudo:user.slug}) }}" target="_blank" title="RSS"><i class="fa fa-play fa-2x"></i></a>
</div>
@ -355,13 +356,14 @@
{% if not config.appsubname is empty %}
{{ config.appsubname }}<br>
{%endif%}
{% if not config.appdescription is empty %}
<small><br>{{ config.appdescription|raw }}</small><br>
{%endif%}
<br>
{% if user.email is not empty or config.facebook is not empty or config.instagram is not empty or config.twitter is not empty or config.google is not empty or config.youtube is not empty %}
<br><br>
{% endif %}
{% if user.email is not empty %}
<i class="fas fa-envelope"></i> Email = <a href="mailto:{{ user.email }}" target="_blank" title="Email">{{ user.email }}</a><br>

View File

@ -20,8 +20,17 @@
/*box-shadow: 0px 0px 5px 1px rgba(255, 255, 255, 0.45);*/
}
</style>
<div id="content" style="display:flex">
<div style="width:70%; overflow:hidden;padding-left:35px;test-align:center;">
<img style="display:none;" id="illustration_illustration_img" src="/{{ appAlias }}/uploads/illustration/{{illustrations[0].illustration}}">
</div>
<div style="width:30%; display:flex; flex-direction: column; align-items:center;padding-top:15px">
<img src="{{asset("uploads/avatar/"~user.avatar)}}" style="width:150px; height:150px;border-radius:100%">
<h2 style="flex-grow:1">{{user.pseudo}}</h2>
{% set qrCode = qr_code_result(absolute_url(path("app_home_user",{userpseudo:user.slug}))) %}
<img src="{{ qrCode.dataUri }}" width="200px" />
</div>
</div>
{% endblock %}
{% block localjavascript %}
@ -47,8 +56,8 @@
}
function resizeImage() {
console.log("resize")
height=$(window).height()-70;
height=$(window).height()-35;
$("#content").height($(window).height()-35);
$("#illustration_illustration_img").css({height:height,width:'auto'});
width=$(window).width()-90;
@ -56,8 +65,6 @@
$("#illustration_illustration_img").css({width:width,height:'auto'});
height=$("#illustration_illustration_img").height();
$("#bigright").css({height:height,"line-height":height+"px"});
$("#bigleft").css({height:height,"line-height":height+"px"});
}
$(document).ready(function() {
@ -65,7 +72,9 @@
tbimg.push("{{illustration.illustration}}");
{% endfor %}
tbimg=shuffle(tbimg)
tbimg=shuffle(tbimg);
total=tbimg.length;
console.log(total);
$('body').imagesLoaded(function() {
resizeImage();
$("#illustration_illustration_img").fadeIn();
@ -73,6 +82,7 @@
var intervalId = window.setInterval(function(){
posImg++;
if(posImg>=total) posImg=0;
img=tbimg[posImg];
console.log(img);
url="/{{ appAlias }}/uploads/illustration/xxx";