Commit b3c5912c authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Mise en paramètres de la configuration du socket + Ajout du hash stack

parent a9dd6644
Loading
Loading
Loading
Loading
+23 −0
Changes for module/Oscar/src/Oscar/Entity/Notification.php: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -52,6 +52,11 @@ class Notification
     */
    private $message;

    /**
     * @ORM\Column(type="string")
     */
    private $hash;

    /**
     * @ORM\Column(type="string")
     */
@@ -104,6 +109,24 @@ class Notification
        return $this->id;
    }

    /**
     * @return mixed
     */
    public function getHash()
    {
        return $this->hash;
    }

    /**
     * @param mixed $hash
     */
    public function setHash($hash)
    {
        $this->hash = $hash;

        return $this;
    }

    /**
     * @return mixed
     */
+19 −5
Changes for module/Oscar/src/Oscar/Service/NotificationService.php: 19 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -59,13 +59,17 @@ class NotificationService implements ServiceLocatorAwareInterface, EntityManager
            foreach ($persons as $person ){
                $ids[] = $person->getId();
            }
            $this->notification(sprintf("Déclaration en attente de validation dans l'activité %s.", $activity->log()), $ids, 'Activity:timesheetwait:'. $activity->getId());
            $this->notification(sprintf("Déclaration en attente de validation dans l'activité %s.", $activity->log()),
                $ids,
                'Activity',
                $activity->getId());
        }
    }

    public function notification( $message, $personsId, $key=null ){
    public function notification( $message, $personsId, $context='Application', $contextId=-1, $key=null)
    {
        if ($key === null) {
            $key = uniqid();
            $key = $context.':'.$contextId.'-'.uniqid();
        }
        $push = [];
        foreach ($personsId as $personid) {
@@ -73,7 +77,9 @@ class NotificationService implements ServiceLocatorAwareInterface, EntityManager
            $date = new \DateTime();
            $notification = new Notification();
            $notification->setContext('Application')
                ->setContextId(-1)
                ->setHash($hash)
                ->setContext($context)
                ->setContextId($contextId)
                ->setDatas([])
                ->setMessage($message)
                ->setDateEffective($date)
@@ -86,11 +92,19 @@ class NotificationService implements ServiceLocatorAwareInterface, EntityManager
            $push[] = $notification->getId();
        }

        // Push vers le socket si besoin
        $configSocket = $this->getServiceLocator()->get('Config')['oscar']['socket'];
        if ($configSocket)
        {
            // todo Faire un truc plus propre pour générer l'URL
            $url = "http://". $_SERVER['SERVER_NAME'].":". $configSocket['port'].$configSocket['push_path'];
            $this->getServiceLocator()->get('Logger')->info("PUSH " . $url);
            $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, "http://localhost:3000/push");
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, "ids=" . implode(',', $push));
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_exec($curl);
        }
    }
}
 No newline at end of file
+8 −0
Changes for module/Oscar/src/Oscar/View/Helpers/Grant.php: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -47,6 +47,14 @@ class Grant extends AbstractHtmlElement implements ServiceLocatorAwareInterface
        return $this->getOscarUserContext()->getRolesOrganisationLeader();
    }

    public function getSocketUrl(){
        $config = $this->getServiceLocator()->getServiceLocator()->get('Config');
        return $_SERVER['SERVER_NAME'].':'.$config['oscar']['socket']['port'];
    }

    public function hasSocket(){
        return (bool) $this->getServiceLocator()->getServiceLocator()->get('Config')['oscar']['socket'];
    }

    public function privileges()
    {
+4 −19
Changes for module/Oscar/view/layout/layout.phtml: 4 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -320,29 +320,13 @@ $this->headScript();
		});
	})();
	</script>

        <?php if( $this->grant()->dbUser() ): ?>
        <div id="notifications">

        </div>
        <script>
            var socket;
            /*
            require(['vue', 'moment', 'jquery'], function(Vue, moment, $){

                var notifications = [], socket, v;



                v = new Vue({

                    el: "#notifications-area",


                });

                v.loadNotifications();
            });
                */
            require(['notifications'], (notifications) => {
                var n = new notifications.default({
                    el: '#notifications-area',
@@ -351,9 +335,9 @@ $this->headScript();
                    },
                });
                n.fetch();

                <?php if( $this->grant()->hasSocket() ): ?>
                require(['io'], (io) => {
                    socket = io('127.0.0.1:3000', {
                    socket = io('<?= $this->grant()->getSocketUrl() ?>', {
                        query: {
                            token: '<?= $this->grant()->dbUser()->getSecret() ?>'
                        }
@@ -370,6 +354,7 @@ $this->headScript();
                        console.log('disconnect');
                    });
                });
                <?php endif; ?>
            });
        </script>
        <?php endif; ?>
+1 −0
Changes for socket/server.js: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ app.get('/', function(req, res){

app.post(config.socket.push_path, function(req, res){
    var ids = req.body.ids.split(',');
    console.log('PUSH with', ids);
    var client = new pg.Client({
        user: config.bdd.user,
        host: config.bdd.host,