From 2bdde4bb94f9e81a38cef49d3c25053d75dc551f Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 14 Feb 2011 13:53:39 +0000 Subject: [PATCH] --- inc/commons/class.common.core.php | 7 ++++--- inc/ws/Controlleur/class.ws.flash.php | 7 +++++-- inc/ws/DAO/class.ws.dao.theme.php | 15 ++++++++++++--- inc/ws/Metier/class.ws.theme.php | 4 ++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index fe60dd7b4..5f5f47f64 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -511,10 +511,11 @@ class commonCore extends cubeCore { . 'LEFT JOIN utilisateurs_entreprise f ON t.facturable_id=f.utilisateur_id ' . 'LEFT JOIN taches ta ON ta.tache_id=b.tache' , 'TEMPTABLE'); - $this->views->createView('themes_vue', 'SELECT t.*,COUNT(*) AS nb_books,GROUP_CONCAT(DISTINCT b.book_id) AS books ' + $this->views->createView('themes_books_nb', 'SELECT theme,COUNT(*) AS nb FROM books GROUP BY theme'); + $this->views->createView('themes_vue', 'SELECT t.*, b.nb as nbBooks, CONCAT(e.prenom,\' \',e.nom,\' (\',e.rs,\')\') AS proprietaire_nom ' . 'FROM themes t ' - . 'LEFT JOIN books b ON t.theme_id=b.theme ' - . 'GROUP BY t.theme_id'); + . 'LEFT JOIN themes_books_nb b ON t.theme_id=b.theme ' + . 'LEFT JOIN utilisateurs_entreprise e ON t.proprietaire=e.utilisateur_id'); $this->views->createView('demandes_vue', 'SELECT d.*, CONCAT(c.rs,\' (\',c.prenom,\' \',c.nom,\')\') AS utilisateur_nom, CONCAT(r.rs,\' (\',r.prenom,\' \',r.nom,\')\') AS revendeur_nom, c.entreprise AS entreprise, a.prenom AS administrateur_nom ' . 'FROM demandes d ' . 'LEFT JOIN utilisateurs_entreprise r ON d.revendeur=r.utilisateur_id ' diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index 612dd0a6c..b43c0bb71 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -289,10 +289,12 @@ class wsFlash extends cubeFlashGateway { if (isset($this->args['book_id'])) { $dao = new wsDAOBook($core->con); $book = $dao->selectById($this->args['book_id']); + } else { + $this->args['book_id'] = 0; } $dao = new wsDAOTheme($core->con); - $themes = $dao->getAllThemes($core->user, 'ORDER BY FIELD (theme_id,1) DESC, theme_id DESC'); + $themes = $dao->getAllThemes($core->user, 'ORDER BY FIELD (theme_id,' . $this->args['book_id'] . ',1) DESC, theme_id DESC', true); foreach($themes as $theme) { $t = $this->xml->addChild('theme'); $t->addAttribute('id', $theme->theme_id); @@ -309,7 +311,8 @@ class wsFlash extends cubeFlashGateway { $right = 'r'; } $t->addAttribute('right', $right); - $t->addAttribute('books', ($theme->nbBooks) - ($mine?'1':'0')); + $t->addAttribute('proprietaire', $theme->proprietaire_nom); + $t->addAttribute('books', max(($theme->nbBooks) - ($mine?1:0), 0)); } } diff --git a/inc/ws/DAO/class.ws.dao.theme.php b/inc/ws/DAO/class.ws.dao.theme.php index ab867b9a8..5180e1f45 100644 --- a/inc/ws/DAO/class.ws.dao.theme.php +++ b/inc/ws/DAO/class.ws.dao.theme.php @@ -7,9 +7,11 @@ class wsDAOTheme extends commonDAO { $theme->nom = $r->nom; $theme->date = $r->date; $theme->proprietaire = $r->proprietaire; - if ($r->exists('books')) { - $theme->books = explode(',', $r->books); - $theme->nbBooks = $r->nb_books; + if ($r->exists('nbBooks')) { + $theme->nbBooks = $r->nbBooks; + } + if ($r->exists('proprietaire_nom')) { + $theme->proprietaire_nom = $r->proprietaire_nom; } $theme->signature = $r->signature; $theme->icones = $r->icones; @@ -85,6 +87,13 @@ class wsDAOTheme extends commonDAO { if (!$onlyFiles) { $this->con->execute('DELETE FROM themes WHERE theme_id=\'' . $this->con->escape($theme_id) . '\''); } + $fref = WS_THEMES . '/' . $theme_id; + if (file_exists($fref)) { + files::deltree($fref); + } + if (file_exists($fref . '.jpg')) { + unlink($fref . '.jpg'); + } } public function rename($theme_id, $newname) diff --git a/inc/ws/Metier/class.ws.theme.php b/inc/ws/Metier/class.ws.theme.php index 4f04dbbc7..b926cb916 100644 --- a/inc/ws/Metier/class.ws.theme.php +++ b/inc/ws/Metier/class.ws.theme.php @@ -22,8 +22,8 @@ class wsTheme extends cubeMetier { protected $nom; protected $date; protected $parametres; - protected $books; - protected $nbBooks; + protected $proprietaire_nom; + protected $nbBooks = 0; } ?> \ No newline at end of file -- 2.39.5