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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| <?php
// v. 20110707
// LSL (c) Tous droits réservés
require_once('langue.php');
class ArticleGroupe
{
private $id;
private $client;
private $langue;
private $titre;
private $description;
private $nombreArticles = 0;
function ArticleGroupe($id = null, $client = null, $langue = null, $titre = null, $description = null)
{
$this->id = $id;
$this->client = $client;
$this->langue = $langue;
$this->titre = $titre;
$this->description = $description;
if ($this->langue == null)
$this->langue = new Langue();
if ($this->client == null)
$this->client = new Client(null);
}
public function getId() { return $this->id; }
public function getClient() { return $this->client; }
public function getLangue() { return $this->langue; }
public function setLangue($langue) { $this->langue = $langue; }
public function getTitre() { return $this->titre; }
public function setTitre($titre) { $this->titre = $titre; }
public function getDescription() { return $this->description; }
public function setDescription($description) { $this->description = $description; }
public function getNombreArticles() { return $this->nombreArticles; }
public function setNombreArticles($nombreArticles) { $this->nombreArticles = $nombreArticles; }
public function existe() { return $this->id != null; }
public function enregistre()
{
if ($this->existe())
{
$sql = 'UPDATE '.MYSQL_PREFIXE.'article_groupe SET '.
'langue_id = '.$this->langue->getId().', '.
'article_groupe_titre = \''.addslashes($this->titre).'\', '.
'article_groupe_description = \''.addslashes($this->description).'\' '.
'WHERE article_groupe_id = '.$this->id;
return mysql_query($sql);
}
else
{
$sql = 'INSERT INTO '.MYSQL_PREFIXE.'article_groupe('.
'client_id, '.
'langue_id, '.
'article_groupe_titre, '.
'article_groupe_description'.
') VALUES ('.
$this->client->getId().', '.
$this->langue->getId().', '.
'\''.addslashes($this->titre).'\', '.
'\''.addslashes($this->description).'\''.
')';
if (mysql_query($sql))
{
$this->id = mysql_insert_id();
return true;
}
}
return false;
}
public function getArticleGroupeParId_et_Client($articleGroupeId, $client)
{
$sql = 'SELECT langue_id, article_groupe_titre, article_groupe_description, COUNT(article_id) AS total '.
'FROM '.MYSQL_PREFIXE.'article_groupe '.
'LEFT JOIN '.MYSQL_PREFIXE.'article ON '.MYSQL_PREFIXE.'article.article_groupe_id = '.MYSQL_PREFIXE.'article_groupe.article_groupe_id '.
'WHERE '.MYSQL_PREFIXE.'article_groupe.article_groupe_id = '.$articleGroupeId.' '.
'AND '.MYSQL_PREFIXE.'article_groupe.client_id = '.$client->getId().' '.
'GROUP BY '.MYSQL_PREFIXE.'article_groupe.article_groupe_id';
if ($requete = mysql_query($sql))
if ($resultat = mysql_fetch_object($requete))
{
$articleGroupe = new ArticleGroupe($articleGroupeId, $client, new Langue(intval($resultat->langue_id)), $resultat->article_groupe_titre, $resultat->article_groupe_description);
$articleGroupe->setNombreArticles(intval($resultat->total));
return $articleGroupe;
}
return new ArticleGroupe();
}
public function getArticleGroupesParClient($client)
{
$tab = array();
$sql = 'SELECT article_groupe_id, article_groupe_titre, '.MYSQL_PREFIXE.'langue.langue_id, langue_nom, langue_icone '.
'FROM '.MYSQL_PREFIXE.'article_groupe '.
'INNER JOIN '.MYSQL_PREFIXE.'langue ON '.MYSQL_PREFIXE.'article_groupe.langue_id = '.MYSQL_PREFIXE.'langue.langue_id '.
'WHERE client_id = '.$client->getId();
if ($requete = mysql_query($sql))
while ($resultat = mysql_fetch_object($requete))
$tab[] = new ArticleGroupe(intval($resultat->article_groupe_id), null, new Langue(intval($resultat->langue_id), $resultat->langue_nom, $resultat->langue_icone), $resultat->article_groupe_titre);
return $tab;
}
}
?> |
Partager