origine = $origine+0; $this->num_suggestion = $num_suggestion+0; $q = "select count(1) from suggestions_origine where origine = '".$this->origine."' and num_suggestion = '".$this->num_suggestion."' "; $r = pmb_mysql_query($q); if (pmb_mysql_result($r, 0, 0) != 0) { $this->load(); } } // charge un auteur et une de ses suggestions à partir de la base. public function load(){ $q = "select * from suggestions_origine where origine = '".$this->origine."' and num_suggestion = '".$this->num_suggestion."' "; $r = pmb_mysql_query($q); $obj = pmb_mysql_fetch_object($r); $this->type_origine = $obj->type_origine; $this->date_suggestion = $obj->date_suggestion; } // enregistre un auteur et une de ses suggestions en base. public function save(){ if (!$this->origine && !$this->num_suggestion) die("Erreur de création suggestions_origine"); $q = "select count(1) from suggestions_origine where origine = '".$this->origine."' and num_suggestion = '".$this->num_suggestion."' "; $r = pmb_mysql_query($q); if (pmb_mysql_result($r, 0, 0) != 0) { $q = "update suggestions_origine set type_origine = '".$this->type_origine."' "; $q.= "where origine = '".$this->origine."' and num_suggestion = '".$this->num_suggestion."' "; $r = pmb_mysql_query($q); } else { $q = "insert into suggestions_origine set origine = '".$this->origine."', num_suggestion = '".$this->num_suggestion."', "; $q.= "type_origine = '".$this->type_origine."', date_suggestion = now() "; $r = pmb_mysql_query($q); } } //supprime la suggestion d'un auteur de la base public static function delete($num_suggestion, $origine=0 ) { $num_suggestion += 0; $q = "delete from suggestions_origine where num_suggestion = '".$num_suggestion."' "; if($origine) $q.= "and origine = '".$origine."' "; $r = pmb_mysql_query($q); } //optimization de la table suggestions_origine public function optimize() { $opt = pmb_mysql_query('OPTIMIZE TABLE suggestions_origine'); return $opt; } //recherche les occurences d'une suggestion triées par date static public function listOccurences($num_suggestion, $limit=0){ $num_suggestion += 0; $q = "Select origine, type_origine, date_suggestion from suggestions_origine where num_suggestion = '".$num_suggestion."' order by date_suggestion asc "; if ($limit) $q.= "limit ".$limit; return $q; } //fusion des suggestions public static function fusionne($origine, $from_sug, $to_sug){ //On commence par supprimer les suggestions pour lesquelles l'origine est identique à celle de destination $q = "Delete from suggestions_origine where origine = '".$origine."' and num_suggestion = '".$from_sug."' "; $r = pmb_mysql_query($q); //On met à jour les suggestions à fusionner $q = "Update suggestions_origine set num_suggestion = '".$to_sug."' where num_suggestion = '".$from_sug."' "; $r = pmb_mysql_query($q); } } ?>