Je suis en train d'essayer de créer un système de notification en temps réel pour le site social que je suis en train de développer en utilisant Symfony2. J'ai réussi d'exécuter le système de notification mais le problème est qu'il ne marche pas correctement. L'explication est ci-dessous:

J'ai téléchargé le calendrier wdCalendar depuis ce lien : http://www.webappers.com/2010/06/08/...alendar-clone/ (Vous pouvez voir le démo sur ce lien: http://www.web-delicious.com/jquery-...dar/sample.php ) et j'ai l'intégré en Symfony2. Puis j'ai crée trois fichiers: mapage.html , moslem.php and moslem1.php. Le code de chacun d'eux est ci-dessous:

Le code de mapage.html:
Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
$(document).ready(function() {
        setTimeout( test, 1000);   
});
    function test() {
        var start = new Date().getMilliseconds();
        $.ajax({
            url: 'moslem.php',
            type: 'POST',
            success: function(data) {
                var max;
                max = data;
                function test1() {
                    $.ajax({
                        url: 'moslem1.php',
                        type: 'POST',
                        dataType: 'JSON',
                        success: function(data1) {
                            if(data1.id>max)
                            {
                                document.write("an event was added with the id: "+data1.id+" and with the subject: "+data1.subject+"<br>");
                            }
                        }
                    });
                }
                var end = new Date().getMilliseconds();
                var time = end - start;
                var time1 = 1000 - time;
                setTimeout( test1, time1);
    }
        });
        setTimeout( test, 1000);   
}

Le code de moslem.php :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$con=mysqli_connect("localhost","root","","test");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM jqcalendar ORDER BY id DESC LIMIT 0, 1");
$num_rows = mysqli_num_rows($result);
if($num_rows!=0){
while($row = mysqli_fetch_array($result)) {
    $max=$row['Id'];
}
echo $max;
}
mysqli_close($con);
?>
le code de moslem1.php :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
<?php
$con=mysqli_connect("localhost","root","","test");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM jqcalendar ORDER BY id DESC LIMIT 0, 1");
while($row = mysqli_fetch_array($result)) {
    $notification = array('id'=>$row['Id'],'subject'=>$row['Subject'],'location'=>$row['Location'],'description'=>$row['Description'],'starttime'=>$row['StartTime'],'endtime'=>$row['EndTime']);
}
echo json_encode($notification);
mysqli_close($con);
?>
Dans la base de données sur laquelle je travaille il y a une table appelée "jqcalendar" dont la structure est comme suit:

Id : int(11)
Subject : varchar(1000)
Location : varchar(200)
Description : varchar(255)
StartTime : datetime
EndTime : datetime
IsAllDayEvent : smallint(6)
Color : varchar(200)
RecurringRule : varchar(500)
Le champs "Id" ci-dessus est l'identifiant primaire de la table "jqcalendar" et il est auto-incrément. Concernant le principe du système de notification que je suis en train d'essayé de créer est comme suit: lorsque un événement est ajouté dans le calendrier, une insertion d'une nouvelle ligne dans la table "jqcalendar" aura lieu et elle sera détectée grâce à une requête jquery/Ajax (sur la table "jqcalendar") qui se passe chaque seconde. Puis, le contenu de quelques champs (ici dans notre exemple, ce sont les deux champs "Id" et "Subject") va être affiché sur l’écran (en fait, le fichier mapage.html c'est celui que se charge par cet affichage là) comme étant une notification. En fait, le problème est que j'ajoute un événement avec l'identifiant ayant une valeur de 10 ou bien les multiples de 10 (par exemple: 100, 1000, 10000,...etc) la notification ne sera pas affichée. Au fait, j'ai ajouté 20 événements dans le calendrier et voilà c'est ce que j'ai obtenu comme affichage sur l'écran:

an event was added with the id: 1 and with the subject: a
an event was added with the id: 2 and with the subject: z
an event was added with the id: 3 and with the subject: e
an event was added with the id: 4 and with the subject: r
an event was added with the id: 5 and with the subject: t
an event was added with the id: 6 and with the subject: y
an event was added with the id: 7 and with the subject: u
an event was added with the id: 8 and with the subject: i
an event was added with the id: 9 and with the subject: o
an event was added with the id: 11 and with the subject: m
an event was added with the id: 12 and with the subject: q
an event was added with the id: 13 and with the subject: s
an event was added with the id: 14 and with the subject: d
an event was added with the id: 15 and with the subject: f
an event was added with the id: 16 and with the subject: g
an event was added with the id: 17 and with the subject: h
an event was added with the id: 18 and with the subject: j
an event was added with the id: 19 and with the subject: k
an event was added with the id: 20 and with the subject: l
Comme vous pouvez le remarquer bien ci-dessus, il y a une notification manquante qui est celle de l'événement ayant l'identifiant est égal à 10. Veuillez juste se concentrer sur ces deux lignes:

an event was added with the id: 9 and with the subject: o
an event was added with the id: 11 and with the subject: m
Alors, ma question est comment je peux résoudre ce problème là??..Vraiment moi je m'étonne pourquoi on m'affiche pas les notifications relatives aux événements avec des identifiants ayant comme des valeurs 10 ou bien multiples de 10 exactement?? ( comme j'ai dit soit 100 ou bien 1000 ou bien 10000 ....etc). j'ai vraiment essayé depuis un longtemps mais malheureusement jusqu'au maintenant j'ai pas arrivé à trouvé la solution..Est ce qu'il y a quelqu'un qui peut m'aider???

Merci d'avance.