Fixing system announcements adding an alert in the menu.

1.10.x
Julio Montoya 12 years ago
parent edb49d87bc
commit d8e7625e46
  1. 2
      main/inc/lib/page.lib.php
  2. 81
      main/inc/lib/system_announcements.lib.php
  3. 4
      main/inc/routes.php
  4. 2
      src/ChamiloLMS/Controller/IndexController.php
  5. 20
      src/ChamiloLMS/Controller/NewsController.php

@ -384,7 +384,7 @@ class PageController
* @assert () != ''
* @assert (1) != ''
*/
public function return_announcements($user_id = null, $show_slide = true)
public function getAnnouncements($user_id = null, $show_slide = true)
{
// Display System announcements
$announcement = isset($_GET['announcement']) ? intval($_GET['announcement']) : null;

@ -625,20 +625,28 @@ class SystemAnnouncementManager
}
/**
* Displays announcements as an slideshow
* @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER
* @param int $id The identifier of the announcement to display
* @param $visible
* @param null $id
* @param string $type
* @param bool $getCount
* @param int $cutSize
* @return string
*/
public static function display_announcements_slider($visible, $id = null)
public static function getAnnouncements($visible, $id = null, $type = 'resumed', $getCount = false, $cutSize = 800)
{
$user_selected_language = Database::escape_string(api_get_interface_language());
$table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
$cut_size = 800;
$now = api_get_utc_datetime();
$select = '*';
if ($getCount) {
$select = 'count(*) as count';
}
$sql = "SELECT * FROM ".$table."
WHERE ( lang = '$user_selected_language' OR lang IS NULL) AND ( '$now' >= date_start AND '$now' <= date_end) ";
$sql = "SELECT $select
FROM $table
WHERE
( lang = '$user_selected_language' OR lang IS NULL) AND
( '$now' >= date_start AND '$now' <= date_end) ";
switch ($visible) {
case self::VISIBLE_GUEST :
@ -664,25 +672,70 @@ class SystemAnnouncementManager
$sql .= " ORDER BY date_start DESC";
$announcements = Database::query($sql);
$html = '';
if (Database::num_rows($announcements) > 0) {
$html .= Display::page_header(get_lang('SystemAnnouncements'));
if ($getCount) {
$announcement = Database::fetch_array($announcements);
return $announcement['count'];
}
$options = array();
if (Database::num_rows($announcements) > 0) {
while ($announcement = Database::fetch_object($announcements)) {
$content = $announcement->content;
$url = api_get_path(WEB_PUBLIC_PATH).'news/'.$announcement->id;
if (empty($id)) {
if (api_strlen(strip_tags($content)) > $cut_size) {
$content = Text::cut($announcement->content, $cut_size).' '.Display::url(get_lang('More'), $url);
if ($type == 'resumed') {
if (api_strlen(strip_tags($content)) > $cutSize) {
$content = Security::remove_XSS(Text::cut($announcement->content, $cutSize)).
' '.Display::url(get_lang('More'), $url);
}
} else {
$content = $announcement->content;
}
}
$announcement->title = Text::cut($announcement->title, $cutSize);
$options[]= array(
'title' => $announcement->title,
'content' => $content,
);
}
$html .= Display::getSlider('portal_news', $options);
}
return $options;
}
/**
* Displays announcements as an slideshow
* @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER
* @param int $id The identifier of the announcement to display
* @return string
*/
public static function display_announcements_slider($visible, $id = null)
{
$announcements = self::getAnnouncements($visible, $id, 'resumed');
$html = null;
if (!empty($announcements)) {
$html .= Display::page_header(get_lang('SystemAnnouncements'));
$html .= Display::getSlider('portal_news', $announcements);
}
return $html;
}
/**
* Displays announcements as an slideshow
* @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER
* @param int $id The identifier of the announcement to display
* @param string $type
* @return string
*/
public static function displayAnnouncementsList($visible, $id = null, $type = 'resumed')
{
$announcements = self::getAnnouncements($visible, $id, $type);
$html = null;
if (!empty($announcements)) {
$html .= Display::page_header(get_lang('SystemAnnouncements'));
foreach($announcements as $announcement) {
$html .= Display::page_subheader2($announcement['title']);
$html .= "<p> ".$announcement['content']."</p>";
}
}
return $html;
}

@ -569,6 +569,10 @@ $app->match('/certificates/{id}', 'certificate.controller:indexAction', 'GET');
/** Portal news */
$app->match('/news/{id}', 'news.controller:indexAction', 'GET')
->bind('portal_news_per_id');
/** Portal news */
$app->match('/news', 'news.controller:newsAction', 'GET')
->bind('portal_news');
/** LP controller (subscribe users to a LP) */

@ -133,7 +133,7 @@ class IndexController extends CommonController
if (api_get_setting('show_hot_courses') == 'true') {
$hotCourses = $pageController->returnHotCourses();
}
$announcementsBlock = $pageController->return_announcements();
$announcementsBlock = $pageController->getAnnouncements();
}
$template->assign('hot_courses', $hotCourses);

@ -29,7 +29,7 @@ class NewsController
} else {
$visibility = api_is_allowed_to_create_course() ? \SystemAnnouncementManager::VISIBLE_TEACHER : \SystemAnnouncementManager::VISIBLE_STUDENT;
}
$content = \SystemAnnouncementManager::display_announcements_slider($visibility, $id);
$content = \SystemAnnouncementManager::displayAnnouncementsList($visibility, $id, 'full');
$app['template']->assign('content', $content);
$app['template']->assign('actions', $actions);
@ -37,4 +37,22 @@ class NewsController
return new Response($response, 200, array());
}
/**
* @param Application $app
* @return Response
*/
public function newsAction(Application $app)
{
if (api_is_anonymous()) {
$visibility = \SystemAnnouncementManager::VISIBLE_GUEST;
} else {
$visibility = api_is_allowed_to_create_course() ? \SystemAnnouncementManager::VISIBLE_TEACHER : \SystemAnnouncementManager::VISIBLE_STUDENT;
}
$content = \SystemAnnouncementManager::displayAnnouncementsList($visibility, null, 'resumed');
$app['template']->assign('content', $content);
$response = $app['template']->renderLayout('layout_1_col.tpl');
return new Response($response, 200, array());
}
}

Loading…
Cancel
Save