commit
This commit is contained in:
parent
bf1c7299b1
commit
030fd9a119
|
@ -153,7 +153,7 @@ class Group
|
||||||
* @var ArrayCollection $message
|
* @var ArrayCollection $message
|
||||||
* @var Message
|
* @var Message
|
||||||
*
|
*
|
||||||
* @ORM\OneToMany(targetEntity="Cadoles\WebsocketBundle\Entity\Message", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
|
* @ORM\OneToMany(targetEntity="Cadoles\WebsocketBundle\Entity\Message", mappedBy="group", cascade={"persist"}, orphanRemoval=true)
|
||||||
*/
|
*/
|
||||||
protected $messages;
|
protected $messages;
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,12 @@ class User implements UserInterface, \Serializable
|
||||||
* @ORM\OneToMany(targetEntity="Cadoles\WebsocketBundle\Entity\Message", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
|
* @ORM\OneToMany(targetEntity="Cadoles\WebsocketBundle\Entity\Message", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
|
||||||
*/
|
*/
|
||||||
private $messages;
|
private $messages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToMany(targetEntity="Cadoles\WebsocketBundle\Entity\Message", mappedBy="readers")
|
||||||
|
*/
|
||||||
|
protected $messagereaders;
|
||||||
|
|
||||||
|
|
||||||
//== CODE A NE PAS REGENERER
|
//== CODE A NE PAS REGENERER
|
||||||
/**
|
/**
|
||||||
|
@ -1382,4 +1387,38 @@ class User implements UserInterface, \Serializable
|
||||||
{
|
{
|
||||||
return $this->messages;
|
return $this->messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add messagereader
|
||||||
|
*
|
||||||
|
* @param \Cadoles\WebsocketBundle\Entity\Message $messagereader
|
||||||
|
*
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
|
public function addMessagereader(\Cadoles\WebsocketBundle\Entity\Message $messagereader)
|
||||||
|
{
|
||||||
|
$this->messagereaders[] = $messagereader;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove messagereader
|
||||||
|
*
|
||||||
|
* @param \Cadoles\WebsocketBundle\Entity\Message $messagereader
|
||||||
|
*/
|
||||||
|
public function removeMessagereader(\Cadoles\WebsocketBundle\Entity\Message $messagereader)
|
||||||
|
{
|
||||||
|
$this->messagereaders->removeElement($messagereader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get messagereaders
|
||||||
|
*
|
||||||
|
* @return \Doctrine\Common\Collections\Collection
|
||||||
|
*/
|
||||||
|
public function getMessagereaders()
|
||||||
|
{
|
||||||
|
return $this->messagereaders;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,10 @@ body {
|
||||||
font-size: 35px;
|
font-size: 35px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.navbar-top-links li a .badge {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 767px) {
|
@media (max-width: 767px) {
|
||||||
.navbar-default .navbar-header #title {
|
.navbar-default .navbar-header #title {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
|
@ -152,7 +152,7 @@
|
||||||
{% block localexternalscript %}
|
{% block localexternalscript %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
{% block localjavascript %}
|
{% block localjavascript %}
|
||||||
|
|
||||||
|
|
|
@ -446,7 +446,7 @@ class PageController extends Controller
|
||||||
public function viewAction(Request $request,$id,$access=null) {
|
public function viewAction(Request $request,$id,$access=null) {
|
||||||
// usage soit portal / user / group
|
// usage soit portal / user / group
|
||||||
$usage=$request->query->get('usage');
|
$usage=$request->query->get('usage');
|
||||||
$group=$request->query->get('group');
|
$groupid=$request->query->get('group');
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$entity = $em->getRepository($this->labelentity)->find($id);
|
$entity = $em->getRepository($this->labelentity)->find($id);
|
||||||
|
@ -474,6 +474,44 @@ class PageController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On marque tt les messages comme lu par l'utilisateur
|
||||||
|
|
||||||
|
if($usage=="group") {
|
||||||
|
// On calcule le nombre de message non lu pour le groupe
|
||||||
|
$group=$em->getRepository("CadolesCoreBundle:Group")->find($groupid);
|
||||||
|
$qb = $em ->createQueryBuilder();
|
||||||
|
$tm = $qb ->select($qb->expr()->count('m.id'))
|
||||||
|
->from('CadolesWebsocketBundle:Message', 'm')
|
||||||
|
->where('m.group = :group')
|
||||||
|
->andWhere('m.user != :user')
|
||||||
|
->setParameter('group', $group)
|
||||||
|
->setParameter('user', $this->getUser())
|
||||||
|
->getQuery()->getSingleScalarResult();
|
||||||
|
|
||||||
|
$qb = $em ->createQueryBuilder();
|
||||||
|
$tr = $qb ->select($qb->expr()->count('m.id'))
|
||||||
|
->from('CadolesWebsocketBundle:Message', 'm')
|
||||||
|
->where('m.group = :group')
|
||||||
|
->andWhere('m.user != :user')
|
||||||
|
->andWhere(':user MEMBER OF m.readers')
|
||||||
|
->setParameter('group', $group)
|
||||||
|
->setParameter('user', $this->getUser())
|
||||||
|
->getQuery()->getSingleScalarResult();
|
||||||
|
|
||||||
|
if($tm-$tr>0) {
|
||||||
|
$messages=$em->getRepository("CadolesWebsocketBundle:Message")->findBy(["group"=>$group]);
|
||||||
|
foreach($messages as $message) {
|
||||||
|
$readers=$message->getReaders();
|
||||||
|
if ( !$readers->contains($this->getUser()) ) {
|
||||||
|
$message->addReader($this->getUser());
|
||||||
|
}
|
||||||
|
$em->persist($message);
|
||||||
|
$em->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Type Calendrier
|
// Type Calendrier
|
||||||
if($entity->getPageCategory()->getId()==-100) {
|
if($entity->getPageCategory()->getId()==-100) {
|
||||||
$entity->setUrl($this->generateUrl('cadoles_portal_user_calendar_view'));
|
$entity->setUrl($this->generateUrl('cadoles_portal_user_calendar_view'));
|
||||||
|
@ -485,7 +523,7 @@ class PageController extends Controller
|
||||||
'access' => $access,
|
'access' => $access,
|
||||||
'canupdate' => $canupdate,
|
'canupdate' => $canupdate,
|
||||||
'usage' => $usage,
|
'usage' => $usage,
|
||||||
'group' => $group
|
'group' => $groupid
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +538,7 @@ class PageController extends Controller
|
||||||
'access' => $access,
|
'access' => $access,
|
||||||
'canupdate' => $canupdate,
|
'canupdate' => $canupdate,
|
||||||
'usage' => $usage,
|
'usage' => $usage,
|
||||||
'group' => $group
|
'group' => $groupid
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +552,7 @@ class PageController extends Controller
|
||||||
'access' => $access,
|
'access' => $access,
|
||||||
'canupdate' => $canupdate,
|
'canupdate' => $canupdate,
|
||||||
'usage' => $usage,
|
'usage' => $usage,
|
||||||
'group' => $group
|
'group' => $groupid
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// Type Widgets
|
// Type Widgets
|
||||||
|
@ -529,7 +567,7 @@ class PageController extends Controller
|
||||||
'mode' => "view",
|
'mode' => "view",
|
||||||
'widgets' => $this->getDoctrine()->getRepository("CadolesPortalBundle:Widget")->getWidgetAccess($access,'config'),
|
'widgets' => $this->getDoctrine()->getRepository("CadolesPortalBundle:Widget")->getWidgetAccess($access,'config'),
|
||||||
'usage' => $usage,
|
'usage' => $usage,
|
||||||
'group' => $group
|
'group' => $groupid
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// Type Editeur
|
// Type Editeur
|
||||||
|
@ -542,7 +580,7 @@ class PageController extends Controller
|
||||||
'access' => $access,
|
'access' => $access,
|
||||||
'canupdate' => $canupdate,
|
'canupdate' => $canupdate,
|
||||||
'usage' => $usage,
|
'usage' => $usage,
|
||||||
'group' => $group
|
'group' => $groupid
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1875,7 +1875,7 @@ class PagewidgetController extends Controller
|
||||||
'tool' => "cadoles_websocket_chat",
|
'tool' => "cadoles_websocket_chat",
|
||||||
'access' => $access,
|
'access' => $access,
|
||||||
'usage' => $usage,
|
'usage' => $usage,
|
||||||
'group' => $group
|
'group' => $group,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,6 @@ class Page
|
||||||
private $templategroups;
|
private $templategroups;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* champs calculé non stocké en base */
|
/* champs calculé non stocké en base */
|
||||||
private $canupdate;
|
private $canupdate;
|
||||||
|
@ -147,6 +146,17 @@ class Page
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* champs calculé non stocké en base */
|
||||||
|
private $counterread;
|
||||||
|
public function getCounterRead()
|
||||||
|
{
|
||||||
|
return $this->counterread;
|
||||||
|
}
|
||||||
|
public function setCounterRead($counterread)
|
||||||
|
{
|
||||||
|
$this->counterread = $counterread;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
// A garder pour forcer l'id en init
|
// A garder pour forcer l'id en init
|
||||||
public function setId($id)
|
public function setId($id)
|
||||||
|
|
|
@ -131,6 +131,29 @@ class PageRepository extends EntityRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On calcule le nombre de message non lu pour le groupe
|
||||||
|
$tm = $this ->getEntityManager()->createQueryBuilder()
|
||||||
|
->select($qb->expr()->count('m.id'))
|
||||||
|
->from('CadolesWebsocketBundle:Message', 'm')
|
||||||
|
->where('m.group = :group')
|
||||||
|
->andWhere('m.user != :user')
|
||||||
|
->setParameter('group', $groupshared)
|
||||||
|
->setParameter('user', $user)
|
||||||
|
->getQuery()->getSingleScalarResult();
|
||||||
|
|
||||||
|
$tr = $this ->getEntityManager()->createQueryBuilder()
|
||||||
|
->select($qb->expr()->count('m.id'))
|
||||||
|
->from('CadolesWebsocketBundle:Message', 'm')
|
||||||
|
->where('m.group = :group')
|
||||||
|
->andWhere('m.user != :user')
|
||||||
|
->andWhere(':user MEMBER OF m.readers')
|
||||||
|
->setParameter('group', $groupshared)
|
||||||
|
->setParameter('user', $user)
|
||||||
|
->getQuery()->getSingleScalarResult();
|
||||||
|
foreach($pagesshared as $key2 => $pageshared) {
|
||||||
|
$pagesshared[$key2]->setCounterRead($tm-$tr);
|
||||||
|
}
|
||||||
|
|
||||||
$groupsshared[$key]->pagesshared=$pagesshared;
|
$groupsshared[$key]->pagesshared=$pagesshared;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,30 @@
|
||||||
{% set forcereload=false %}
|
{% set forcereload=false %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% set isactive="" %}
|
||||||
{% if entity.id is defined and page.id==entity.id %}
|
{% if entity.id is defined and page.id==entity.id %}
|
||||||
<li id="menupage-{{page.id}}" class="active" style="cursor:pointer"><a onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','group','{{forcereload}}','{{groupshared.id}}')">Groupe = {{ groupshared.label }}</a></li>
|
{% set isactive="class='active'" %}
|
||||||
{% else %}
|
|
||||||
<li id="menupage-{{page.id}}"><a style="cursor:pointer" onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','group','{{forcereload}}','{{groupshared.id}}')">Groupe = {{ groupshared.label }}</a></li>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<li id="menupage-{{page.id}}" {{ isactive }} style="cursor:pointer">
|
||||||
|
<a data-group="{{groupshared.id}}" onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','group','{{forcereload}}','{{groupshared.id}}')">
|
||||||
|
Groupe = {{ groupshared.label }}
|
||||||
|
{% if page.counterread > 0 %}
|
||||||
|
<span id="badge-{{groupshared.id}}" class="badge">{{page.counterread}}</span>
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<ul id="pagesshared" class="nav navbar-top-links navbar-left">
|
<ul id="pagesshared" class="nav navbar-top-links navbar-left">
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Groupe = {{ groupshared.label }}<span class="caret"></span></a>
|
<a data-group="{{groupshared.id}}" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
|
||||||
|
Groupe = {{ groupshared.label }}
|
||||||
|
<span class="caret"></span>
|
||||||
|
{% if groupshared.pagesshared[0].counterread > 0 %}
|
||||||
|
<span id="badge-{{groupshared.id}}" class="badge">{{groupshared.pagesshared[0].counterread}}</span>
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
|
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
{% for page in groupshared.pagesshared %}
|
{% for page in groupshared.pagesshared %}
|
||||||
{% set forcereload=true %}
|
{% set forcereload=true %}
|
||||||
|
@ -61,11 +76,16 @@
|
||||||
{% set forcereload=false %}
|
{% set forcereload=false %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% set isactive="" %}
|
||||||
{% if entity.id is defined and page.id==entity.id %}
|
{% if entity.id is defined and page.id==entity.id %}
|
||||||
<li id="menupage-{{page.id}}" class="active" style="cursor:pointer"><a onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','group','{{forcereload}}','{{groupshared.id}}')">{{ page.name }}</a></li>
|
{% set isactive="class='active'" %}
|
||||||
{% else %}
|
|
||||||
<li id="menupage-{{page.id}}"><a style="cursor:pointer" onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','group','{{forcereload}}','{{groupshared.id}}')">{{ page.name }}</a></li>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<li id="menupage-{{page.id}}" {{isactive}} style="cursor:pointer">
|
||||||
|
<a onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','group','{{forcereload}}','{{groupshared.id}}')">
|
||||||
|
{{ page.name }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
@ -182,7 +202,19 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{%if app.user %}
|
||||||
|
<a id="refreshcounter" data-event=""></a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block localexternalscript %}
|
||||||
|
{% if app.user %}
|
||||||
|
<script src="/{{alias}}/bundles/goswebsocket/js/vendor/autobahn.min.js"></script>
|
||||||
|
<script src="/{{alias}}/bundles/goswebsocket/js/gos_web_socket_client.js"></script>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block localjavascript %}
|
{% block localjavascript %}
|
||||||
|
@ -235,7 +267,55 @@
|
||||||
responsive: true,
|
responsive: true,
|
||||||
iDisplayLength: 10,
|
iDisplayLength: 10,
|
||||||
order: [[ 1, "asc" ]],
|
order: [[ 1, "asc" ]],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Init socket de counter
|
||||||
|
var _WS_URI = "wss://{{ gos_web_socket_server_host }}:{{ gos_web_socket_server_port }}";
|
||||||
|
var _WS_URI = "wss://{{ gos_web_socket_server_host }}:5555";
|
||||||
|
|
||||||
|
var webSocket = WS.connect(_WS_URI);
|
||||||
|
var globalsession;
|
||||||
|
|
||||||
|
webSocket.on("socket/connect", function (session) {
|
||||||
|
globalsession=session;
|
||||||
|
session.call("websocket/rpc/update_connection_data", {"userid": "{{app.user.id}}" }).then(
|
||||||
|
function (result)
|
||||||
|
{
|
||||||
|
//console.log("RPC Valid!", result);
|
||||||
|
},
|
||||||
|
function (error, desc)
|
||||||
|
{
|
||||||
|
//console.log("RPC Error", error, desc);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// The callback function in "subscribe" is called everytime an event is published in that channel.
|
||||||
|
session.subscribe("websocket/counter", function (uri, payload) {
|
||||||
|
if(payload.log) {
|
||||||
|
console.log("Received message", payload.log);
|
||||||
|
}
|
||||||
|
if(payload.alert) {
|
||||||
|
alert(payload.alert);
|
||||||
|
}
|
||||||
|
if(payload.from!={{app.user.id}}) {
|
||||||
|
menu=$("a[data-group='"+payload.group+"']");
|
||||||
|
if(menu.length) {
|
||||||
|
if(payload.add) {
|
||||||
|
console.log("Ajout counter pour group "+payload.group+" by "+payload.from);
|
||||||
|
if(menu.children(".badge").length) {
|
||||||
|
menu.children(".badge").html(+(menu.children(".badge").html())+1);
|
||||||
|
}
|
||||||
|
else menu.append("<span id='badge-"+payload.group+"' class='badge'>1</span");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '#refreshcounter', function(){
|
||||||
|
event=$(this).data("event");
|
||||||
|
session.publish("websocket/counter", event);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(window).resize(function() {
|
$(window).resize(function() {
|
||||||
|
@ -308,6 +388,11 @@
|
||||||
else
|
else
|
||||||
$("#pagecontainer").append("<iframe id='page-"+id+"' data-category='"+catid+"' class='pageframe' src='"+url+"' style='border:none; width:100%'></iframe>");
|
$("#pagecontainer").append("<iframe id='page-"+id+"' data-category='"+catid+"' class='pageframe' src='"+url+"' style='border:none; width:100%'></iframe>");
|
||||||
|
|
||||||
|
// Détruire le badge associé car normalement de fait on a lu les notif
|
||||||
|
if(usage=="group") {
|
||||||
|
$("#badge-"+groupid).remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Cacher les actions possibles sur la page
|
// Cacher les actions possibles sur la page
|
||||||
$("#menuupdate").hide();
|
$("#menuupdate").hide();
|
||||||
|
@ -377,4 +462,9 @@
|
||||||
$(location).attr('href', url);
|
$(location).attr('href', url);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Permet de déclencher l'évenement de modification des counter
|
||||||
|
function counter(event) {
|
||||||
|
$('#refreshcounter').data("event",event);
|
||||||
|
$('#refreshcounter').click();
|
||||||
|
};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -74,6 +74,7 @@ class ChatController extends Controller
|
||||||
'border' => $border,
|
'border' => $border,
|
||||||
'colorbodyback' => $colorbodyback,
|
'colorbodyback' => $colorbodyback,
|
||||||
'colorbodyfont' => $colorbodyfont,
|
'colorbodyfont' => $colorbodyfont,
|
||||||
|
'fgmanager' => ($usergroup->getFgmanager()||$user->getRole()=="ROLE_ADMIN"||$user->getRole()=="ROLE_MODO"),
|
||||||
'form' => $form->createView()
|
'form' => $form->createView()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,17 @@ class Message
|
||||||
*/
|
*/
|
||||||
private $group;
|
private $group;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToMany(targetEntity="Cadoles\CoreBundle\Entity\User", inversedBy="messagereaders", cascade={"persist"})
|
||||||
|
* @ORM\JoinTable(name="messageuser",
|
||||||
|
* joinColumns={@ORM\JoinColumn(name="message", referencedColumnName="id")},
|
||||||
|
* inverseJoinColumns={@ORM\JoinColumn(name="user", referencedColumnName="id")}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
protected $readers;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -155,4 +166,38 @@ class Message
|
||||||
{
|
{
|
||||||
return $this->group;
|
return $this->group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add reader
|
||||||
|
*
|
||||||
|
* @param \Cadoles\CoreBundle\Entity\User $reader
|
||||||
|
*
|
||||||
|
* @return Message
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ class RPCService implements RpcInterface {
|
||||||
*/
|
*/
|
||||||
public function updateConnectionData(ConnectionInterface $connection, WampRequest $request, $params) {
|
public function updateConnectionData(ConnectionInterface $connection, WampRequest $request, $params) {
|
||||||
$connection->userkey = $params['userkey'];
|
$connection->userkey = $params['userkey'];
|
||||||
|
$connection->userid = $params['userid'];
|
||||||
|
|
||||||
return array("result" => array_sum($params));
|
return array("result" => array_sum($params));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,12 @@ services:
|
||||||
tags:
|
tags:
|
||||||
- { name: gos_web_socket.topic }
|
- { name: gos_web_socket.topic }
|
||||||
|
|
||||||
|
cadoles.websocket.counter:
|
||||||
|
class: Cadoles\WebsocketBundle\Topic\WebsocketCounter
|
||||||
|
arguments: ['@gos_web_socket.websocket.client_manipulator','@doctrine.orm.entity_manager','@service_container']
|
||||||
|
tags:
|
||||||
|
- { name: gos_web_socket.topic }
|
||||||
|
|
||||||
cadoles.websocket.rpc:
|
cadoles.websocket.rpc:
|
||||||
class: Cadoles\WebsocketBundle\RPC\RPCService
|
class: Cadoles\WebsocketBundle\RPC\RPCService
|
||||||
tags:
|
tags:
|
||||||
|
|
|
@ -6,6 +6,11 @@ websocket_topic:
|
||||||
group:
|
group:
|
||||||
pattern: '[-+]?\d+'
|
pattern: '[-+]?\d+'
|
||||||
|
|
||||||
|
websocket_counter:
|
||||||
|
channel: websocket/counter
|
||||||
|
handler:
|
||||||
|
callback: 'websocket.counter'
|
||||||
|
|
||||||
websocket_rpc:
|
websocket_rpc:
|
||||||
channel: websocket/rpc/{method}
|
channel: websocket/rpc/{method}
|
||||||
handler:
|
handler:
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
.msgavatar {
|
.msgavatar {
|
||||||
float:left;
|
float:left;
|
||||||
height:40px;
|
height:40px;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
.msgdiv {
|
.msgdiv {
|
||||||
float:left;
|
float:left;
|
||||||
|
@ -52,7 +53,9 @@
|
||||||
<div id='message-{{message.id}}' class='message row'>
|
<div id='message-{{message.id}}' class='message row'>
|
||||||
<div class='msgavatar'>
|
<div class='msgavatar'>
|
||||||
<img id='user_avatar_img' src='/{{ alias }}/uploads/avatar/{{message.user.avatar}}' class='avatar'><br>
|
<img id='user_avatar_img' src='/{{ alias }}/uploads/avatar/{{message.user.avatar}}' class='avatar'><br>
|
||||||
<i class='delmessage fa fa-trash fa-fw' data-id='{{message.id}}' style='cursor: pointer;'></i>
|
{% if fgmanager or message.user == app.user %}
|
||||||
|
<i class='delmessage fa fa-trash fa-fw' data-id='{{message.id}}' style='cursor: pointer;'></i>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class='msgdiv'>
|
<div class='msgdiv'>
|
||||||
<div class='msgtitle'>
|
<div class='msgtitle'>
|
||||||
|
@ -87,11 +90,11 @@
|
||||||
session.call("websocket/rpc/update_connection_data", {"userkey": "{{userkey}}" }).then(
|
session.call("websocket/rpc/update_connection_data", {"userkey": "{{userkey}}" }).then(
|
||||||
function (result)
|
function (result)
|
||||||
{
|
{
|
||||||
console.log("RPC Valid!", result);
|
//console.log("RPC Valid!", result);
|
||||||
},
|
},
|
||||||
function (error, desc)
|
function (error, desc)
|
||||||
{
|
{
|
||||||
console.log("RPC Error", error, desc);
|
//console.log("RPC Error", error, desc);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -101,7 +104,7 @@
|
||||||
html ="<div id='message-"+payload.msg.id+"' class='message row'>";
|
html ="<div id='message-"+payload.msg.id+"' class='message row'>";
|
||||||
html+="<div class='msgavatar'>";
|
html+="<div class='msgavatar'>";
|
||||||
html+="<img id='user_avatar_img' src='/{{ alias }}/uploads/avatar/"+payload.msg.avatar+"' class='avatar'><br>";
|
html+="<img id='user_avatar_img' src='/{{ alias }}/uploads/avatar/"+payload.msg.avatar+"' class='avatar'><br>";
|
||||||
if(payload.msg.userid=={{app.user.id}}) {
|
if(payload.msg.userid=={{app.user.id}} || '{{ fgmanager }}'=='1') {
|
||||||
html+="<i class='delmessage fa fa-trash fa-fw' data-id='"+payload.msg.id+"' style='cursor: pointer;'></i>";
|
html+="<i class='delmessage fa fa-trash fa-fw' data-id='"+payload.msg.id+"' style='cursor: pointer;'></i>";
|
||||||
}
|
}
|
||||||
html+="</div>";
|
html+="</div>";
|
||||||
|
@ -111,10 +114,8 @@
|
||||||
html+="</div>";
|
html+="</div>";
|
||||||
html+="</div>";
|
html+="</div>";
|
||||||
$(".mychat").prepend(html);
|
$(".mychat").prepend(html);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log("Received message by "+payload.msg.userid+" = ",payload.msg);
|
//console.log("Received message by "+payload.msg.userid+" = ",payload.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(payload.log) {
|
if(payload.log) {
|
||||||
|
@ -136,14 +137,18 @@
|
||||||
event={type: "add", message: data};
|
event={type: "add", message: data};
|
||||||
session.publish("websocket/channel/{{groupid}}", event);
|
session.publish("websocket/channel/{{groupid}}", event);
|
||||||
CKEDITOR.instances["chat_message"].setData('');
|
CKEDITOR.instances["chat_message"].setData('');
|
||||||
|
|
||||||
|
event={type: "add", group:{{groupid}}};
|
||||||
|
parent.parent.counter(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', '.delmessage', function(){
|
$(document).on('click', '.delmessage', function(){
|
||||||
console.log("suppression");
|
|
||||||
id=$(this).data("id");
|
id=$(this).data("id");
|
||||||
event={type: "del", id: id};
|
event={type: "del", id: id};
|
||||||
session.publish("websocket/channel/{{groupid}}", event);
|
session.publish("websocket/channel/{{groupid}}", event);
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cadoles\WebsocketBundle\Topic;
|
||||||
|
|
||||||
|
use Gos\Bundle\WebSocketBundle\Topic\TopicInterface;
|
||||||
|
use Ratchet\ConnectionInterface;
|
||||||
|
use Ratchet\Wamp\Topic;
|
||||||
|
use Gos\Bundle\WebSocketBundle\Router\WampRequest;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface;
|
||||||
|
|
||||||
|
use Cadoles\WebsocketBundle\Entity\Message;
|
||||||
|
|
||||||
|
class WebsocketCounter implements TopicInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $em;
|
||||||
|
protected $container;
|
||||||
|
protected $clientManipulator;
|
||||||
|
|
||||||
|
public function __construct(ClientManipulatorInterface $clientManipulator, EntityManager $em, ContainerInterface $container) {
|
||||||
|
$this->clientManipulator = $clientManipulator;
|
||||||
|
$this->em = $em;
|
||||||
|
$this->container = $container;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will receive any Subscription requests for this topic.
|
||||||
|
*
|
||||||
|
* @param ConnectionInterface $connection
|
||||||
|
* @param Topic $topic
|
||||||
|
* @param WampRequest $request
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
|
||||||
|
{
|
||||||
|
$userid=$connection->userid;
|
||||||
|
//this will broadcast the message to ALL subscribers of this topic.
|
||||||
|
//$topic->broadcast(['log' => $connection->resourceId." has joined ".$topic->getId()." ".$userid]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will receive any UnSubscription requests for this topic.
|
||||||
|
*
|
||||||
|
* @param ConnectionInterface $connection
|
||||||
|
* @param Topic $topic
|
||||||
|
* @param WampRequest $request
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onUnSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
|
||||||
|
{
|
||||||
|
//this will broadcast the message to ALL subscribers of this topic.
|
||||||
|
//$topic->broadcast(['msg' => $connection->resourceId . " has left " . $topic->getId()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will receive any Publish requests for this topic.
|
||||||
|
*
|
||||||
|
* @param ConnectionInterface $connection
|
||||||
|
* @param Topic $topic
|
||||||
|
* @param WampRequest $request
|
||||||
|
* @param $event
|
||||||
|
* @param array $exclude
|
||||||
|
* @param array $eligible
|
||||||
|
* @return mixed|void
|
||||||
|
*/
|
||||||
|
public function onPublish(ConnectionInterface $connection, Topic $topic, WampRequest $request, $event, array $exclude, array $eligible)
|
||||||
|
{
|
||||||
|
$userid=$connection->userid;
|
||||||
|
|
||||||
|
$user=$this->em->getRepository("CadolesCoreBundle:User")->find($userid);
|
||||||
|
if(!$user)
|
||||||
|
return;
|
||||||
|
|
||||||
|
$group=$this->em->getRepository("CadolesCoreBundle:Group")->find($event["group"]);
|
||||||
|
if(!$group)
|
||||||
|
return;
|
||||||
|
|
||||||
|
$usergroup=$this->em->getRepository("CadolesCoreBundle:UserGroup")->findOneBy(["user"=>$user,"group"=>$group]);
|
||||||
|
if(!$usergroup)
|
||||||
|
return;
|
||||||
|
|
||||||
|
$topic->broadcast([$event["type"] => 1, "group" => $event["group"] , "from" =>$userid]);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like RPC is will use to prefix the channel
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return 'websocket.counter';
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,7 +37,7 @@ class WebsocketTopic implements TopicInterface
|
||||||
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
|
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
|
||||||
{
|
{
|
||||||
//this will broadcast the message to ALL subscribers of this topic.
|
//this will broadcast the message to ALL subscribers of this topic.
|
||||||
$topic->broadcast(['log' => $connection->resourceId." has joined ".$topic->getId()]);
|
//$topic->broadcast(['log' => $connection->resourceId." has joined ".$topic->getId()]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +107,11 @@ class WebsocketTopic implements TopicInterface
|
||||||
|
|
||||||
if($event["type"]=="del") {
|
if($event["type"]=="del") {
|
||||||
$message=$this->em->getRepository("CadolesWebsocketBundle:Message")->find($event["id"]);
|
$message=$this->em->getRepository("CadolesWebsocketBundle:Message")->find($event["id"]);
|
||||||
if($message&&($usergroup->getFgmanager()||$message->getUser()==$user)) {
|
if($message&&($usergroup->getFgmanager()||$message->getUser()==$user||$user->getRole()=="ROLE_ADMIN"||$user->getRole()=="ROLE_MODO" )) {
|
||||||
$topic->broadcast(['del' => $message->getId()]);
|
$id=$message->getId();
|
||||||
|
$this->em->remove($message);
|
||||||
|
$this->em->flush();
|
||||||
|
$topic->broadcast(['del' => $id]);
|
||||||
}
|
}
|
||||||
else $topic->broadcast(['log' => "Suppression interdite"]);
|
else $topic->broadcast(['log' => "Suppression interdite"]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue