diff --git a/src/ninegate-1.0/app/AppKernel.php b/src/ninegate-1.0/app/AppKernel.php index 600c5c6e..75594149 100644 --- a/src/ninegate-1.0/app/AppKernel.php +++ b/src/ninegate-1.0/app/AppKernel.php @@ -38,7 +38,7 @@ class AppKernel extends Kernel new Cadoles\CoreBundle\CadolesCoreBundle(), new Cadoles\CronBundle\CadolesCronBundle(), new Cadoles\PortalBundle\CadolesPortalBundle(), - new Cadoles\PortalBundle\CadolesWebsocketBundle(), + new Cadoles\WebsocketBundle\CadolesWebsocketBundle(), ]; diff --git a/src/ninegate-1.0/app/config/config.yml b/src/ninegate-1.0/app/config/config.yml index 45cddc71..f3e7b093 100644 --- a/src/ninegate-1.0/app/config/config.yml +++ b/src/ninegate-1.0/app/config/config.yml @@ -152,10 +152,17 @@ ivory_ck_editor: language: fr toolbar: "my_toolbar_2" uiColor: "#ffffff" + removePlugins: 'elementspath' + small_config: + language: fr + toolbar: "my_toolbar_3" + uiColor: "#ffffff" + removePlugins: 'elementspath' toolbars: configs: my_toolbar_1: [ "@document1", "-", "@clipboard1", "-", "@basicstyles1", "-", "@paragraph1", "/", "@links1", "-", "@insert1", "-", "@styles1", "-" , "@colors1", "-" , "@tools1" ] my_toolbar_2: [ "@basicstyles1", "-", "@paragraph2", "-", "@insert2", "-", "@styles1"] + my_toolbar_3: [ "@basicstyles1", "-", "@paragraph3", "-", "@insert3"] items: document1: [ 'Source','-','NewPage','DocProps','Preview','Print','-','Templates' ] @@ -163,9 +170,11 @@ ivory_ck_editor: basicstyles1: [ 'Bold','Italic','Underline','RemoveFormat' ] paragraph1: [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] paragraph2: [ 'JustifyLeft','JustifyCenter','JustifyRight','NumberedList','BulletedList' ] + paragraph3: [ 'NumberedList','BulletedList' ] links1: [ 'Link','Unlink','Anchor' ] insert1: [ 'Image','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] insert2: [ 'Image','Table','Smiley','Link','Unlink' ] + insert3: [ 'Smiley','Link','Unlink' ] styles1: [ 'Styles','Format','Font','FontSize' ] colors1: [ 'TextColor','BGColor' ] tools1: [ 'Maximize', 'ShowBlocks','-','About' ] \ No newline at end of file diff --git a/src/ninegate-1.0/app/config/security.yml b/src/ninegate-1.0/app/config/security.yml index 538b4151..35fc8633 100644 --- a/src/ninegate-1.0/app/config/security.yml +++ b/src/ninegate-1.0/app/config/security.yml @@ -41,6 +41,7 @@ security: check_path: /saml/acs access_control: + - { path: ^/websocket, roles: [ROLE_ADMIN, ROLE_MODO, ROLE_USER] } - { path: ^/user, roles: [ROLE_ADMIN, ROLE_MODO, ROLE_USER] } - { path: ^/config, roles: [ROLE_ADMIN, ROLE_MODO] } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/UserGroup.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/UserGroup.php index f9b0ff1e..c23bcc05 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/UserGroup.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/UserGroup.php @@ -40,7 +40,11 @@ class UserGroup */ private $fgmanager = false; - + /** + * @ORM\Column(type="string", length=60, nullable=true) + */ + private $keyvalue; + /** * Get id * @@ -122,4 +126,28 @@ class UserGroup { return $this->fgmanager; } + + /** + * Set keyvalue + * + * @param string $keyvalue + * + * @return UserGroup + */ + public function setKeyvalue($keyvalue) + { + $this->keyvalue = $keyvalue; + + return $this; + } + + /** + * Get keyvalue + * + * @return string + */ + public function getKeyvalue() + { + return $this->keyvalue; + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Command/InitDataCommand.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Command/InitDataCommand.php index bca31031..088ce2ba 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Command/InitDataCommand.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Command/InitDataCommand.php @@ -668,7 +668,24 @@ class InitDataCommand extends ContainerAwareCommand $em->persist($entityWidget); - + // Widget Chat + $entityWidget = $em->getRepository('CadolesPortalBundle:Widget')->find(-1840); + if(!$entityWidget) $entityWidget = new Widget(); + $entityicon = $em->getRepository('CadolesPortalBundle:Icon')->findoneby(["label"=>"uploads/icon/icon_chat.png"]); + $entityWidget->setId(-1840); + $entityWidget->setRoworder(2); + $entityWidget->setIcon($entityicon); + $entityWidget->setName('Chat'); + $entityWidget->setDescription("Conversation instantanée"); + $entityWidget->setRouteview("cadoles_portal_config_panelwidget_view_chat"); + $entityWidget->setHeight("1000"); + $entityWidget->setAutoajust(false); + $entityWidget->setBorder(true); + $entityWidget->setOpened(true); + $entityWidget->setAccess(["config","user","group"]); + $parameter = json_decode('{"fields": []}'); + $entityWidget->setParameter($parameter); + $em->persist($entityWidget); diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php index 917e3de3..51b7cfbe 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php @@ -1841,4 +1841,41 @@ class PagewidgetController extends Controller ]); } + public function viewchatAction(Request $request,$id,$access="config") { + $usage=$request->query->get('usage'); + $group=$request->query->get('group'); + + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository($this->labelentity)->find($id); + if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + + // Permissions + if($access=="config") { + $canupdate = true; + } + else { + // On s'assure que l'utilisateur à la permission de voir + $page=$entity->getPage(); + $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); + if(!$cansee) throw $this->createNotFoundException('Permission denied'); + } + + if($usage!="group") { + $group=$em->getRepository("CadolesCoreBundle:Group")->findOneBy(["fgall"=>true])->getId(); + + } + + + // Render + return $this->render($this->labelentity.':viewchat.html.twig', [ + 'entity' => $entity, + 'canadd' => $canupdate, + 'canupdate' => $canupdate, + 'onheader' => false, + 'tool' => "cadoles_websocket_chat", + 'access' => $access, + 'usage' => $usage, + 'group' => $group + ]); + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml index 9598eccb..3320e0fc 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml @@ -759,7 +759,9 @@ cadoles_portal_config_panelwidget_view_info: path: /config/pagewidget/view/info/{id} defaults: { _controller: CadolesPortalBundle:Pagewidget:viewinfo, access: config } - +cadoles_portal_config_panelwidget_view_chat: + path: /config/pagewidget/view/chat/{id} + defaults: { _controller: CadolesPortalBundle:Pagewidget:viewchat, access: config } #-- Access user cadoles_portal_user_pagewidget_widget_sumbit: @@ -857,3 +859,7 @@ cadoles_portal_user_panelwidget_view_appexternal: cadoles_portal_user_panelwidget_view_info: path: /pagewidget/view/info/{id} defaults: { _controller: CadolesPortalBundle:Pagewidget:viewinfo, access: user } + +cadoles_portal_user_panelwidget_view_chat: + path: /pagewidget/view/chat/{id} + defaults: { _controller: CadolesPortalBundle:Pagewidget:viewchat, access: user } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/constants.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/constants.twig index 3722056b..df869625 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/constants.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/constants.twig @@ -237,11 +237,24 @@ {% set colorbodyfont = color['fontcolorhover'] %} {% endif %} - + {% if not entity.border %} + {% set colorbodyback = color['colorbody'] %} + {% endif %} + + {% if colorbodyfont == colorbodyback %} + {% if colorbodyfont == color['main'] %} + {% set colorbodyfont=color['fontcolorhover'] %} + {% else %} + {% set colorbodyfont=color['main'] %} + {% endif %} + {% endif %} {% set stylewidgetbodyframe = "" %} {% set stylewidgetbodyframe = stylewidgetbodyframe ~ "background-color: #" ~ colorbodyback ~ "; " %} {% set stylewidgetbodyframe = stylewidgetbodyframe ~ "color: #" ~ colorbodyfont ~ "; " %} + {% if entity.border %} + {% set stylewidgetbodyframe = stylewidgetbodyframe ~ "padding: 0px 0px 0px 10px; " %} + {% endif %} {% if not entity.autoajust %} {% set stylewidgetbodyframe = stylewidgetbodyframe ~ "height: " ~ (entity.height-50-2) ~ "px;" %} {% endif %} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewchat.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewchat.html.twig new file mode 100644 index 00000000..3f93f6fa --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewchat.html.twig @@ -0,0 +1,58 @@ +{% set theme = app.session.get('theme') %} +{% if theme is not empty %} + {{ include('@Theme/'~theme~'/function.html.twig') }} +{% endif %} + +{% import "@CadolesPortal/Pagewidget/constants.twig" as constants %} + +{% set stylewidget = constants.mystylewidget(entity) %} +{% set stylewidgetmenu = constants.mystylewidgetmenu(entity) %} +{% set stylewidgetheader = constants.mystylewidgetheader(entity) %} +{% set stylewidgetbody = constants.mystylewidgetbody(entity) %} +{% set stylewidgetbodyframe = constants.mystylewidgetbodyframe(entity) %} +{% set stylewidgetbodyimage = constants.mystylewidgetbodyimage(entity) %} + +{% set color = app.session.get('color') %} +{% set colorbodyback = entity.colorbodyback %} +{% if colorbodyback is null %} + {% set colorbodyback = color['main'] %} +{% endif %} + +{% set colorbodyfont = entity.colorbodyfont %} +{% if colorbodyfont is null %} + {% set colorbodyfont = color['fontcolorhover'] %} +{% endif %} + +
+ {% if canupdate %} +
+ + +
+ {% endif %} + + + {% if onheader %} +
+ +
+ {% else %} +
+ {% if entity.icon %} + + {% else %} + + {% endif %} + {{ entity.name }} +
+ +
+ +
+ {% endif %} +
+ + + diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Controller/ChatController.php b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Controller/ChatController.php index d2b0dcaa..b3d98772 100644 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Controller/ChatController.php +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Controller/ChatController.php @@ -10,6 +10,8 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Form\FormError; use Ramsey\Uuid\Uuid; +use Cadoles\WebsocketBundle\Form\ChatType; + class ChatController extends Controller { public function clientAction($id, Request $request) @@ -19,21 +21,46 @@ class ChatController extends Controller die(); } else { - // Génération d'une clé temporaire d'accès au chat - $key = Uuid::uuid4(); - $user->setKeyvalue($key); + $framed=$request->query->get('framed'); + if($framed) { + $border=$request->query->get('border'); + if($border) { + $colorbodyback=$request->query->get('colorbodyfont'); + $colorbodyfont=$request->query->get('colorbodyback'); + } + else { + $colorbodyback=$request->query->get('colorbodyback'); + $colorbodyfont=$request->query->get('colorbodyfont'); + } + } + else { + $border=false; + $colorbodyback=$this->get('session')->get('color')["main"]; + $colorbodyfont=$this->get('session')->get('color')["fontcolorhover"]; + } - // Sauvegarde $em = $this->getDoctrine()->getManager(); - $em->persist($user); - $em->flush(); // On récupère les 100 derniers message du groupe - $group=$user=$em->getRepository("CadolesCoreBundle:Group")->find($id); + $group=$em->getRepository("CadolesCoreBundle:Group")->find($id); if(!$group) die(); - $messages=$em->getRepository("CadolesWebsocketBundle:Message")->findBy(["group"=>$group],["submitdate"=>"DESC"]); - dump($messages); + // Génération d'une clé temporaire d'accès au chat + $key = Uuid::uuid4(); + $usergroup=$em->getRepository("CadolesCoreBundle:UserGroup")->findOneBy(["group"=>$group,"user"=>$user]); + if(!$usergroup) die("noingroup".$user->getUserName()); + $usergroup->setKeyvalue($key); + + // Sauvegarde + $em->persist($usergroup); + $em->flush(); + + + // Récupération des message du groupe + $messages=$em->getRepository("CadolesWebsocketBundle:Message")->findBy(["group"=>$group],["submitdate"=>"DESC"],100); + + // Création du formulaire + $form = $this->createForm(ChatType::class,null,[]); // Affichage du chat return $this->render('CadolesWebsocketBundle:Chat:client.html.twig',[ @@ -42,7 +69,12 @@ class ChatController extends Controller 'usesidebar' => false, 'userkey' => $key, 'groupid' => $id, - 'messages' => $messages + 'messages' => $messages, + 'framed' => $framed, + 'border' => $border, + 'colorbodyback' => $colorbodyback, + 'colorbodyfont' => $colorbodyfont, + 'form' => $form->createView() ]); } } diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Form/ChatType.php b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Form/ChatType.php new file mode 100644 index 00000000..b8910e88 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Form/ChatType.php @@ -0,0 +1,41 @@ +add("message",CKEditorType::class,[ + 'config_name' => 'small_config', + 'label' => "Message", + 'mapped'=> false, + 'required' => false, + 'config' => ["height" => "100px",'filebrowserUploadRoute' => 'cadoles_portal_user_pagewidget_upload'] + ]); + + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([]); + } +} diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/views/Chat/client.html.twig b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/views/Chat/client.html.twig index 4b2dc597..9e87eede 100644 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/views/Chat/client.html.twig +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/views/Chat/client.html.twig @@ -1,11 +1,27 @@ {% extends '@CadolesCore/base.html.twig' %} {% block localstyle %} + {% if framed %} + {% if border %} + #page-wrapper { + padding: 5px 25px 10px 15px; + background: transparent; + } + {% else %} + #page-wrapper { + padding: 5px 25px 0px 15px; + background: transparent; + } + {% endif %} + {% else %} + #page-wrapper { padding-top:20px; padding-bottom:30px; } + {% endif %} + .message { padding:10px; margin-top: 5px; - background-color: #{{ color['main'] }}; - color: #{{ color['fontcolorhover'] }}; + background-color: #{{ colorbodyback }}; + color: #{{ colorbodyfont }}; } .msgavatar { float:left; @@ -19,12 +35,31 @@ line-height: 12px; margin-bottom: 10px; } + #cke_1_bottom{ display:none } {% endblock %} {% block pagewrapper %} + {{ form_start(form) }} +
+ {{ form_widget(form.message) }} + Envoyer +
+ + {{ form_end(form) }} +
- - + {% for message in messages %} +
+
+
+
+ {{message.user.lastname}} {{message.user.firstname}}
+ {{message.submitdate|date('d/m/Y H:i')}} +
+
{{message.topic | raw}}
+
+
+ {% endfor %}
{% endblock %} @@ -60,21 +95,34 @@ //the callback function in "subscribe" is called everytime an event is published in that channel. session.subscribe("websocket/channel/{{groupid}}", function (uri, payload) { - html ="
"; - html+="
"; - html+="
" - html+="
"+payload.msg.lastname+"
"+new Date(payload.msg.submitdate.date).toLocaleDateString("fr-FR", dateoptions)+"
"; - html+="
"+payload.msg.message+"
"; - html+="
"; - html+="
"; - $(".mychat").append(html); + if(payload.msg) { + html ="
"; + html+="
"; + html+="
" + html+="
"+payload.msg.lastname+"
"+new Date(payload.msg.submitdate.date).toLocaleDateString("fr-FR", dateoptions)+"
"; + html+="
"+payload.msg.message+"
"; + html+="
"; + html+="
"; + $(".mychat").prepend(html); - console.log("Received message", payload.msg); + console.log("Received message", payload.msg); + } + + if(payload.log) { + console.log("Received message", payload.log); + } }); - session.publish("websocket/channel/{{groupid}}", "This is a message!"); + $( "#sendbtn" ).click(function() { + var data = CKEDITOR.instances["chat_message"].getData(); + session.publish("websocket/channel/{{groupid}}", data); + }); + + /* + session.publish("websocket/channel/{{groupid}}", "This is a message!"); session.publish("websocket/channel/{{groupid}}", "This is a message!"); + */ }) {% endif %} }); diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Topic/WebsocketTopic.php b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Topic/WebsocketTopic.php index e175b688..2cdcbbc0 100644 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Topic/WebsocketTopic.php +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Topic/WebsocketTopic.php @@ -35,18 +35,10 @@ class WebsocketTopic implements TopicInterface * @return void */ public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request) - { - /* - $userkey=$request->getAttributes()->get('user'); - $groupid=$request->getAttributes()->get('group'); - - $user=$this->em->getRepository("CadolesCoreBundle:User")->findOneBy(['keyvalue'=> $userkey]); - if(!$user) $topic->broadcast(['msg' => 'user NOT FIND']); - else $topic->broadcast(['msg' => $user->getUsername()]); - + { //this will broadcast the message to ALL subscribers of this topic. - $topic->broadcast(['msg' => $connection->resourceId . " group = $groupid && user = $userkey has joined " . $topic->getId()]); - */ + $topic->broadcast(['log' => $connection->resourceId." has joined ".$topic->getId()]); + } /** @@ -82,15 +74,18 @@ class WebsocketTopic implements TopicInterface $group=$this->em->getRepository("CadolesCoreBundle:Group")->find($groupid); if(!$group) { - $topic->broadcast(['msg' => 'group NOT FIND']); + $topic->broadcast(['log' => 'group NOT FIND']); } - $user=$this->em->getRepository("CadolesCoreBundle:User")->findOneBy(['keyvalue'=> $userkey]); - if(!$user) { - $topic->broadcast(['msg' => 'user NOT FIND']); + $usergroup=$this->em->getRepository("CadolesCoreBundle:UserGroup")->findOneBy(['keyvalue'=> $userkey]); + if(!$usergroup) { + $topic->broadcast(['log' => 'user NOT IN GROUP']); + } + else { + $user=$usergroup->getUser(); } - if($group&&$user) { + if($group&&$usergroup&&$user) { $message=new Message(); $message->setTopic($event); $message->setUser($user);