Permalink
Browse files

global news Atom/RSS feed added, fixes #279.

  • Loading branch information...
1 parent 3864da7 commit bab1f8052933f0e3c5a3becc997417abadd6cff9 @bfontaine bfontaine committed Feb 2, 2013
Showing with 68 additions and 31 deletions.
  1. +6 −0 controllers/feeds.php
  2. +51 −24 helpers/feeds.php
  3. +9 −7 helpers/news.php
  4. +2 −0 routes.php
View
6 controllers/feeds.php
@@ -16,4 +16,10 @@ function display_course_atom_feed() {
return feed_helper(params('cursus'), params('course'), 'atom');
}
+function display_global_rss_feed() {
+ return feed_helper(null, null, 'rss', 50, 0);
+}
+function display_global_atom_feed() {
+ return feed_helper(null, null, 'atom', 50, 0);
+}
View
75 helpers/feeds.php
@@ -20,11 +20,14 @@ function feedElCmp($a, $b) {
function feed_helper($cursus_sn, $course_sn, $type='atom',
$news_count=25, $contents_count=25) {
- $cursus = CursusQuery::create()
- ->findOneByShortName($cursus_sn);
+ $cursus = null;
+ if ($cursus_sn !== null) {
+ $cursus = CursusQuery::create()
+ ->findOneByShortName($cursus_sn);
- if ($cursus === null) {
- halt(NOT_FOUND);
+ if ($cursus === null) {
+ halt(NOT_FOUND);
+ }
}
$course = null;
@@ -41,7 +44,20 @@ function feed_helper($cursus_sn, $course_sn, $type='atom',
$user_rights = is_connected() ? user()->getRights() : 0;
- $title = $course ? $course->getName() : $cursus->getName();
+ $title = 'IP7';
+
+ if ($course) {
+ $title = $course->getName();
+ } else if ($cursus) {
+ $title = $cursus->getName();
+ }
+
+ $desc = 'Dernières actualités ';
+
+ if ($contents_count > 0) {
+ $desc .= 'et nouveaux contenus ';
+ }
+
$isRSS = ($type === 'rss'); // RSS2 or Atom
$time = time();
$root = 'http://www.infop7.org';
@@ -51,7 +67,7 @@ function feed_helper($cursus_sn, $course_sn, $type='atom',
$feed->setTitle($title);
$feed->setLink($url);
- $feed->setDescription('Dernières actualités et nouveaux contenus de ' . $title);
+ $feed->setDescription($desc . \Lang\de($title));
if ($isRSS) {
@@ -66,25 +82,34 @@ function feed_helper($cursus_sn, $course_sn, $type='atom',
}
- $news = get_news($cursus, $course, $news_count);
- $contents = ContentQuery::create()
- ->joinWith('Content.Course')
- ->filterByCursus($cursus)
- ->filterByValidated(true)
- ->filterByDeleted(false)
- ->where( '(SELECT content_types.access_rights '
- . 'FROM content_types '
- . 'WHERE content_types.id = contents.content_type_id) <= ?',
- $user_rights, PDO::PARAM_INT)
- ->where('Access_Rights <= ?', $user_rights, PDO::PARAM_INT)
- ->orderByDate('desc')
- ->limit($contents_count);
+ $news = get_news($cursus, $course, $news_count, true);
- if ($course) {
- $contents = $contents->filterByCourse($course);
- }
+ if ($contents_count > 0) {
+ $title = $course ? $course->getName() : $cursus->getName();
+ $contents = ContentQuery::create()
+ ->filterByValidated(true)
+ ->filterByDeleted(false)
+ ->where( '(SELECT content_types.access_rights '
+ . 'FROM content_types '
+ . 'WHERE content_types.id = contents.content_type_id) <= ?',
+ $user_rights, PDO::PARAM_INT)
+ ->where('Access_Rights <= ?', $user_rights, PDO::PARAM_INT)
+ ->orderByDate('desc')
+ ->limit($contents_count);
+
+ if ($cursus) {
+ $contents = $contents->joinWith('Content.Course')->filterByCursus($cursus);
+ }
- $contents = $contents->find();
+ if ($course) {
+ $contents = $contents->filterByCourse($course);
+ }
+
+ $contents = $contents->find();
+
+ } else {
+ $contents = array();
+ }
$els = array();
@@ -123,7 +148,9 @@ function feed_helper($cursus_sn, $course_sn, $type='atom',
}
- usort($els, 'feedElCmp');
+ if ($contents_count > 0 && $news_count > 0) {
+ usort($els, 'feedElCmp');
+ }
foreach ($els as $_ => $e) {
View
16 helpers/news.php
@@ -1,17 +1,19 @@
<?php
// Return news (Propel objects)
-function get_news($cursus=null, $course=null, $limit=10) {
+function get_news($cursus=null, $course=null, $limit=10, $with_expired=false) {
$user_rights = is_connected() ? user()->getRights() : 0;
$q = NewsQuery::create()
->where('Access_Rights <= ?', $user_rights, PDO::PARAM_INT)
- ->limit($limit)
- ->condition('has_no_expiration', 'Expiration_Date IS NULL')
- ->condition('hasnt_expired', 'Expiration_date > NOW()')
- ->where(array('has_no_expiration', 'hasnt_expired'), 'or')
- ->orderByDate('desc');
+ ->limit($limit);
+
+ if (!$with_expired) {
+ $q = $q->condition('has_no_expiration', 'Expiration_Date IS NULL')
+ ->condition('hasnt_expired', 'Expiration_date > NOW()')
+ ->where(array('has_no_expiration', 'hasnt_expired'), 'or');
+ }
if ($cursus) {
$q = $q->filterByCursus($cursus);
@@ -21,7 +23,7 @@ function get_news($cursus=null, $course=null, $limit=10) {
$q = $q->filterByCourse($course);
}
- return $q->find();
+ return $q->orderByDate('desc')->find();
}
// check if a news is correct (for update/creation)
View
2 routes.php
@@ -92,6 +92,8 @@
## news archives
dispatch('/actus/archives', 'display_news_archives');
+dispatch('/actus/flux.rss', 'display_global_rss_feed');
+dispatch('/actus/flux.atom', 'display_global_atom_feed');
## (almost-)static pages
dispatch('/contact', 'display_contact_page');

0 comments on commit bab1f80

Please sign in to comment.