Browse Source

Improve UI

jmontoyaa 7 years ago
parent
commit
c56513c41b

+ 13 - 3
main/admin/gradebook_dependency.php

@@ -27,6 +27,7 @@ if (!$category) {
 $categoryObj = Category::load($categoryId);
 /** @var Category $categoryObj */
 $categoryObj = $categoryObj[0];
+
 $dependencies = $categoryObj->getCourseListDependency();
 
 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
@@ -48,12 +49,20 @@ if (empty($dependencies)) {
 
 $content = '';
 $courseList = [];
+
+/*$mandatoryList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
+$mandatoryList = isset($mandatoryList['courses']) ? $mandatoryList['courses'] : [];*/
+
 foreach ($dependencies as $courseId) {
     $courseInfo = api_get_course_info_by_id($courseId);
-    $subCategory = Category::load(null, null, $courseInfo['code']);
+    $courseCode = $courseInfo['code'];
+    $subCategory = Category::load(null, null, $courseCode);
     /** @var Category $subCategory */
-    $subCategory = $subCategory[0];
-    $userList = CourseManager::get_student_list_from_course_code($courseInfo['code']);
+    $subCategory = $subCategory ? $subCategory[0] : [];
+    if (empty($subCategory)) {
+        continue;
+    }
+    $userList = CourseManager::get_student_list_from_course_code($courseCode);
     $users = [];
     foreach ($userList as $user) {
         $userInfo = api_get_user_info($user['user_id']);
@@ -66,6 +75,7 @@ foreach ($dependencies as $courseId) {
         $users[] = $userInfo;
     }
     $courseInfo['users'] = $users;
+    //$courseInfo['is_mandatory'] = in_array($courseCode, $mandatoryList);
     $courseList[] = $courseInfo;
 }
 

+ 41 - 25
main/admin/gradebook_list.php

@@ -39,8 +39,19 @@ $currentUrl = api_get_self().'?';
 $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
 $contentForm = '';
 
+$toolbar = Display::url(
+    Display::return_icon('add.png', get_lang('Add'), [], ICON_SIZE_MEDIUM),
+    $currentUrl.'&action=add'
+);
+
+$tpl = new Template(get_lang('Gradebook'));
+
 switch ($action) {
     case 'add':
+        $toolbar = Display::url(
+            Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
+            $currentUrl
+        );
         $form = new FormValidator(
             'category_add',
             'post',
@@ -127,6 +138,10 @@ switch ($action) {
         }
         break;
     case 'edit':
+        $toolbar = Display::url(
+            Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
+            $currentUrl
+        );
         /** @var GradebookCategory $category */
         $category = $repo->find($categoryId);
         if (!empty($category)) {
@@ -209,23 +224,31 @@ switch ($action) {
             }
         }
         break;
-}
+    case 'list':
+    default:
+        $paginator = new Paginator();
+        $pagination = $paginator->paginate(
+            $gradeBookList,
+            $page,
+            5
+        );
 
-$paginator = new Paginator;
-$pagination = $paginator->paginate(
-    $gradeBookList,
-    $page,
-    5
-);
+        // pagination.tpl needs current_url with out "page" param
+        $pagination->setCustomParameters(['current_url' => $currentUrl]);
 
-// pagination.tpl needs current_url with out "page" param
-$pagination->setCustomParameters(['current_url' => $currentUrl]);
 
-$tpl = new Template(get_lang('Gradebook'));
-$toolbar = Display::url(
-    Display::return_icon('add.png', get_lang('Add'), [], ICON_SIZE_MEDIUM),
-    $currentUrl.'&action=add'
-);
+        $pagination->renderer = function ($data) use ($tpl) {
+            foreach ($data as $key => $value) {
+                $tpl->assign($key, $value);
+            }
+            $layout = $tpl->get_template('admin/pagination.tpl');
+            $content = $tpl->fetch($layout);
+
+            return $content;
+        };
+
+        break;
+}
 
 $searchForm = new FormValidator(
     'course_filter',
@@ -238,16 +261,6 @@ $searchForm = new FormValidator(
 $searchForm->addText('keyword', '', false);
 $searchForm->addButtonSearch(get_lang('Search'));
 
-$pagination->renderer = function ($data) use ($tpl) {
-    foreach ($data as $key => $value) {
-        $tpl->assign($key, $value);
-    }
-    $layout = $tpl->get_template('admin/pagination.tpl');
-    $content = $tpl->fetch($layout);
-
-    return $content;
-};
-
 $tpl->assign('current_url', $currentUrl);
 $tpl->assign(
     'actions',
@@ -257,7 +270,10 @@ $tpl->assign(
         [1, 4]
     )
 );
+
 $tpl->assign('form', $contentForm);
-$tpl->assign('gradebook_list', $pagination);
+if (!empty($pagination)) {
+    $tpl->assign('gradebook_list', $pagination);
+}
 $layout = $tpl->get_template('admin/gradebook_list.tpl');
 $tpl->display($layout);

+ 3 - 1
main/template/default/admin/gradebook_dependency.tpl

@@ -2,7 +2,9 @@
 
 {% block content %}
     {% for course in courses %}
-        <h3>{{ course.title }} ({{ course.code }})</h3>
+        <h3>
+            {{ course.title }} ({{ course.code }})
+        </h3>
 
         {% if course.users %}
             <table class="table">

+ 29 - 26
main/template/default/admin/gradebook_list.tpl

@@ -2,33 +2,36 @@
 
 {% block content %}
     {{ form }}
-    <table class="table">
-        <thead class="title">
+
+    {% if gradebook_list %}
+        <table class="table">
+            <thead class="title">
+                <tr>
+                    <th>{{ 'Name' | get_lang }}</th>
+                    <th>{{ 'Course' | get_lang }}</th>
+                    <th>{{ 'Actions' | get_lang }} </th>
+                </tr>
+            </thead>
+        {% for item in gradebook_list %}
             <tr>
-                <th>{{ 'Name' | get_lang }}</th>
-                <th>{{ 'Course' | get_lang }}</th>
-                <th>{{ 'Actions' | get_lang }} </th>
+                <td>
+                    {{ item.name }}
+                </td>
+                <td>
+                    {{ item.courseCode }}
+                </td>
+                <td>
+                    <a href="{{ current_url }}&action=edit&id={{ item.id }}">
+                        <img src="{{ 'edit.png'|icon(22) }}" />
+                    </a>
+                    <a href="{{ _p.web_main }}admin/gradebook_dependency.php?id={{ item.id }}">
+                        <img src="{{ '2rightarrow.png'|icon(22) }}" />
+                    </a>
+                </td>
             </tr>
-        </thead>
-    {% for item in gradebook_list %}
-        <tr>
-            <td>
-                {{ item.name }}
-            </td>
-            <td>
-                {{ item.courseCode }}
-            </td>
-            <td>
-                <a href="{{ current_url }}&action=edit&id={{ item.id }}">
-                    <img src="{{ 'edit.png'|icon(22) }}" />
-                </a>
-                <a href="{{ _p.web_main }}admin/gradebook_dependency.php?id={{ item.id }}">
-                    <img src="{{ '2rightarrow.png'|icon(22) }}" />
-                </a>
-            </td>
-        </tr>
-    {% endfor %}
-    </table>
+        {% endfor %}
+        </table>
 
-   {{ gradebook_list }}
+       {{ gradebook_list }}
+    {% endif %}
 {% endblock %}