Преглед изворни кода

Flux déplacés de catégories lors de la suppression de la leur (issue #28)

Marien Fressinaud пре 13 година
родитељ
комит
1bee8ad9a7
3 измењених фајлова са 30 додато и 2 уклоњено
  1. 5 1
      app/controllers/configureController.php
  2. 24 0
      app/models/Feed.php
  3. 1 1
      app/views/configure/feed.phtml

+ 5 - 1
app/controllers/configureController.php

@@ -11,8 +11,11 @@ class configureController extends ActionController {
 	}
 
 	public function categorizeAction () {
+		$feedDAO = new FeedDAO ();
 		$catDAO = new CategoryDAO ();
 		$catDAO->checkDefault ();
+		$defaultCategory = $catDAO->getDefault ();
+		$defaultId = $defaultCategory->id ();
 
 		if (Request::isPost ()) {
 			$cats = Request::param ('categories', array ());
@@ -27,7 +30,8 @@ class configureController extends ActionController {
 						'color' => $cat->color ()
 					);
 					$catDAO->updateCategory ($ids[$key], $values);
-				} elseif ($ids[$key] != '000000') {
+				} elseif ($ids[$key] != $defaultId) {
+					$feedDAO->changeCategory ($ids[$key], $defaultId);
 					$catDAO->deleteCategory ($ids[$key]);
 				}
 			}

+ 24 - 0
app/models/Feed.php

@@ -296,6 +296,30 @@ class FeedDAO extends Model_pdo {
 		}
 	}
 
+	public function changeCategory ($idOldCat, $idNewCat) {
+		$catDAO = new CategoryDAO ();
+		$newCat = $catDAO->searchById ($idNewCat);
+		if (!$newCat) {
+			$newCat = $catDAO->getDefault ();
+		}
+
+		$sql = 'UPDATE feed SET category=? WHERE category=?';
+		$stm = $this->bd->prepare ($sql);
+
+		$values = array (
+			$newCat->id (),
+			$idOldCat
+		);
+
+		if ($stm && $stm->execute ($values)) {
+			return true;
+		} else {
+			$info = $stm->errorInfo();
+			Log::record ('SQL error : ' . $info[2], Log::ERROR);
+			return false;
+		}
+	}
+
 	public function deleteFeed ($id) {
 		$sql = 'DELETE FROM feed WHERE id=?';
 		$stm = $this->bd->prepare ($sql);

+ 1 - 1
app/views/configure/feed.phtml

@@ -2,7 +2,7 @@
 
 <?php if ($this->flux) { ?>
 <div class="post">
-	<a href="<?php echo _url ('index', 'index'); ?>"><?php echo Translate::t ('back_to_rss_feeds'); ?></a>
+	<a href="<?php echo _url ('index', 'index'); ?>"><?php echo Translate::t ('back_to_rss_feeds'); ?></a> <?php echo Translate::t ('or'); ?> <a href="<?php echo _url ('index', 'index', 'get', 'f_' . $this->flux->id ()); ?>"><?php echo Translate::t ('filter'); ?></a>
 
 	<h1><?php echo $this->flux->name (); ?></h1>
 	<?php echo $this->flux->description (); ?>