Browse Source

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

Yannick Warnier 7 years ago
parent
commit
4a170f4957

+ 1 - 0
main/inc/lib/api.lib.php

@@ -109,6 +109,7 @@ define('TOOL_LINK_CATEGORY', 'link_category');
 define('TOOL_COURSE_DESCRIPTION', 'course_description');
 define('TOOL_SEARCH', 'search');
 define('TOOL_LEARNPATH', 'learnpath');
+define('TOOL_LEARNPATH_CATEGORY', 'learnpath_category');
 define('TOOL_AGENDA', 'agenda');
 define('TOOL_ANNOUNCEMENT', 'announcement');
 define('TOOL_FORUM', 'forum');

+ 32 - 0
main/lp/learnpath.class.php

@@ -4124,6 +4124,38 @@ class learnpath
         );
     }
 
+    /**
+     * Publishes a learnpath category.
+     * This basically means show or hide the learnpath category to normal users.
+     * @param int $id
+     * @param int $visibility
+     * @return bool
+     */
+    public static function toggleCategoryVisibility($id, $visibility = 1)
+    {
+        $action = 'visible';
+
+        if ($visibility != 1) {
+            $action = 'invisible';
+
+            $list = new LearnpathList(api_get_user_id(), null, null, null, false, $id);
+
+            $learPaths = $list->get_flat_list();
+
+            foreach ($learPaths as $lp) {
+                learnpath::toggle_visibility($lp['iid'], 0);
+            }
+        }
+
+        return api_item_property_update(
+            api_get_course_info(),
+            TOOL_LEARNPATH_CATEGORY,
+            $id,
+            $action,
+            api_get_user_id()
+        );
+    }
+
     /**
      * Publishes a learnpath. This basically means show or hide the learnpath
      * on the course homepage

+ 9 - 0
main/lp/lp_controller.php

@@ -850,6 +850,15 @@ switch ($action) {
             require 'lp_list.php';
         }
         break;
+    case 'toggle_category_visibility':
+        if (!$is_allowed_to_edit) {
+            api_not_allowed(true);
+        }
+
+        learnpath::toggleCategoryVisibility($_REQUEST['id'], $_REQUEST['new_status']);
+
+        header('Location: '.api_get_self().'?'.api_get_cidreq());
+        exit;
     case 'toggle_visible':
         // Change lp visibility (inside lp tool).
         if (!$is_allowed_to_edit) {

+ 14 - 4
main/lp/lp_list.php

@@ -84,10 +84,14 @@ if ($is_allowed_to_edit) {
         }
     }
     $actionLeft = null;
-    $actionLeft .= Display::url(
-        Display::return_icon('new_folder.png', get_lang('AddCategory'), array(), ICON_SIZE_MEDIUM),
-        api_get_self().'?'.api_get_cidreq().'&action=add_lp_category'
-    );
+
+    if (!$current_session) {
+        $actionLeft .= Display::url(
+            Display::return_icon('new_folder.png', get_lang('AddCategory'), array(), ICON_SIZE_MEDIUM),
+            api_get_self().'?'.api_get_cidreq().'&action=add_lp_category'
+        );
+    }
+
     $actionLeft .= Display::url(
         Display::return_icon('new_learnpath.png', get_lang('LearnpathAddLearnpath'), '', ICON_SIZE_MEDIUM),
         api_get_self().'?'.api_get_cidreq().'&action=add_lp'
@@ -833,6 +837,12 @@ foreach ($categories as $item) {
 
     $data[] = [
         'category' => $item,
+        'category_visibility' => api_get_item_visibility(
+            $courseInfo,
+            TOOL_LEARNPATH_CATEGORY,
+            $item->getId(),
+            $current_session
+        ),
         'lp_list' => $listData
     ];
 }

+ 51 - 43
main/template/default/learnpath/list.tpl

@@ -11,57 +11,65 @@
 {{ introduction_section }}
 
 {% for lp_data in data %}
-    <h3 class="page-header">
+    {% if categories|length > 1 and lp_data.category.id %}
         {% if is_allowed_to_edit %}
-            {% if (categories|length) > 1 %}
+            <h3 class="page-header">
                 {{ lp_data.category.getName() }}
-            {% endif %}
-        {% else %}
-            {% if (categories|length) > 1 %}
-                {% if lp_data.lp_list is not empty and lp_data.category.getId() != 0 %}
-                    {{ lp_data.category.getName() }}
-                {% elseif lp_data.lp_list is not empty and lp_data.category.getId() == 0 %}
-                    {{ lp_data.category.getName() }}
-                {% elseif lp_data.lp_list is not empty and lp_data.category.getId() != 0 %}
-                    {{ lp_data.category.getName() }}
-                {% endif %}
-            {% endif %}
-        {% endif %}
 
-        {% if lp_data.category.getId() > 0 and is_allowed_to_edit %}
-            <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=add_lp_category&id=' ~ lp_data.category.getId() }}" title="{{ "Edit"|get_lang }}">
-                <img src="{{ "edit.png"|icon }}" alt="{{ "Edit"|get_lang }}">
-            </a>
+                {% if lp_data.category.getId() > 0 %}
+                    {% if not _c.session_id %}
+                        <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=add_lp_category&id=' ~ lp_data.category.getId() }}" title="{{ "Edit"|get_lang }}">
+                            <img src="{{ "edit.png"|icon }}" alt="{{ "Edit"|get_lang }}">
+                        </a>
 
-            <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=add_users_to_category&id=' ~ lp_data.category.getId() }}" title="{{ "AddUser"|get_lang }}">
-                <img src="{{ "user.png"|icon }}" alt="{{ "AddUser"|get_lang }}">
-            </a>
+                        <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=add_users_to_category&id=' ~ lp_data.category.getId() }}" title="{{ "AddUser"|get_lang }}">
+                            <img src="{{ "user.png"|icon }}" alt="{{ "AddUser"|get_lang }}">
+                        </a>
+
+                        {% if loop.index0 == 1 %}
+                            <a href="#">
+                                <img src="{{ "up_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
+                            </a>
+                        {% else %}
+                            <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=move_up_category&id=' ~ lp_data.category.getId() }}" title="{{ "Move"|get_lang }}">
+                                <img src="{{ "up.png"|icon }}" alt="{{ "Move"|get_lang }}">
+                            </a>
+                        {% endif %}
 
-            {% if loop.index0 == 1 %}
-                <a href="#">
-                    <img src="{{ "up_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
-                </a>
-            {% else %}
-                <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=move_up_category&id=' ~ lp_data.category.getId() }}" title="{{ "Move"|get_lang }}">
-                    <img src="{{ "up.png"|icon }}" alt="{{ "Move"|get_lang }}">
-                </a>
-            {% endif %}
+                        {% if (data|length - 1) == loop.index0 %}
+                            <a href="#">
+                                <img src="{{ "down_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
+                            </a>
+                        {% else %}
+                            <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=move_down_category&id=' ~ lp_data.category.getId() }}" title="{{ "Move"|get_lang }}">
+                                <img src="{{ "down.png"|icon }}" alt="{{ "Move"|get_lang }}">
+                            </a>
+                        {% endif %}
+                    {% endif %}
 
-            {% if (data|length - 1) == loop.index0 %}
-                <a href="#">
-                    <img src="{{ "down_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
-                </a>
-            {% else %}
-                <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=move_down_category&id=' ~ lp_data.category.getId() }}" title="{{ "Move"|get_lang }}">
-                    <img src="{{ "down.png"|icon }}" alt="{{ "Move"|get_lang }}">
-                </a>
-            {% endif %}
+                    {% if lp_data.category_visibility == 0 %}
+                        <a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_visibility', 'id':lp_data.category.id, 'new_status':1}|url_encode }}"
+                           title="{{ 'Show'|get_lang }}">
+                            <img src="{{ 'invisible.png'|icon }}" alt="{{ 'Show'|get_lang }}">
+                        </a>
+                    {% else %}
+                        <a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_visibility', 'id':lp_data.category.id, 'new_status':0}|url_encode }}"
+                           title="{{ 'Hide'|get_lang }}">
+                            <img src="{{ 'visible.png'|icon }}" alt="{{ 'Hide'|get_lang }}">
+                        </a>
+                    {% endif %}
 
-            <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query  ~ '&action=delete_lp_category&id=' ~ lp_data.category.getId() }}" title="{{ "Delete"|get_lang }}">
-                <img src="{{ "delete.png"|icon }}" alt="{{ "Delete"|get_lang }}">
-            </a>
+                    {% if not _c.session_id %}
+                        <a href="{{ 'lp_controller.php?' ~ _p.web_cid_query  ~ '&action=delete_lp_category&id=' ~ lp_data.category.getId() }}" title="{{ "Delete"|get_lang }}">
+                            <img src="{{ "delete.png"|icon }}" alt="{{ "Delete"|get_lang }}">
+                        </a>
+                    {% endif %}
+                {% endif %}
+            </h3>
+        {% elseif lp_data.lp_list is not empty %}
+            <h3 class="page-header">{{ lp_data.category.getName() }}</h3>
         {% endif %}
-    </h3>
+    {% endif %}
 
     {% if lp_data.lp_list %}
         <div class="table-responsive">