Move no-data-view block code in a function

pull/3890/head
Julio Montoya 4 years ago
parent 5f25ea0d04
commit 0d7afc280a
  1. 13
      public/main/announcements/announcements.php
  2. 11
      public/main/course_progress/index.php
  3. 15
      public/main/exercise/exercise.class.php
  4. 3
      public/main/glossary/index.php
  5. 17
      public/main/inc/lib/display.lib.php
  6. 63
      public/main/inc/lib/glossary.lib.php
  7. 20
      public/main/inc/lib/link.lib.php
  8. 1
      public/main/link/link.php
  9. 15
      public/main/template/default/course_progress/progress.html.twig
  10. 55
      public/main/template/default/glossary/list.html.twig
  11. 37
      public/main/template/default/link/index.html.twig

@ -288,17 +288,12 @@ switch ($action) {
if (($allowToEdit || $allowStudentInGroupToSend) &&
(empty($_GET['origin']) || 'learnpath' !== $_GET['origin'])
) {
$html .= '<div id="no-data-view">';
$html .= '<h3>'.get_lang('Announcements').'</h3>';
$html .= Display::return_icon('valves.png', '', [], 64);
$html .= '<div class="controls">';
$html .= Display::url(
$html .= Display::noDataView(
get_lang('Announcements'),
Display::return_icon('valves.png', '', [], 64),
get_lang('Add an announcement'),
api_get_self().'?'.api_get_cidreq().'&action=add',
['class' => 'btn btn-primary']
api_get_self().'?'.api_get_cidreq().'&action=add'
);
$html .= '</div>';
$html .= '</div>';
} else {
$html = Display::return_message(get_lang('There are no announcements.'), 'warning');
}

@ -584,6 +584,7 @@ switch ($action) {
$list = [];
$listThematic = [];
$extra = [];
$noData = '';
// Display thematic data
if (!empty($thematic_data)) {
/** @var CThematic $thematic */
@ -673,10 +674,20 @@ switch ($action) {
$extra[$thematic->getIid()]['last_done'] = $last_done_thematic_advance;
$listThematic[] = $thematic;
}
} else {
if (api_is_allowed_to_edit(null, true)) {
$noData = Display::noDataView(
get_lang('Educational programming'),
Display::return_icon('course_progress.png', '', [], 64),
get_lang('Add thematic'),
api_get_path(WEB_CODE_PATH).'course_progress/index.php?'.api_get_cidreq().'&action=thematic_add'
);
}
}
$tpl->assign('extra', $extra);
$tpl->assign('data', $listThematic);
$tpl->assign('no_data', $noData);
$thematicLayout = $tpl->get_template('course_progress/progress.html.twig');
$content = $tpl->fetch($thematicLayout);
break;

@ -9483,17 +9483,12 @@ class Exercise
if (empty($tableRows) && empty($categoryId)) {
if ($is_allowedToEdit && 'learnpath' !== $origin) {
$content .= '<div id="no-data-view">';
$content .= '<h3>'.get_lang('Quiz').'</h3>';
$content .= Display::return_icon('quiz.png', '', [], 64);
$content .= '<div class="controls">';
$content .= Display::url(
'<em class="fa fa-plus"></em> '.get_lang('Create a new test'),
'exercise_admin.php?'.api_get_cidreq(),
['class' => 'btn btn-primary']
$content .= Display::noDataView(
get_lang('Quiz'),
Display::return_icon('quiz.png', '', [], 64),
get_lang('Create a new test'),
'exercise_admin.php?'.api_get_cidreq()
);
$content .= '</div>';
$content .= '</div>';
}
} else {
if (empty($tableRows)) {

@ -467,7 +467,7 @@ switch ($action) {
break;
default:
$tool_name = get_lang('List');
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php?add_ready=1&'.api_get_cidreq().'"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php?add_ready=1&'.api_get_cidreq().'"></script>';
$htmlHeadXtra[] = api_get_js('jquery.highlight.js');
$content = GlossaryManager::display_glossary();
@ -475,7 +475,6 @@ switch ($action) {
}
Display::display_header($tool_name);
Display::display_introduction_section(TOOL_GLOSSARY);
echo $content;

@ -2934,4 +2934,21 @@ HTML;
return $result; // example: #fc443a
}
}
public static function noDataView(string $title, string $icon, string $buttonTitle, string $url): string
{
$content = '<div id="no-data-view">';
$content .= '<h3>'.$title.'</h3>';
$content .= $icon;
$content .= '<div class="controls">';
$content .= self::url(
'<em class="fa fa-plus"></em> '.$buttonTitle,
$url,
['class' => 'btn btn-primary']
);
$content .= '</div>';
$content .= '</div>';
return $content;
}
}

@ -440,12 +440,9 @@ class GlossaryManager
return true;
}
/**
* @return string
*/
public static function getGlossaryView()
public static function getGlossaryView(): string
{
$view = Session::read('glossary_view');
$view = Session::read('glossary_view', '');
if (empty($view)) {
$defaultView = api_get_configuration_value('default_glossary_view');
if (empty($defaultView)) {
@ -480,8 +477,7 @@ class GlossaryManager
'',
ICON_SIZE_MEDIUM
);
$actionsLeft .= '<a
href="'.$url.'&action=addglossary">'.$addIcon.'</a>';
$actionsLeft .= '<a href="'.$url.'&action=addglossary">'.$addIcon.'</a>';
}
if (api_is_allowed_to_edit(null, true)) {
@ -547,31 +543,38 @@ class GlossaryManager
$form->addElement('hidden', 'sid', api_get_session_id());
$form->addButtonSearch(get_lang('Search'));
$actionsRight = $form->returnForm();
$toolbar = Display::toolbarAction('toolbar-document', [$actionsLeft, $actionsRight]);
$content = $toolbar;
$items = self::get_number_glossary_terms();
if (0 != $items && (!$view || 'table' === $view)) {
// @todo Table haven't paggination
$table = new SortableTable(
'glossary',
['GlossaryManager', 'get_number_glossary_terms'],
['GlossaryManager', 'get_glossary_data'],
0
);
$table->set_header(0, get_lang('Term'), true);
$table->set_header(1, get_lang('Term definition'), true);
if (api_is_allowed_to_edit(null, true)) {
$table->set_header(2, get_lang('Detail'), false, 'width=90px', ['class' => 'td_actions']);
$table->set_column_filter(2, ['GlossaryManager', 'actions_filter']);
if (!empty($items)) {
if ('table' === $view) {
// @todo Table haven't pagination
$table = new SortableTable(
'glossary',
['GlossaryManager', 'get_number_glossary_terms'],
['GlossaryManager', 'get_glossary_data'],
0
);
$table->set_header(0, get_lang('Term'), true);
$table->set_header(1, get_lang('Term definition'), true);
if (api_is_allowed_to_edit(null, true)) {
$table->set_header(2, get_lang('Detail'), false, 'width=90px', ['class' => 'td_actions']);
$table->set_column_filter(2, ['GlossaryManager', 'actions_filter']);
}
$content .= $table->return_table();
} else {
$content .= self::displayGlossaryList();
}
} else {
if (api_is_allowed_to_edit(true, true)) {
$content .= Display::noDataView(
get_lang('Glossary'),
Display::return_icon('glossary.png', '', [], 64),
get_lang('Add glossary'),
$url.'&'.http_build_query(['action' => 'addglossary'])
);
}
$content .= $table->return_table();
}
if ('list' === $view) {
$content .= self::displayGlossaryList();
}
return $content;
@ -579,14 +582,12 @@ class GlossaryManager
/**
* Display the glossary terms in a list.
*
* @return bool true
*/
public static function displayGlossaryList()
public static function displayGlossaryList(): string
{
$glossaryList = self::get_glossary_data(0, 1000, 0, 'ASC');
$content = '';
foreach ($glossaryList as $key => $glossary_item) {
foreach ($glossaryList as $glossary_item) {
$actions = '';
if (api_is_allowed_to_edit(null, true)) {
$actions = '<div class="pull-right">'.

@ -1433,11 +1433,11 @@ Do you really want to delete this category and its links ?')."')) return false;\
/* Action Links */
$actions = '';
if (api_is_allowed_to_edit(null, true)) {
$actions .= '<a href="'.api_get_self().'?'.api_get_cidreq(
).'&action=addlink&category_id='.$categoryId.'">'.
$actions .= '<a
href="'.api_get_self().'?'.api_get_cidreq().'&action=addlink&category_id='.$categoryId.'">'.
Display::return_icon('new_link.png', get_lang('Add a link'), '', ICON_SIZE_MEDIUM).'</a>';
$actions .= '<a href="'.api_get_self().'?'.api_get_cidreq(
).'&action=addcategory&category_id='.$categoryId.'">'.
$actions .= '<a
href="'.api_get_self().'?'.api_get_cidreq().'&action=addcategory&category_id='.$categoryId.'">'.
Display::return_icon('new_folder.png', get_lang('Add a category'), '', ICON_SIZE_MEDIUM).'</a>';
}
@ -1516,7 +1516,8 @@ Do you really want to delete this category and its links ?')."')) return false;\
$header .= Display::return_icon('forum_nestedview.png');
} else {
$header .= '<a
class="'.$visibilityClass.'" href="'.api_get_self().'?'.api_get_cidreq().'&category_id='.$categoryItemId.'">';
class="'.$visibilityClass.'"
href="'.api_get_self().'?'.api_get_cidreq().'&category_id='.$categoryItemId.'">';
$header .= Display::return_icon('forum_listview.png');
}
$header .= Security::remove_XSS($category->getCategoryTitle()).'</a>';
@ -1547,6 +1548,15 @@ Do you really want to delete this category and its links ?')."')) return false;\
$counter++;
}
if (empty($counter) && api_is_allowed_to_edit()) {
$content .= Display::noDataView(
get_lang('Links'),
Display::return_icon('links.png', '', [], 64),
get_lang('Add links'),
api_get_self().'?'.api_get_cidreq().'&'.http_build_query(['action' => 'addlink'])
);
}
return $content;
}

@ -67,7 +67,6 @@ if ('editlink' === $action) {
$interbreadcrumb[] = ['url' => 'link.php', 'name' => get_lang('Links')];
}
// Statistics
Event::event_access_tool(TOOL_LINK);
/* Action Handling */

@ -191,19 +191,10 @@
</div>
</div>
{% else %}
<div class="alert alert-info" role="alert">{{ 'There is no thematic section' | trans }}</div>
{% if is_allowed_to_edit %}
<div id="no-data-view" class="tool-view">
<h2>{{ "Educational programming"|trans }}</h2>
<img src="{{ "course_progress.png"|icon(64) }}" width="64" height="64">
<div class="controls">
<a
href="{{ url('legacy_main', {name : 'course_progress/index.php'}) }}?{{ course_url_params ~ "&action=thematic_add" ~ token }}"
class="btn btn-outline-primary">
{{ "Add thematic"|trans }}
</a>
</div>
</div>
{{ no_data }}
{% else %}
<div class="alert alert-info" role="alert">{{ 'There is no thematic section' | trans }}</div>
{% endif %}
{% endif %}
{% endautoescape %}

@ -1,39 +1,26 @@
{% autoescape false %}
{% if data is empty %}
<div class="alert alert-info" role="alert">{{ 'There is no thematic section' | get_lang }}</div>
{% if is_allowed_to_edit %}
<div id="no-data-view" class="tool-view">
<h2>{{ "Glossary"|trans }}</h2>
<img src="{{ "glossary.png"|icon(64) }}" width="64" height="64">
<div class="controls">
<a href="{{ _p.web_self }}?{{ _p.web_cid_query ~ "&action=addglossary" }}" class="btn btn-outline-primary">
{{ "Add glossary"|trans }}
</a>
{% if data is not empty %}
<div class="glossary mt-5">
{% for item in data %}
<div class="item-glossary mb-4 pl-2 pr-2">
{% if item.edit %}
<div class="float-right">
<div class="btn-group" role="group">
<a href="{{ item.edit }}" class="btn btn-light btn-sm">
<i class="fas fa-pencil-alt"></i>
</a>
<a
title="{{ 'Confirm if you want to delete'|trans }}" href="{{ item.delete }}"
class="btn btn-light btn-sm delete-swal">
<i class="far fa-trash-alt"></i>
</a>
</div>
</div>
{% endif %}
<h5 class="terms-title">{{ item.title }}</h5>
{{ item.description }}
</div>
{% endfor %}
</div>
{% endif %}
{% else %}
<div class="glossary mt-5">
{% for item in data %}
<div class="item-glossary mb-4 pl-2 pr-2">
{% if item.edit %}
<div class="float-right">
<div class="btn-group" role="group">
<a href="{{ item.edit }}" class="btn btn-light btn-sm">
<i class="fas fa-pencil-alt"></i>
</a>
<a title="{{ 'Confirm if you want to delete'|trans }}" href="{{ item.delete }}" class="btn btn-light btn-sm delete-swal">
<i class="far fa-trash-alt"></i>
</a>
</div>
</div>
{% endif %}
<h5 class="terms-title">{{ item.title }}</h5>
{{ item.description }}
</div>
{% endfor %}
</div>
{% endif %}
{% endautoescape %}

@ -1,14 +1,15 @@
{% block content %}
{% autoescape false %}
{% if list_not_category|length > 0 and list_in_category|length > 0 %}
<div class="link-page">
<ul class="list-group mb-3">
<ul class="list-group mb-3">
{% for item in list_not_category %}
<li class="list-group-item">
<h5 class="link-title mb-1">
{{ item.link_validator }}
<a href="{{ item.url }}" class="{{ item.visibility == true ? '' : 'text-muted' }}" target="{{ item.target }}">{{ item.title }}</a>
<a href="{{ item.url }}"
class="{{ item.visibility == true ? '' : 'text-muted' }}"
target="{{ item.target }}">{{ item.title }}</a>
<div class="toolbar">
<div class="btn-group btn-group-sm">
{{ item.toolbar }}
@ -24,7 +25,11 @@
<div class="link-accordion accordion" id="accordion_category">
<div class="card">
<h5 class="card-header" id="heading_{{ item.id }}">
<a class="title-card" href="#" data-toggle="collapse" data-target="#collapse_{{ item.id }}" aria-expanded="true" aria-controls="collapse_{{ item.id }}">
<a class="title-card"
href="#" data-toggle="collapse"
data-target="#collapse_{{ item.id }}"
aria-expanded="true"
aria-controls="collapse_{{ item.id }}">
{{ item.title }}
</a>
<div class="float-right">
@ -33,16 +38,19 @@
</div>
</div>
</h5>
<div id="collapse_{{ item.id }}" class="collapse show" aria-labelledby="heading_{{ item.id }}" data-parent="#accordion_category">
<div id="collapse_{{ item.id }}" class="collapse show"
aria-labelledby="heading_{{ item.id }}"
data-parent="#accordion_category">
<div class="card-body">
{{ item.description }}
<ul class="list-group">
{% for row in item.children %}
<li class="list-group-item list-group-item-action">
<h5 class="link-title mb-1">
{{ row.link_validator }}
<a href="{{ row.url }}" class="{{ row.visibility == true ? '' : 'text-muted' }}" target="{{ row.target }}">{{ row.title }}</a>
<a href="{{ row.url }}"
class="{{ row.visibility == true ? '' : 'text-muted' }}"
target="{{ row.target }}">{{ row.title }}</a>
<div class="toolbar">
<div class="btn-group btn-group-sm">
{{ row.toolbar }}
@ -53,31 +61,16 @@
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% else %}
<div class="alert alert-info" role="alert">
{{ 'There are no registered links'|trans }}
</div>
{% if is_allowed_to_edit %}
<div id="no-data-view" class="tool-view">
<h2>{{ "Links"|trans }}</h2>
<img src="{{ "links.png"|icon(64) }}" width="64" height="64">
<div class="controls">
<a href="{{ web_self ~ "?" ~ _p.web_cid_query ~ "&action=addlink" }}" class="btn btn-outline-primary">
{{ "Add links"|trans }}
</a>
</div>
</div>
{% endif %}
{% endif %}
{% endautoescape %}
{% endblock %}
Loading…
Cancel
Save