From 0d7afc280ad7cd26ba32a423c8c3b042fe3b73d8 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 5 May 2021 10:56:54 +0200 Subject: [PATCH] Move no-data-view block code in a function --- public/main/announcements/announcements.php | 13 ++-- public/main/course_progress/index.php | 11 ++++ public/main/exercise/exercise.class.php | 15 ++--- public/main/glossary/index.php | 3 +- public/main/inc/lib/display.lib.php | 17 +++++ public/main/inc/lib/glossary.lib.php | 63 ++++++++++--------- public/main/inc/lib/link.lib.php | 20 ++++-- public/main/link/link.php | 1 - .../course_progress/progress.html.twig | 15 +---- .../template/default/glossary/list.html.twig | 55 +++++++--------- .../template/default/link/index.html.twig | 37 +++++------ 11 files changed, 124 insertions(+), 126 deletions(-) diff --git a/public/main/announcements/announcements.php b/public/main/announcements/announcements.php index 7fea8de2ef..c544d10c37 100644 --- a/public/main/announcements/announcements.php +++ b/public/main/announcements/announcements.php @@ -288,17 +288,12 @@ switch ($action) { if (($allowToEdit || $allowStudentInGroupToSend) && (empty($_GET['origin']) || 'learnpath' !== $_GET['origin']) ) { - $html .= '
'; - $html .= '

'.get_lang('Announcements').'

'; - $html .= Display::return_icon('valves.png', '', [], 64); - $html .= '
'; - $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 .= '
'; - $html .= '
'; } else { $html = Display::return_message(get_lang('There are no announcements.'), 'warning'); } diff --git a/public/main/course_progress/index.php b/public/main/course_progress/index.php index 0b14f3266a..56bc3e33e5 100644 --- a/public/main/course_progress/index.php +++ b/public/main/course_progress/index.php @@ -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; diff --git a/public/main/exercise/exercise.class.php b/public/main/exercise/exercise.class.php index bbffe976ac..c2cdfc2cd9 100644 --- a/public/main/exercise/exercise.class.php +++ b/public/main/exercise/exercise.class.php @@ -9483,17 +9483,12 @@ class Exercise if (empty($tableRows) && empty($categoryId)) { if ($is_allowedToEdit && 'learnpath' !== $origin) { - $content .= '
'; - $content .= '

'.get_lang('Quiz').'

'; - $content .= Display::return_icon('quiz.png', '', [], 64); - $content .= '
'; - $content .= Display::url( - ' '.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 .= '
'; - $content .= '
'; } } else { if (empty($tableRows)) { diff --git a/public/main/glossary/index.php b/public/main/glossary/index.php index 2c5a8204a8..acaf17dfe3 100644 --- a/public/main/glossary/index.php +++ b/public/main/glossary/index.php @@ -467,7 +467,7 @@ switch ($action) { break; default: $tool_name = get_lang('List'); - $htmlHeadXtra[] = ''; + $htmlHeadXtra[] = ''; $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; diff --git a/public/main/inc/lib/display.lib.php b/public/main/inc/lib/display.lib.php index 8975b65e4c..d50f212949 100644 --- a/public/main/inc/lib/display.lib.php +++ b/public/main/inc/lib/display.lib.php @@ -2934,4 +2934,21 @@ HTML; return $result; // example: #fc443a } } + + public static function noDataView(string $title, string $icon, string $buttonTitle, string $url): string + { + $content = '
'; + $content .= '

'.$title.'

'; + $content .= $icon; + $content .= '
'; + $content .= self::url( + ' '.$buttonTitle, + $url, + ['class' => 'btn btn-primary'] + ); + $content .= '
'; + $content .= '
'; + + return $content; + } } diff --git a/public/main/inc/lib/glossary.lib.php b/public/main/inc/lib/glossary.lib.php index 119beadffd..d1237d3afc 100644 --- a/public/main/inc/lib/glossary.lib.php +++ b/public/main/inc/lib/glossary.lib.php @@ -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 .= ''.$addIcon.''; + $actionsLeft .= ''.$addIcon.''; } 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 = '
'. diff --git a/public/main/inc/lib/link.lib.php b/public/main/inc/lib/link.lib.php index 4220a2d99e..fc12c20c4c 100644 --- a/public/main/inc/lib/link.lib.php +++ b/public/main/inc/lib/link.lib.php @@ -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 .= ''. + $actions .= ''. Display::return_icon('new_link.png', get_lang('Add a link'), '', ICON_SIZE_MEDIUM).''; - $actions .= ''. + $actions .= ''. Display::return_icon('new_folder.png', get_lang('Add a category'), '', ICON_SIZE_MEDIUM).''; } @@ -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 .= ''; + 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()).''; @@ -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; } diff --git a/public/main/link/link.php b/public/main/link/link.php index a8c8e1e365..8392a51d68 100644 --- a/public/main/link/link.php +++ b/public/main/link/link.php @@ -67,7 +67,6 @@ if ('editlink' === $action) { $interbreadcrumb[] = ['url' => 'link.php', 'name' => get_lang('Links')]; } -// Statistics Event::event_access_tool(TOOL_LINK); /* Action Handling */ diff --git a/public/main/template/default/course_progress/progress.html.twig b/public/main/template/default/course_progress/progress.html.twig index 3295ec5977..7d6a287f95 100644 --- a/public/main/template/default/course_progress/progress.html.twig +++ b/public/main/template/default/course_progress/progress.html.twig @@ -191,19 +191,10 @@
{% else %} - {% if is_allowed_to_edit %} -
-

{{ "Educational programming"|trans }}

- - -
+ {{ no_data }} + {% else %} + {% endif %} {% endif %} {% endautoescape %} \ No newline at end of file diff --git a/public/main/template/default/glossary/list.html.twig b/public/main/template/default/glossary/list.html.twig index 29d649cea6..73e00fbe62 100644 --- a/public/main/template/default/glossary/list.html.twig +++ b/public/main/template/default/glossary/list.html.twig @@ -1,39 +1,26 @@ {% autoescape false %} -{% if data is empty %} - - - {% if is_allowed_to_edit %} -
-

{{ "Glossary"|trans }}

- -
- - {{ "Add glossary"|trans }} - + {% if data is not empty %} +
+ {% for item in data %} +
+ {% if item.edit %} +
+ +
+ {% endif %} +
{{ item.title }}
+ {{ item.description }}
+ {% endfor %}
{% endif %} - -{% else %} -
- {% for item in data %} -
- {% if item.edit %} -
- -
- {% endif %} -
{{ item.title }}
- {{ item.description }} -
- {% endfor %} -
-{% endif %} {% endautoescape %} \ No newline at end of file diff --git a/public/main/template/default/link/index.html.twig b/public/main/template/default/link/index.html.twig index 7aa2d0a34d..d5a2651dee 100644 --- a/public/main/template/default/link/index.html.twig +++ b/public/main/template/default/link/index.html.twig @@ -1,14 +1,15 @@ {% block content %} {% autoescape false %} {% if list_not_category|length > 0 and list_in_category|length > 0 %} - {% endfor %}
- {% else %} - - {% if is_allowed_to_edit %} -
-

{{ "Links"|trans }}

- - -
- {% endif %} - {% endif %} {% endautoescape %} {% endblock %} \ No newline at end of file