gestion des annonces masquables (ref #191)

This commit is contained in:
afornerot 2020-07-17 11:12:01 +02:00
parent 01fd5f297f
commit bdddfc925f
11 changed files with 178 additions and 9 deletions

View File

@ -347,6 +347,12 @@ class User implements UserInterface, \Serializable
*/ */
protected $messagesees; protected $messagesees;
/**
* @ORM\ManyToMany(targetEntity="Cadoles\PortalBundle\Entity\Alert", mappedBy="readers")
*/
protected $alertreaders;
//== CODE A NE PAS REGENERER //== CODE A NE PAS REGENERER
/** /**
* @ORM\PostLoad * @ORM\PostLoad
@ -1883,4 +1889,38 @@ class User implements UserInterface, \Serializable
{ {
return $this->niveau01other; return $this->niveau01other;
} }
/**
* Add alertreader
*
* @param \Cadoles\PortalBundle\Entity\Alert $alertreader
*
* @return User
*/
public function addAlertreader(\Cadoles\PortalBundle\Entity\Alert $alertreader)
{
$this->alertreaders[] = $alertreader;
return $this;
}
/**
* Remove alertreader
*
* @param \Cadoles\PortalBundle\Entity\Alert $alertreader
*/
public function removeAlertreader(\Cadoles\PortalBundle\Entity\Alert $alertreader)
{
$this->alertreaders->removeElement($alertreader);
}
/**
* Get alertreaders
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAlertreaders()
{
return $this->alertreaders;
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -126,6 +126,14 @@ class AlertController extends Controller
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$data = $form->getData(); $data = $form->getData();
// Si non masquable on s'assure qu'il n'y a pas de reader
if(!$data->getFghideable()) {
$readers=$data->getReaders();
foreach($readers as $reader) {
$data->removeReader($reader);
}
}
// Sauvegarde // Sauvegarde
$em->persist($data); $em->persist($data);
$em->flush(); $em->flush();
@ -187,6 +195,27 @@ class AlertController extends Controller
return $response; return $response;
} }
public function readAction(Request $request) {
$output=array();
$id=$request->request->get('id');
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository($this->labelentity)->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find entity.');
}
if(!$entity->getReaders()->contains($this->getUser())) {
$entity->addReader($this->getUser());
$em->persist($entity);
$em->flush();
}
$response = new Response(json_encode($output));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
protected function getDatas() protected function getDatas()
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();

View File

@ -804,7 +804,7 @@ class PagewidgetController extends Controller
} }
$alertsroles=$qb->getQuery()->getResult(); $alertsroles=$qb->getQuery()->getResult();
foreach($alertsroles as $alertrole) { foreach($alertsroles as $alertrole) {
if(!$alerts->contains($alertrole)) $alerts->add($alertrole); if(!$alerts->contains($alertrole)&&!$alertrole->getReaders()->contains($this->getUser())) $alerts->add($alertrole);
} }
} }
@ -826,8 +826,8 @@ class PagewidgetController extends Controller
->setParameter("alertcategory",$alertcategoryfilter); ->setParameter("alertcategory",$alertcategoryfilter);
} }
$alertsniveau01s=$qb->getQuery()->getResult(); $alertsniveau01s=$qb->getQuery()->getResult();
foreach($alertsniveau01s as $alertsniveau01) { foreach($alertsniveau01s as $alertniveau01) {
if(!$alerts->contains($alertsniveau01s)) $alerts->add($alertsniveau01); if(!$alerts->contains($alertniveau01)&&!$alertniveau01->getReaders()->contains($this->getUser())) $alerts->add($alertniveau01);
} }
// Récupération des alerts par group // Récupération des alerts par group
@ -850,7 +850,7 @@ class PagewidgetController extends Controller
} }
$alertsgroups=$qb->getQuery()->getResult(); $alertsgroups=$qb->getQuery()->getResult();
foreach($alertsgroups as $alertgroup) { foreach($alertsgroups as $alertgroup) {
if(!$alerts->contains($alertgroup)) $alerts->add($alertgroup); if(!$alerts->contains($alertgroup)&&!$alertgroup->getReaders()->contains($this->getUser())) $alerts->add($alertgroup);
} }
} }

View File

@ -60,6 +60,11 @@ class Alert
*/ */
protected $unpublishedat; protected $unpublishedat;
/**
* @ORM\Column(name="fghideable", type="boolean")
*/
private $fghideable;
/** /**
* @var string * @var string
* *
@ -91,6 +96,14 @@ class Alert
*/ */
protected $niveau01s; protected $niveau01s;
/**
* @ORM\ManyToMany(targetEntity="Cadoles\CoreBundle\Entity\User", inversedBy="alertreaders", cascade={"persist"})
* @ORM\JoinTable(name="alertuserread",
* joinColumns={@ORM\JoinColumn(name="alert", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="user", referencedColumnName="id")}
* )
*/
protected $readers;
// Is Online // Is Online
public function isOnline() public function isOnline()
@ -390,4 +403,62 @@ class Alert
{ {
return $this->niveau01s; return $this->niveau01s;
} }
/**
* Set fghideable
*
* @param boolean $fghideable
*
* @return Alert
*/
public function setFghideable($fghideable)
{
$this->fghideable = $fghideable;
return $this;
}
/**
* Get fghideable
*
* @return boolean
*/
public function getFghideable()
{
return $this->fghideable;
}
/**
* Add reader
*
* @param \Cadoles\CoreBundle\Entity\User $reader
*
* @return Alert
*/
public function addReader(\Cadoles\CoreBundle\Entity\User $reader)
{
$this->readers[] = $reader;
return $this;
}
/**
* Remove reader
*
* @param \Cadoles\CoreBundle\Entity\User $reader
*/
public function removeReader(\Cadoles\CoreBundle\Entity\User $reader)
{
$this->readers->removeElement($reader);
}
/**
* Get readers
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getReaders()
{
return $this->readers;
}
} }

View File

@ -36,6 +36,11 @@ class AlertType extends AbstractType
"config" => array("height" => "500px") "config" => array("height" => "500px")
]) ])
->add("fghideable",ChoiceType::class,[
"label" =>"Permettre aux utilisateurs de masquer l'annonce",
"choices" => ["non"=>"0","oui"=>"1"]
])
->add('alertcategory', EntityType::class, [ ->add('alertcategory', EntityType::class, [
'label' => 'Catégorie', 'label' => 'Catégorie',
'class' => 'CadolesPortalBundle:Alertcategory', 'class' => 'CadolesPortalBundle:Alertcategory',

View File

@ -163,6 +163,9 @@ cadoles_portal_config_ajax_alert_seleclist:
path: /config/alert/ajax/selectlist path: /config/alert/ajax/selectlist
defaults: { _controller: CadolesPortalBundle:Alert:ajaxseleclist } defaults: { _controller: CadolesPortalBundle:Alert:ajaxseleclist }
cadoles_portal_user_alert_read:
path: /user/alert/read
defaults: { _controller: CadolesPortalBundle:Alert:read }
#== ALERT CATEGORY ======================================================================================================================================= #== ALERT CATEGORY =======================================================================================================================================

View File

@ -46,6 +46,7 @@
<div class="form-group row clearfix"> <div class="form-group row clearfix">
<div class="col-md-8"> <div class="col-md-8">
{{ form_row(form.title) }} {{ form_row(form.title) }}
{{ form_row(form.fghideable) }}
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
{{ form_row(form.alertcategory) }} {{ form_row(form.alertcategory) }}

View File

@ -547,7 +547,7 @@
var grid = $('.grid').masonry(optiongrid); var grid = $('.grid').masonry(optiongrid);
} }
// Place un message en leur // Place un message en lu
function hideMessage(id) { function hideMessage(id) {
$.ajax({ $.ajax({
method: "POST", method: "POST",
@ -566,4 +566,20 @@
} }
}); });
} }
// Place un message en lu
function hideAlert(id) {
$.ajax({
method: "POST",
url: "{{ path('cadoles_portal_user_alert_read') }}",
data: {
id:id
},
success: function() {
$("#alert-"+id).remove();
var grid = $('.grid').masonry(optiongrid);
}
});
}
{% endblock %} {% endblock %}

View File

@ -32,7 +32,7 @@
<div class="widgetbody" style="{{ stylewidgetbody }}"> <div class="widgetbody" style="{{ stylewidgetbody }}">
{% for alert in alerts %} {% for alert in alerts %}
<div class="panel list-item" style="background: {{ alert.alertcategory.color ? '#'~alert.alertcategory.color : '#'~colormain }};"> <div id="alert-{{ alert.id }}" class="panel list-item" style="background: {{ alert.alertcategory.color ? '#'~alert.alertcategory.color : '#'~colormain }};">
<div class="panel-heading" role="tab"> <div class="panel-heading" role="tab">
{% if alert.alertcategory.icon %} {% if alert.alertcategory.icon %}
<img height="25" src="/{{ alias }}/{{ alert.alertcategory.icon.label }}"> <img height="25" src="/{{ alias }}/{{ alert.alertcategory.icon.label }}">
@ -41,9 +41,13 @@
{% endif %} {% endif %}
{{ alert.title }} {{ alert.title }}
{% if alert.fghideable and app.user %}
&nbsp;<a onClick="hideAlert({{alert.id}})" style="cursor:pointer;" title="Ne plus afficher"><i class="fa fa-eye-slash"></i></a>
{%endif%}
</div> </div>
<div id="alert-{{ alert.id }}" class="panel-body"> <div class="panel-body">
{{ alert.content|raw }} {{ alert.content|raw }}
</div> </div>