diviner.result.class.php 5.84 KB
Newer Older
maryam's avatar
done  
maryam committed
1
2
3
4
5
6
7
<?php

class diviner_result
{
	private $mode = '';
	private $user = '';
	private $devin = '';
David's avatar
David committed
8
9
10
11
	private $oracle = '';
	private $userlvl = '';
	private $lang = '';
	private $devinName ='';
maryam's avatar
done  
maryam committed
12
13
14
	
	private $previousSGDev = 0;
	private $previousSDev = 0;
David's avatar
David committed
15
16
	private $previousSGOracle = 0;
	private $previousSOracle = 0;
maryam's avatar
done  
maryam committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
	private $pointsDev = 10;
	
	private $reussie = 'oui';

	public function set_mode($mode)
	{
		$this->mode = $mode;
	}

	public function process()
	{
		if ( $this->init() )
        {
            $this->score();;
            return $this->display();
        }
        return false;
	}

	private function init()
	
	{	
David's avatar
David committed
39
40
		include('./sys/load_iso.php');
		$db = db::getInstance();
maryam's avatar
done  
maryam committed
41
42
43
		//Récupération des informaions de base: userid
		$this->user = user::getInstance();
		$this->devin = $this->user->id;
David's avatar
David committed
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
71
72
73
74
		$this->devinName = $this->user->username;
		$this->lang = $_SESSION["langDevin"];

		$sql = 'SELECT * FROM user_niveau WHERE userid=' . $this->devin;
		$result = $db->query($sql);
		$res = mysqli_fetch_assoc($result);
		$spoken_lang = explode(';',$res['spoken_lang']);
		$i=0;

		while ($i<count($spoken_lang)) {
			if(strcmp($iso[$this->lang],$spoken_lang[$i]) == 0){
				break;
			}
			$i++;
		}
		if($i!=count($spoken_lang)){
			$lang_lvl = explode(';',$res['niveau'])[$i];
		
			$sql = 'SELECT * FROM coeff_niveau_langue WHERE niveau_langue="' . $lang_lvl . '"';
			$result = $db->query($sql);
			$this->lang_lvl_pts = mysqli_fetch_assoc($result)['coeff'];
		}
		else{
			$this->lang_lvl_pts = 1; //par défaut
		}

		$this->userlvl = userlvl::getInstance();
		$this->points= $this->userlvl->get_points();
		$this->time = $this->userlvl->get_time();


maryam's avatar
done  
maryam committed
75
76
77
78
79
		return true;
	}

