gestion des annonces masquables (ref #191)
This commit is contained in:
parent
01fd5f297f
commit
bdddfc925f
|
@ -347,6 +347,12 @@ class User implements UserInterface, \Serializable
|
|||
*/
|
||||
protected $messagesees;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Cadoles\PortalBundle\Entity\Alert", mappedBy="readers")
|
||||
*/
|
||||
protected $alertreaders;
|
||||
|
||||
|
||||
//== CODE A NE PAS REGENERER
|
||||
/**
|
||||
* @ORM\PostLoad
|
||||
|
@ -1883,4 +1889,38 @@ class User implements UserInterface, \Serializable
|
|||
{
|
||||
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 |
|
@ -126,6 +126,14 @@ class AlertController extends Controller
|
|||
$em = $this->getDoctrine()->getManager();
|
||||
$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
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
@ -187,6 +195,27 @@ class AlertController extends Controller
|
|||
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()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
|
|
@ -804,7 +804,7 @@ class PagewidgetController extends Controller
|
|||
}
|
||||
$alertsroles=$qb->getQuery()->getResult();
|
||||
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);
|
||||
}
|
||||
$alertsniveau01s=$qb->getQuery()->getResult();
|
||||
foreach($alertsniveau01s as $alertsniveau01) {
|
||||
if(!$alerts->contains($alertsniveau01s)) $alerts->add($alertsniveau01);
|
||||
foreach($alertsniveau01s as $alertniveau01) {
|
||||
if(!$alerts->contains($alertniveau01)&&!$alertniveau01->getReaders()->contains($this->getUser())) $alerts->add($alertniveau01);
|
||||
}
|
||||
|
||||
// Récupération des alerts par group
|
||||
|
@ -850,7 +850,7 @@ class PagewidgetController extends Controller
|
|||
}
|
||||
$alertsgroups=$qb->getQuery()->getResult();
|
||||
foreach($alertsgroups as $alertgroup) {
|
||||
if(!$alerts->contains($alertgroup)) $alerts->add($alertgroup);
|
||||
if(!$alerts->contains($alertgroup)&&!$alertgroup->getReaders()->contains($this->getUser())) $alerts->add($alertgroup);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,11 @@ class Alert
|
|||
*/
|
||||
protected $unpublishedat;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="fghideable", type="boolean")
|
||||
*/
|
||||
private $fghideable;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
|
@ -90,7 +95,15 @@ class Alert
|
|||
* )
|
||||
*/
|
||||
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
|
||||
public function isOnline()
|
||||
|
@ -390,4 +403,62 @@ class Alert
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,11 @@ class AlertType extends AbstractType
|
|||
"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, [
|
||||
'label' => 'Catégorie',
|
||||
'class' => 'CadolesPortalBundle:Alertcategory',
|
||||
|
|
|
@ -163,6 +163,9 @@ cadoles_portal_config_ajax_alert_seleclist:
|
|||
path: /config/alert/ajax/selectlist
|
||||
defaults: { _controller: CadolesPortalBundle:Alert:ajaxseleclist }
|
||||
|
||||
cadoles_portal_user_alert_read:
|
||||
path: /user/alert/read
|
||||
defaults: { _controller: CadolesPortalBundle:Alert:read }
|
||||
|
||||
|
||||
#== ALERT CATEGORY =======================================================================================================================================
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
<div class="form-group row clearfix">
|
||||
<div class="col-md-8">
|
||||
{{ form_row(form.title) }}
|
||||
{{ form_row(form.fghideable) }}
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
{{ form_row(form.alertcategory) }}
|
||||
|
|
|
@ -547,7 +547,7 @@
|
|||
var grid = $('.grid').masonry(optiongrid);
|
||||
}
|
||||
|
||||
// Place un message en leur
|
||||
// Place un message en lu
|
||||
function hideMessage(id) {
|
||||
$.ajax({
|
||||
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 %}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
<div class="widgetbody" style="{{ stylewidgetbody }}">
|
||||
{% 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">
|
||||
{% if alert.alertcategory.icon %}
|
||||
<img height="25" src="/{{ alias }}/{{ alert.alertcategory.icon.label }}">
|
||||
|
@ -40,10 +40,14 @@
|
|||
<img height="25" src="/{{ alias }}/uploads/icon/icon_megaphone.png">
|
||||
{% endif %}
|
||||
|
||||
{{ alert.title }}
|
||||
{{ alert.title }}
|
||||
{% if alert.fghideable and app.user %}
|
||||
<a onClick="hideAlert({{alert.id}})" style="cursor:pointer;" title="Ne plus afficher"><i class="fa fa-eye-slash"></i></a>
|
||||
{%endif%}
|
||||
|
||||
</div>
|
||||
|
||||
<div id="alert-{{ alert.id }}" class="panel-body">
|
||||
<div class="panel-body">
|
||||
{{ alert.content|raw }}
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue