Adding flash messages see BT#9016

Just add messages using for example:
Display::addFlash(Display::return_message(get_lang('Save'), 'warning'));

Chamilo will show the message and delete it from the session.
So the message will not be shown twice.
1.9.x
Julio Montoya 10 years ago
parent 882dbe1975
commit 7f85cac35a
  1. 48
      main/inc/lib/display.lib.php
  2. 5
      main/inc/lib/template.lib.php
  3. 8
      main/inc/lib/wami-recorder/record_document.php
  4. 23
      main/newscorm/lp_add_audio.php
  5. 8
      main/template/default/layout/page_body.tpl

@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
use \ChamiloSession as Session;
/**
* Class Display
* Contains several public functions dealing with the display of
@ -1905,4 +1907,50 @@ class Display
return null;
}
/**
* Adds a message in the queue
* @param string $message
*/
public static function addFlash($message)
{
$messages = Session::read('flash_messages');
if (empty($messages)) {
$messages[] = $message;
} else {
array_push($messages, $message);
}
Session::write('flash_messages', $messages);
}
/**
* @return string
*/
public static function getFlashToString()
{
$messages = Session::read('flash_messages');
$messageToString = '';
if (!empty($messages)) {
foreach ($messages as $message) {
$messageToString .= $message;
}
}
return $messageToString;
}
/**
* Shows the message from the session
*/
public static function showFlash()
{
echo self::getFlashToString();
}
/**
* Destroys the message session
*/
public static function cleanFlashMessages()
{
Session::erase('flash_messages');
}
}

@ -6,6 +6,7 @@ require_once api_get_path(SYS_PATH).'vendor/twig/twig/lib/Twig/Autoloader.php';
/**
* Class Template
*
* @author Julio Montoya <gugli100@gmail.com>
* @todo better organization of the class, methods and variables
*
@ -151,8 +152,6 @@ class Template
$this->templateFolder = $defaultStyle;
}
$this->assign('template', $this->templateFolder);
$this->assign('css_styles', $this->theme);
$this->assign('login_class', null);
@ -965,6 +964,8 @@ class Template
*/
public function display($template)
{
$this->assign('flash_messages', Display::getFlashToString());
Display::cleanFlashMessages();
echo $this->twig->render($template, $this->params);
}

@ -1,6 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
$language_file = array('document');
require_once '../../../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
@ -89,6 +90,7 @@ $file = array(
)
);
$output = true;
ob_start();
$documentData = DocumentManager::upload_document(
$file,
$wamidir,
@ -99,6 +101,7 @@ $documentData = DocumentManager::upload_document(
false,
$output
);
$contents = ob_get_contents();
if (!empty($documentData)) {
$newDocId = $documentData['id'];
@ -125,6 +128,11 @@ if (!empty($documentData)) {
$lp->set_modified_on();
$lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId);
Display::addFlash(
Display::return_message(get_lang('Updated'), 'info')
);
}
}
} else {
Display::addFlash($contents);
}

@ -5,9 +5,6 @@
* @author Julio Montoya - Improving the list of templates
* @package chamilo.learnpath
*/
/**
* INIT SECTION
*/
$this_section = SECTION_COURSES;
@ -54,14 +51,14 @@ $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpa
switch ($type) {
case 'chapter':
$interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
$interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewChapter'));
$interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
$interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewChapter'));
break;
case 'document':
$interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
$interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
break;
default:
$interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewStep'));
$interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewStep'));
break;
}
@ -76,8 +73,8 @@ if (empty($lp_item_id)) {
api_not_allowed();
}
$courseInfo = api_get_course_info();
$lp_item = new learnpathItem($lp_item_id);
$tpl = new Template(null);
$form = new FormValidator('add_audio', 'post', api_get_self().'?action=add_audio&id='.$lp_item_id, null, array('enctype' => 'multipart/form-data'));
$suredel = trim(get_lang('AreYouSureToDelete'));
@ -85,12 +82,12 @@ $lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
$file = null;
if (isset($lp_item->audio) && !empty($lp_item->audio)) {
$file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio.'?'.api_get_cidreq();
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio.'?'.api_get_cidreq();
if (!file_exists($file)) {
$file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio.'?'.api_get_cidreq();
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio.'?'.api_get_cidreq();
}
}
@ -105,6 +102,8 @@ $page .= '</div>';
$recordVoiceForm = Display::page_subheader(get_lang('RecordYourVoice'));
$page .= '<div id="doc_form" class="span8">';
$tpl = new Template(null);
$tpl->assign('unique_file_id', api_get_unique_id());
$tpl->assign('course_code', api_get_course_id());
$tpl->assign('php_session_id', session_id());

@ -5,16 +5,18 @@
</div>
{% endif %}
{{ flash_messages }}
{# Page header #}
{% if header != '' %}
{% if header != '' %}
<div class="page-header">
<h1>{{ header }}</h1>
</div>
{% endif %}
{# Show messages #}
{% if message != '' %}
{% if message != '' %}
<section id="messages">
{{ message}}
</section>
{% endif %}
{% endif %}

Loading…
Cancel
Save