diff options
| author | 2013-03-16 22:52:07 +0100 | |
|---|---|---|
| committer | 2013-03-16 22:52:07 +0100 | |
| commit | 59b2ae54caf7a23b459193ba73b17d7c9c3317af (patch) | |
| tree | cefa1849d7366ed7234c4350933838fac1272730 /app/controllers/feedController.php | |
| parent | 8c2b3bfc30caa22258b9569b8a228db0adc90618 (diff) | |
Fix bug #24 : les flux ont désormais une catégorie par défaut
Diffstat (limited to 'app/controllers/feedController.php')
| -rwxr-xr-x | app/controllers/feedController.php | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index 48fcdf8cb..fd3abbcf2 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -16,43 +16,56 @@ class feedController extends ActionController { $feed = new Feed ($url); $feed->load (); + $catDAO = new CategoryDAO (); + $cat = $feed->category (); + if ($cat == '') { + $cat = $catDAO->getDefault ()->id (); + } + $feedDAO = new FeedDAO (); $values = array ( 'id' => $feed->id (), 'url' => $feed->url (), - 'category' => null, + 'category' => $cat, 'name' => $feed->name (), 'website' => $feed->website (), 'description' => $feed->description (), 'lastUpdate' => time () ); - $feedDAO->addFeed ($values); + if ($feedDAO->addFeed ($values)) { + $entryDAO = new EntryDAO (); + $entries = $feed->entries (); + foreach ($entries as $entry) { + $values = array ( + 'id' => $entry->id (), + 'guid' => $entry->guid (), + 'title' => $entry->title (), + 'author' => $entry->author (), + 'content' => $entry->content (), + 'link' => $entry->link (), + 'date' => $entry->date (true), + 'is_read' => $entry->isRead (), + 'is_favorite' => $entry->isFavorite (), + 'id_feed' => $feed->id () + ); + $entryDAO->addEntry ($values); + } - $entryDAO = new EntryDAO (); - $entries = $feed->entries (); - foreach ($entries as $entry) { - $values = array ( - 'id' => $entry->id (), - 'guid' => $entry->guid (), - 'title' => $entry->title (), - 'author' => $entry->author (), - 'content' => $entry->content (), - 'link' => $entry->link (), - 'date' => $entry->date (true), - 'is_read' => $entry->isRead (), - 'is_favorite' => $entry->isFavorite (), - 'id_feed' => $feed->id () + // notif + $notif = array ( + 'type' => 'good', + 'content' => 'Le flux <em>' . $feed->name () . '</em> a bien été ajouté' + ); + Session::_param ('notification', $notif); + $params['id'] = $feed->id (); + } else { + // notif + $notif = array ( + 'type' => 'bad', + 'content' => '<em>' . $feed->name () . '</em> n\' a pas pu être ajouté' ); - $entryDAO->addEntry ($values); + Session::_param ('notification', $notif); } - - // notif - $notif = array ( - 'type' => 'good', - 'content' => 'Le flux <em>' . $feed->url () . '</em> a bien été ajouté' - ); - Session::_param ('notification', $notif); - $params['id'] = $feed->id (); } catch (FileNotExistException $e) { Log::record ($e->getMessage (), Log::ERROR); // notif @@ -137,19 +150,11 @@ class feedController extends ActionController { } else { $entryDAO = new EntryDAO (); $feedDAO = new FeedDAO (); - $catDAO = new CategoryDAO (); $categories = Request::param ('categories', array ()); $feeds = Request::param ('feeds', array ()); - - foreach ($categories as $cat) { - $values = array ( - 'id' => $cat->id (), - 'name' => $cat->name (), - 'color' => $cat->color () - ); - $catDAO->addCategory ($values); - } + + $this->addCategories ($categories); $nb_month_old = $this->view->conf->oldEntries (); $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); @@ -230,4 +235,17 @@ class feedController extends ActionController { Request::forward (array ('c' => 'configure', 'a' => 'feed'), true); } } + + private function addCategories ($categories) { + $catDAO = new CategoryDAO (); + + foreach ($categories as $cat) { + $values = array ( + 'id' => $cat->id (), + 'name' => $cat->name (), + 'color' => $cat->color () + ); + $catDAO->addCategory ($values); + } + } } |
