summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-04-17 19:05:53 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-04-17 19:05:53 +0200
commit392672ab2771c6d22f55017c4ed64a0e00945b23 (patch)
tree087ae495e38551392c94d942a4b6f32a7ebae015
parent6ce2b575eb501733e6936ac4b5f2e70d0f6ca13b (diff)
Fix issue #58 : possibilité de vider une catégorie
-rwxr-xr-xapp/controllers/configureController.php1
-rwxr-xr-xapp/controllers/feedController.php38
-rwxr-xr-xapp/models/Category.php14
-rw-r--r--app/models/Feed.php14
-rw-r--r--app/views/configure/categorize.phtml11
5 files changed, 68 insertions, 10 deletions
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php
index 428768b9b..9f4a8b24a 100755
--- a/app/controllers/configureController.php
+++ b/app/controllers/configureController.php
@@ -56,6 +56,7 @@ class configureController extends ActionController {
}
$this->view->categories = $catDAO->listCategories ();
+ $this->view->defaultCategory = $catDAO->getDefault ();
View::prependTitle ('Gestion des catégories - ');
}
diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php
index fb0f790fd..7a34430ea 100755
--- a/app/controllers/feedController.php
+++ b/app/controllers/feedController.php
@@ -228,19 +228,43 @@ class feedController extends ActionController {
array ('error' => array ('Vous n\'avez pas le droit d\'accéder à cette page'))
);
} else {
+ $type = Request::param ('type', 'feed');
$id = Request::param ('id');
$feedDAO = new FeedDAO ();
- $feedDAO->deleteFeed ($id);
+ if ($type == 'category') {
+ if ($feedDAO->deleteFeedByCategory ($id)) {
+ $notif = array (
+ 'type' => 'good',
+ 'content' => 'La catégorie a été vidée'
+ );
+ } else {
+ $notif = array (
+ 'type' => 'bad',
+ 'content' => 'Un problème est survenu'
+ );
+ }
+ } else {
+ if ($feedDAO->deleteFeed ($id)) {
+ $notif = array (
+ 'type' => 'good',
+ 'content' => 'Le flux a été supprimé'
+ );
+ } else {
+ $notif = array (
+ 'type' => 'bad',
+ 'content' => 'Un problème est survenu'
+ );
+ }
+ }
- // notif
- $notif = array (
- 'type' => 'good',
- 'content' => 'Le flux a été supprimé'
- );
Session::_param ('notification', $notif);
- Request::forward (array ('c' => 'configure', 'a' => 'feed'), true);
+ if ($type == 'category') {
+ Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true);
+ } else {
+ Request::forward (array ('c' => 'configure', 'a' => 'feed'), true);
+ }
}
}
diff --git a/app/models/Category.php b/app/models/Category.php
index ae803591f..7ce572e71 100755
--- a/app/models/Category.php
+++ b/app/models/Category.php
@@ -158,6 +158,20 @@ class CategoryDAO extends Model_pdo {
return HelperCategory::daoToCategory ($stm->fetchAll (PDO::FETCH_ASSOC));
}
+ public function getDefault () {
+ $sql = 'SELECT * FROM category WHERE id="000000"';
+ $stm = $this->bd->prepare ($sql);
+
+ $stm->execute ();
+ $res = $stm->fetchAll (PDO::FETCH_ASSOC);
+ $cat = HelperCategory::daoToCategory ($res);
+
+ if (isset ($cat[0])) {
+ return $cat[0];
+ } else {
+ return false;
+ }
+ }
public function checkDefault () {
$def_cat = $this->searchById ('000000');
diff --git a/app/models/Feed.php b/app/models/Feed.php
index 070f044a9..222e22256 100644
--- a/app/models/Feed.php
+++ b/app/models/Feed.php
@@ -283,6 +283,20 @@ class FeedDAO extends Model_pdo {
return false;
}
}
+ public function deleteFeedByCategory ($id) {
+ $sql = 'DELETE FROM feed WHERE category=?';
+ $stm = $this->bd->prepare ($sql);
+
+ $values = array ($id);
+
+ if ($stm && $stm->execute ($values)) {
+ return true;
+ } else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
+ return false;
+ }
+ }
public function searchById ($id) {
$sql = 'SELECT * FROM feed WHERE id=?';
diff --git a/app/views/configure/categorize.phtml b/app/views/configure/categorize.phtml
index 943dd489e..660ddef20 100644
--- a/app/views/configure/categorize.phtml
+++ b/app/views/configure/categorize.phtml
@@ -6,13 +6,18 @@
<form method="post" action="<?php echo _url ('configure', 'categorize'); ?>">
<legend>Gestion des catégories - <a href="<?php echo _url ('configure', 'feed'); ?>">gestion des flux</a></legend>
+ <p class="alert alert-warn">Lors de la suppression d'une catégorie, ses flux seront automatiquement classés dans <em><?php echo $this->defaultCategory->name (); ?></em>.</p>
+
<?php $i = 0; foreach ($this->categories as $cat) { $i++; ?>
<div class="form-group">
- <label class="group-name" for="cat_<?php echo $cat->id (); ?>">Catégorie n°<?php echo $i; ?></label>
+ <label class="group-name" for="cat_<?php echo $cat->id (); ?>">
+ Catégorie n°<?php echo $i; ?>
+ </label>
<div class="group-controls">
<input type="text" id="cat_<?php echo $cat->id (); ?>" name="categories[]" value="<?php echo $cat->name (); ?>" />
- <?php if ($cat->id () == '000000') { ?>
- <i class="icon i_help"></i> ne peut pas être supprimé
+ <a href="<?php echo _url ('feed', 'delete', 'id', $cat->id (), 'type', 'category'); ?>">Vider ?</a> (<?php echo $cat->nbFeed (); ?> flux)
+ <?php if ($cat->id () == $this->defaultCategory->id ()) { ?>
+ <i class="icon i_help"></i> ne peut pas être supprimée
<?php } ?>
<input type="hidden" name="ids[]" value="<?php echo $cat->id (); ?>" />
</div>