	private function score()
	{
David's avatar
David committed
80
81
82
83
		if(!isset($_SESSION["motDeviner"]))
		{
			include('./sys/load_iso.php');
			require_once('./controllers/update_score_coeff.php');
maryam's avatar
done  
maryam committed
84
85
86
			//connexion à la BD
			$db = db::getInstance();
			
David's avatar
David committed
87
88
			updateScoreDevinSucces($this->devin,$iso[$_SESSION["langDevin"]],$this->points);
//~ 			exit;
maryam's avatar
done  
maryam committed
89
			
David's avatar
David committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//~ 			//récupération du score précédent;
//~ 			$sql = 'SELECT scoreGlobal,scoreDevin,first_game_time FROM score WHERE userid="'.$this->devin.'" AND langue="'. $iso[$_SESSION["langDevin"]] .'"';
//~ 			$result=$db->query($sql);
//~ 			
//~ 				$res= mysqli_fetch_assoc($result);
//~ 				$this->previousSGDev= $res['scoreGlobal'];
//~ 				$this->previousSDev= $res['scoreDevin'];
//~ 			//maj des variables de scores

 				$pointsCoef = $this->points*$this->lang_lvl_pts;
 				$_SESSION["pointsCoef"] = $pointsCoef;
//~ 				$this->previousSGDev= $this->previousSGDev+($this->points*$this->lang_lvl_pts);
//~ 				$this->previousSDev= $this->previousSDev+($this->points*$this->lang_lvl_pts);
//~ 				
//~ 				//echo $this->previousSDev;

//~ 				//maj des scores dans la BD
//~ 				if($res["first_game_time"]==""){
//~ 				$sql = 'UPDATE score 
//~ 						SET  scoreGlobal='.$db->escape((string) $this->previousSGDev) . ', ' .
//~ 						'scoreDevin='.$db->escape((string) $this->previousSDev) . ',' .
//~ 						'first_game_time="'.date('Y-m-d H:i:s').'"
//~ 						WHERE userid='.$this->devin.' AND langue= "'.$iso[$_SESSION["langDevin"]].'"';	
//~ 				}
//~ 				else{
//~ 					$sql = 'UPDATE score 
//~ 						SET  scoreGlobal='.$db->escape((string) $this->previousSGDev) . ', ' .
//~ 						'scoreDevin='.$db->escape((string) $this->previousSDev) . '
//~ 						WHERE userid='.$this->devin.' AND langue= "'.$iso[$_SESSION["langDevin"]].'"';	
//~ 				}

//~ 			$db->query($sql);
maryam's avatar
done  
maryam committed
122
123
124
125
126
127
128
	
		// Requête de mise à jour de la table partie
			$db = db::getInstance();
			$sql = 'UPDATE parties 
					SET  reussie='.$db->escape((string) $this->reussie).'
					WHERE idDevin='.$this->devin.' ORDER BY tpsDevin DESC LIMIT 1 ';		
			$db->query($sql);
David's avatar
David committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176


			//Récupération de enregistrementID
			$sql = 'SELECT enregistrementID FROM parties WHERE idDevin="'.$this->devin.'" ORDER BY tpsDevin DESC LIMIT 1 ';
	        $res1=$db->query($sql); 
	        $this->res2= mysqli_fetch_assoc($res1);
	        
	       // récupération de l'id de l'oracle et de la carte grâce à enregistrementID
			$sql = 'SELECT idOracle,carteID,OracleLang
	                    FROM enregistrement WHERE enregistrementID='.$this->res2['enregistrementID'].'';	
	        $res1=$db->query($sql); 
	        $res3= mysqli_fetch_assoc($res1);

	        
		updateScoreOracleDevinSucces($res3["idOracle"],$iso[$res3["OracleLang"]],$this->res2['enregistrementID']);

//~ 	        //récupération du score précédent;
//~ 			$sql = 'SELECT scoreGlobal,scoreOracle FROM score WHERE userid="'.$res3["idOracle"].'" AND langue="'. $iso[$res3["OracleLang"]] .'"';
//~ 			$result=$db->query($sql);
//~ 			$res= mysqli_fetch_assoc($result);
//~ 				$this->previousSGOracle= $res['scoreGlobal'];
//~ 				$this->previousSOracle= $res['scoreOracle'];

//~ 				$this->previousSGOracle= $this->previousSGOracle+$this->points;
//~ 				$this->previousSOracle= $this->previousSOracle+$this->points;
//~ 			
//~ 				//maj des variables de scores
//~ 				$sql = 'UPDATE score 
//~ 						SET  scoreGlobal='.$db->escape((string) $this->previousSGOracle) . ', ' .
//~ 						'scoreOracle='.$db->escape((string) $this->previousSOracle) . '
//~ 						WHERE userid='.$res3["idOracle"].' AND langue= "'.$iso[$res3["OracleLang"]].'"';	
//~ 				$db->query($sql);
				$this->oracle=$res3["idOracle"];
			
			// récupération du contenu de la carte avec carteID
	    	$sql = 'SELECT carteID,niveau,mot,tabou1,tabou2,tabou3,tabou4,tabou5 FROM carte WHERE carteID="'.$res3['carteID'].'"';
	        $res=$db->query($sql); 
	        $this->res= mysqli_fetch_assoc($res);

	        $_SESSION["motDeviner"] = true;//pour éviter de s'ajouter des points à l'infini avec des refresh

			return true;

		}
		else{
			header('Location: index.php?page.home.html');      
			return false;
		}
maryam's avatar
done  
maryam committed
177
178
179
180
	}

	private function display()
	{
David's avatar
David committed
181
		$_SESSION["notif"]["notification_done"]["Devin"] = 'points';	 		
maryam's avatar
done  
maryam committed
182
183
184
185
186
187
		include('./views/diviner.result.html');
        return true;
	}
}

?>