| Line 77... | 
            Line 77... | 
          
          
            | 77 | 
            		
  | 
            77 | 
            		
  | 
          
          
            | 78 | 
            		$resultat = $this->bdd->requeter($insertion);
  | 
            78 | 
            		$resultat = $this->bdd->requeter($insertion);
  | 
          
          
            | 79 | 
            		if ($resultat == false) {
  | 
            79 | 
            		if ($resultat == false) {
  | 
          
          
            | 80 | 
            			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
  | 
            80 | 
            			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
  | 
          
          
            | - | 
               | 
            81 | 
            		} else {
  | 
          
          
            | 81 | 
            		} else {
  | 
            82 | 
            			self::updateStats($this->bdd, $ressources[0],$parametres['protocole']);
  | 
          
          
            | 82 | 
            			RestServeur::envoyerEnteteStatutHttp(RestServeur::HTTP_CODE_CREATION_OK);
  | 
            83 | 
            			RestServeur::envoyerEnteteStatutHttp(RestServeur::HTTP_CODE_CREATION_OK);
  | 
          
          
            | 83 | 
            		}
  | 
            84 | 
            		}
  | 
          
          
            | Line 84... | 
            Line 85... | 
          
          
            | 84 | 
            	}
  | 
            85 | 
            	}
  | 
          
          
            | Line 100... | 
            Line 101... | 
          
          
            | 100 | 
            							'ce_utilisateur = '.$this->proteger($parametres['utilisateur']).' ';		
  | 
            101 | 
            							'ce_utilisateur = '.$this->proteger($parametres['utilisateur']).' ';		
  | 
          
          
            | 101 | 
            		$resultat = $this->bdd->requeter($modification);
  | 
            102 | 
            		$resultat = $this->bdd->requeter($modification);
  | 
          
          
            | 102 | 
            		if ($resultat == false) {
  | 
            103 | 
            		if ($resultat == false) {
  | 
          
          
            | 103 | 
            			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
  | 
            104 | 
            			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
  | 
          
          
            | 104 | 
            		} else {
  | 
            105 | 
            		} else {
  | 
          
          
            | - | 
               | 
            106 | 
            			self::updateStats($this->bdd, $ressources[0],$parametres['protocole']);
  | 
          
          
            | 105 | 
            			RestServeur::envoyerEnteteStatutHttp(RestServeur::HTTP_CODE_OK);
  | 
            107 | 
            			RestServeur::envoyerEnteteStatutHttp(RestServeur::HTTP_CODE_OK);
  | 
          
          
            | 106 | 
            		}
  | 
            108 | 
            		}
  | 
          
          
            | 107 | 
            	}
  | 
            109 | 
            	}
  | 
          
          
            | Line -... | 
            Line 110... | 
          
          
            | - | 
               | 
            110 | 
            	
  | 
          
          
            | - | 
               | 
            111 | 
            	static function updateStats($db, $id_image, $id_proto) {
  | 
          
          
            | - | 
               | 
            112 | 
            		$id_image = intval($id_image);
  | 
          
          
            | - | 
               | 
            113 | 
            		$id_proto = intval($id_proto);
  | 
          
          
            | - | 
               | 
            114 | 
            		if(!$id_image || !$id_proto) throw new Exception("Ne peut mettre à jour les statistiques de vote",
  | 
          
          
            | - | 
               | 
            115 | 
            														 RestServeur::HTTP_CODE_ERREUR);
  | 
          
          
            | - | 
               | 
            116 | 
            		/* REPLACE ... SELECT: réinitalise les champs non-défini (MySQL 5.1)
  | 
          
          
            | - | 
               | 
            117 | 
            		   REPLACE ... SET a=b, c=d: idem ou plusieurs requête
  | 
          
          
            | - | 
               | 
            118 | 
            		   Du coup il faut récupérer les données actuelles mais REPLACE ne le permet pas
  | 
          
          
            | - | 
               | 
            119 | 
            		   (http://dev.mysql.com/doc/refman/5.5/en/replace.html :
  | 
          
          
            | - | 
               | 
            120 | 
            		   You cannot refer to values from the current row and use them in the new row.)
  | 
          
          
            | - | 
               | 
            121 | 
            		   D'où INSERT ... ON DUPLICATE KEY UPDATE. Notons que VALUES() récupère la valeur
  | 
          
          
            | - | 
               | 
            122 | 
            		   *associée* au champ passé en paramètre, c'est à dire VALUES(moyenne) == divo.moyenne */
  | 
          
          
            | - | 
               | 
            123 | 
            		$db->requeter(sprintf('INSERT INTO del_image_stat (ce_image, ce_protocole, moyenne, nb_votes)'.
  | 
          
          
            | - | 
               | 
            124 | 
            							  ' SELECT ce_image, ce_protocole, AVG(valeur) AS moyenne, COUNT(valeur) AS nb_votes'.
  | 
          
          
            | - | 
               | 
            125 | 
            							  ' FROM del_image_vote divo'.
  | 
          
          
            | - | 
               | 
            126 | 
            							  ' WHERE ce_image = %d AND ce_protocole = %d GROUP BY ce_image, ce_protocole'.
  | 
          
          
            | - | 
               | 
            127 | 
            							  ' ON DUPLICATE KEY UPDATE moyenne = VALUES(moyenne), nb_votes = VALUES(nb_votes)',
  | 
          
          
            | - | 
               | 
            128 | 
            							  $id_image, $id_proto));
  | 
          
          
            | - | 
               | 
            129 | 
            		
  | 
          
          
            | - | 
               | 
            130 | 
             
  | 
          
          
            | - | 
               | 
            131 | 
            	}
  | 
          
          
            | 108 | 
            	
  | 
            132 | 
             
  | 
          
          
            | 109 | 
            	/*-------------------------------------------------------------------------------
  | 
            133 | 
            	/*-------------------------------------------------------------------------------
  | 
          
          
            | 110 | 
            	 							CONFIGURATION DU SERVICE
  | 
            134 | 
            	 							CONFIGURATION DU SERVICE
  | 
          
          
            | 111 | 
            	 --------------------------------------------------------------------------------*/
  | 
            135 | 
            	 --------------------------------------------------------------------------------*/
  | 
          
          
            | 112 | 
            	/**
  | 
            136 | 
            	/**
  |