notificationMessage.php 1.87 KB
Newer Older
David's avatar
David committed
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php

class Notification
{
	private $user = '';
	public $messNotif = array();
	private $db;
	private $time = "";

	function initNotif()
	{	
		//Récupération des informaions de base: userid
		$this->user = user::getInstance();
		//connexion à la BD
		$this->db = db::getInstance();
		
		$this->time = date('Y-m-d H:i:s');

		return true;
	}

	function readNotif()
	{
		//récupération des messages de notification;
		$sql = 'SELECT * FROM `notif` WHERE `userid`="'.$this->user->id.'" ORDER BY `time` DESC';
		$result=$this->db->query($sql);
        // comptage du nombre de résultats
        $nb_result=$result->num_rows;
        
        //pour chaque enregistrement:
        if ($nb_result > 0)
        { 		while($res = mysqli_fetch_assoc($result)){

        			if($res['emetteur'] != 0){
						$sql = "SELECT `photo` FROM `user` WHERE `userid`=".$res['emetteur'];
						$resultat=$this->db->query($sql);
						$res2 = mysqli_fetch_assoc($resultat);
						$emetteur = $res2["photo"];
					}
					else{
						$emetteur = $res["game"].".jpg";
					}

					$this->messNotif[$res['id']][$res['state']][$emetteur][$res["time"]] = $res['message'];
				}
		}
	}

	function addNotif($userid,$notification,$emetteur){
		//récupération des messages de notification;
		$sql = "INSERT INTO `notif`(`userid`, `message`, `emetteur` , `time`) VALUES ($userid,'".$notification."',$emetteur,'".$this->time."')";
		$result=$this->db->query($sql);
	}

	function addNotifGAME($userid,$notification,$role){
		//récupération des messages de notification;
		$sql = "INSERT INTO `notif`(`userid`, `message`, `emetteur` ,`game` , `time`) VALUES ($userid,'".$notification."',0,'".$role."','".$this->time."')";
		$result=$this->db->query($sql);
	}


	function notifRead($id) {
		//récupération des messages de notification;
		$sql= 'UPDATE `notif` SET `state`=1 WHERE id= $id';
		$result=$this->db->query($sql);
	}
		
}

?>