Browse Source

Minor - UI changes use Display::panel instead of custom code

Julio Montoya 6 years ago
parent
commit
838b69f507

+ 42 - 0
main/dashboard/block.class.php

@@ -12,10 +12,52 @@
  */
 class Block
 {
+    protected $path;
+
     /**
      * Constructor.
      */
     public function __construct()
     {
     }
+
+    /**
+     * @return string
+     */
+    public function getDeleteLink(): string
+    {
+        global $charset;
+        $closeLink = '<a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(
+                api_htmlentities(
+                    get_lang('ConfirmYourChoice'),
+                    ENT_QUOTES,
+                    $charset
+                )
+            ).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'"> 
+                <em class="fa fa-times"></em>
+            </a>';
+        return $closeLink;
+    }
+
+    /**
+     * @param string $title
+     * @param string $content
+     *
+     * @return string
+     */
+    public function getBlockCard($title, $content): string
+    {
+        $html = Display::panel(
+            $title,
+            $content,
+            '',
+            'default',
+            '',
+            '',
+            '',
+            $this->getDeleteLink()
+        );
+
+        return $html;
+    }
 }

+ 2 - 2
main/inc/lib/dashboard.lib.php

@@ -239,8 +239,8 @@ class DashboardManager
                             $plugin_controller = Database::escape_string($plugin_info['controller']);
                         }
 
-                        $ins = "INSERT INTO $tbl_block(name, description, path, controller)
-                            VALUES ('$plugin_name', '$plugin_description', '$plugin_path', '$plugin_controller')";
+                        $ins = "INSERT INTO $tbl_block(name, description, path, controller, active)
+                               VALUES ('$plugin_name', '$plugin_description', '$plugin_path', '$plugin_controller', 1)";
                         $result = Database::query($ins);
                         $affected_rows = Database::affected_rows($result);
                     }

+ 8 - 4
main/inc/lib/display.lib.php

@@ -2442,6 +2442,7 @@ class Display
      * @param string $extra
      * @param string $id
      * @param string $customColor
+     * @param string $rightAction
      *
      * @return string
      */
@@ -2452,15 +2453,19 @@ class Display
         $type = 'default',
         $extra = '',
         $id = '',
-        $customColor = ''
+        $customColor = '',
+        $rightAction = ''
     ) {
         $headerStyle = '';
         if (!empty($customColor)) {
             $headerStyle = 'style = "color: white; background-color: '.$customColor.'" ';
         }
 
-        //$title = !empty($title) ? '<div class="panel-heading" '.$headerStyle.' ><h3 class="panel-title">'.$title.'</h3>'.$extra.'</div>' : '';
-        $title = !empty($title) ? '<h4 class="card-header">'.$title.'</h4>'.$extra : '';
+        if (!empty($rightAction)) {
+            $rightAction = '<span class="float-right">'.$rightAction.'</span>';
+        }
+
+        $title = !empty($title) ? '<h3 class="card-header">'.$title.' '.$rightAction.'</h3>'.$extra : '';
         $footer = !empty($footer) ? '<div class="card-footer">'.$footer.'</div>' : '';
         $typeList = ['primary', 'success', 'info', 'warning', 'danger'];
         $style = !in_array($type, $typeList) ? 'default' : $type;
@@ -2469,7 +2474,6 @@ class Display
             $id = " id='$id'";
         }
 
-        //<div '.$id.' class="panel panel-'.$style.'">
         return '
             <div '.$id.' class="card">
                 '.$title.'

+ 3 - 1
main/template/default/dashboard/index.html.twig

@@ -1,3 +1,4 @@
+{% autoescape false %}
 {% if blocklist == '' %}
 <div id="columns">
     <div class="row">
@@ -18,4 +19,5 @@
 </div>
 {% else %}
     {{ blocklist }}
-{% endif %}
+{% endif %}
+{% endautoescape %}

+ 8 - 25
plugin/dashboard/block_course/block_course.class.php

@@ -18,7 +18,6 @@ class BlockCourse extends Block
 {
     private $user_id;
     private $courses;
-    private $path;
     private $permission = [DRH];
 
     /**
@@ -65,28 +64,12 @@ class BlockCourse extends Block
      */
     public function get_block()
     {
-        global $charset;
         $column = 2;
         $data = [];
-        $content = $this->get_content_html();
-        $html = '
-		            <div class="panel panel-default" id="intro">
-		                <div class="panel-heading">'.get_lang('CoursesInformation').'
-		                    <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(
-                api_htmlentities(
-                    get_lang('ConfirmYourChoice'),
-                    ENT_QUOTES,
-                    $charset
-                )
-            ).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
-                <em class="fa fa-times"></em>
-                </a></div>
-		                </div>
-		                <div class="panel-body">
-		                   '.$content.'
-		                </div>
-		            </div>
-				';
+        $html = $this->getBlockCard(
+            get_lang('YourCourseList'),
+            $this->getContent()
+        );
         $data['column'] = $column;
         $data['content_html'] = $html;
 
@@ -98,10 +81,10 @@ class BlockCourse extends Block
      *
      * @return string content html
      */
-    public function get_content_html()
+    public function getContent()
     {
         $course_data = $this->get_course_information_data();
-        $content = '<h4>'.get_lang('YourCourseList').'</h4>';
+        $content = '';
         $data_table = null;
         if (!empty($course_data)) {
             $data_table .= '<table class="data_table" width:"95%">';
@@ -134,9 +117,9 @@ class BlockCourse extends Block
         }
         $content .= $data_table;
         if (!empty($course_data)) {
-            $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/course.php?follow">'.get_lang('SeeMore').'</a></div>';
+            $content .= '<div style="text-align:right;margin-top:10px;">
+            <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/course.php?follow">'.get_lang('SeeMore').'</a></div>';
         }
-        //$content .= '</div>';
 
         return $content;
     }

+ 7 - 21
plugin/dashboard/block_daily/block_daily.class.php

@@ -24,7 +24,6 @@ class BlockDaily extends Block
 {
     private $user_id;
     private $courses;
-    private $path;
     private $permission = [DRH];
 
     /**
@@ -72,27 +71,14 @@ class BlockDaily extends Block
      */
     public function get_block()
     {
-        global $charset;
         $column = 2;
         $data = [];
-        $content = $this->get_content_html();
-        $html = '<div class="panel panel-default" id="intro">
-		                <div class="panel-heading">'.get_lang('GradebookAndAttendances').'
-		                    <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(
-                api_htmlentities(
-                    get_lang('ConfirmYourChoice'),
-                    ENT_QUOTES,
-                    $charset
-                )
-            ).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
-                    <em class="fa fa-times"></em>
-                        </a></div>
-		                </div>
-		                <div class="panel-body">
-		                   '.$content.'
-		                </div>
-		            </div>
-				';
+
+        $html = $this->getBlockCard(
+            get_lang('GradebookAndAttendances'),
+            $this->getContent()
+        );
+
         $data['column'] = $column;
         $data['content_html'] = $html;
 
@@ -104,7 +90,7 @@ class BlockDaily extends Block
      *
      * @return string content html
      */
-    public function get_content_html()
+    public function getContent()
     {
         $course_data = $this->get_course_information_data();
         $content = '<h4>'.get_lang('YourCourseList').'</h4>';

+ 6 - 12
plugin/dashboard/block_evaluation_graph/block_evaluation_graph.class.php

@@ -25,7 +25,6 @@ class BlockEvaluationGraph extends Block
     private $user_id;
     private $courses;
     private $sessions;
-    private $path;
     private $permission = [DRH, SESSIONADMIN];
 
     /**
@@ -73,20 +72,12 @@ class BlockEvaluationGraph extends Block
      */
     public function get_block()
     {
-        global $charset;
         $column = 1;
         $data = [];
         $evaluations_base_courses_graph = $this->get_evaluations_base_courses_graph();
         $evaluations_courses_in_sessions_graph = $this->get_evaluations_courses_in_sessions_graph();
 
-        $html = '<div class="panel panel-default" id="intro">
-                    <div class="panel-heading">
-                        '.get_lang('EvaluationsGraph').'
-                        <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
-                        <em class="fa fa-times"></em>
-                        </a></div>
-                    </div>
-                    <div class="panel-body">';
+        $html = '';
         if (empty($evaluations_base_courses_graph) && empty($evaluations_courses_in_sessions_graph)) {
             $html .= '<p>'.api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8').'</p>';
         } else {
@@ -109,8 +100,11 @@ class BlockEvaluationGraph extends Block
                 }
             }
         }
-        $html .= '</div>
-                 </div>';
+
+        $html = $this->getBlockCard(
+            get_lang('EvaluationsGraph'),
+            $html
+        );
 
         $data['column'] = $column;
         $data['content_html'] = $html;

+ 6 - 21
plugin/dashboard/block_global_info/block_global_info.class.php

@@ -23,7 +23,6 @@ class BlockGlobalInfo extends Block
 {
     private $user_id;
     private $courses;
-    private $path;
     private $permission = [];
 
     /**
@@ -35,9 +34,6 @@ class BlockGlobalInfo extends Block
     {
         $this->user_id = $user_id;
         $this->path = 'block_global_info';
-        if ($this->is_block_visible_for_user($user_id)) {
-            //$this->courses = CourseManager::get_courses_followed_by_drh($user_id);
-        }
     }
 
     /**
@@ -68,21 +64,12 @@ class BlockGlobalInfo extends Block
      */
     public function get_block()
     {
-        global $charset;
         $column = 2;
         $data = [];
-        $content = $this->get_content_html();
-        $html = '<div class="panel panel-default" id="intro">
-                    <div class="panel-heading">'.get_lang('GlobalPlatformInformation').'
-                        <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
-                        <em class="fa fa-times"></em>
-                        </a></div>
-                    </div>
-                    <div class="panel-body">
-                       '.$content.'
-                    </div>
-                </div>
-                ';
+        $html = $this->getBlockCard(
+            get_lang('GlobalPlatformInformation'),
+            $this->getContent()
+        );
         $data['column'] = $column;
         $data['content_html'] = $html;
 
@@ -94,10 +81,9 @@ class BlockGlobalInfo extends Block
      *
      * @return string content html
      */
-    public function get_content_html()
+    public function getContent()
     {
         $global_data = $this->get_global_information_data();
-        $content = '<h4>'.get_lang('GlobalPlatformInformation').'</h4>';
         $data_table = null;
         if (!empty($global_data)) {
             $data_table = '<table class="table table-bordered">';
@@ -119,9 +105,8 @@ class BlockGlobalInfo extends Block
         } else {
             $data_table .= get_lang('ThereIsNoInformationAboutThePlatform');
         }
-        $content .= $data_table;
 
-        return $content;
+        return $data_table;
     }
 
     /**

+ 6 - 18
plugin/dashboard/block_session/block_session.class.php

@@ -19,7 +19,6 @@ class BlockSession extends Block
 {
     private $user_id;
     private $sessions;
-    private $path;
     private $permission = [DRH, SESSIONADMIN];
 
     /**
@@ -62,25 +61,15 @@ class BlockSession extends Block
      */
     public function get_block()
     {
-        global $charset;
         $column = 2;
         $data = [];
-        $content = $this->get_content_html();
-        $content_html = '<div class="panel panel-default" id="intro">
-                            <div class="panel-heading">
-                                '.get_lang('SessionsInformation').'
-                                <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
-                                <em class="fa fa-times"></em>
-                                </a></div>
-                            </div>
-                            <div class="panel-body">
-                            '.$content.'
-                            </div>
-                        </div>
-                ';
+        $html = $this->getBlockCard(
+            get_lang('YourSessionsList'),
+            $this->getContent()
+        );
 
         $data['column'] = $column;
-        $data['content_html'] = $content_html;
+        $data['content_html'] = $html;
 
         return $data;
     }
@@ -90,11 +79,10 @@ class BlockSession extends Block
      *
      * @return string content html
      */
-    public function get_content_html()
+    public function getContent()
     {
         $content = '';
         $sessions = $this->sessions;
-        $content .= '<h4>'.get_lang('YourSessionsList').'</h4>';
         if (count($sessions) > 0) {
             $sessions_table = '<table class="data_table" width:"95%">';
             $sessions_table .= '<tr>

+ 6 - 19
plugin/dashboard/block_student/block_student.class.php

@@ -19,7 +19,6 @@ class BlockStudent extends Block
 {
     private $user_id;
     private $students;
-    private $path;
     private $permission = [DRH];
 
     /**
@@ -62,22 +61,12 @@ class BlockStudent extends Block
      */
     public function get_block()
     {
-        global $charset;
         $column = 1;
         $data = [];
-        $student_content_html = $this->get_students_content_html_for_drh();
-        $html = '<div class="panel panel-default" id="intro">
-                    <div class="panel-heading">
-                        '.get_lang('StudentsInformationsList').'
-                        <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
-                            <em class="fa fa-times"></em>
-                        </a>
-                        </div>
-                    </div>
-                    <div class="panel-body">
-                        '.$student_content_html.'
-                    </div>
-                    </div>';
+        $html = $this->getBlockCard(
+            get_lang('YourStudents'),
+            $this->getContent()
+        );
         $data['column'] = $column;
         $data['content_html'] = $html;
 
@@ -89,10 +78,9 @@ class BlockStudent extends Block
      *
      * @return string content html
      */
-    public function get_students_content_html_for_platform_admin()
+    public function getContent()
     {
         $students = $this->students;
-        $content = '<h4>'.get_lang('YourStudents').'</h4>';
         $students_table = null;
         if (count($students) > 0) {
             $students_table .= '<table class="data_table">';
@@ -148,12 +136,11 @@ class BlockStudent extends Block
             $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
         }
 
-        $content .= $students_table;
+        $content = $students_table;
 
         if (count($students) > 0) {
             $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=useroverview">'.get_lang('SeeMore').'</a></div>';
         }
-        //$content .= '</div>';
 
         return $content;
     }

+ 5 - 16
plugin/dashboard/block_student_graph/block_student_graph.class.php

@@ -25,7 +25,6 @@ class BlockStudentGraph extends Block
 {
     private $user_id;
     private $students;
-    private $path;
     private $permission = [DRH];
 
     /**
@@ -72,23 +71,13 @@ class BlockStudentGraph extends Block
      */
     public function get_block()
     {
-        global $charset;
         $column = 1;
         $data = [];
-        $students_attendance_graph = $this->get_students_attendance_graph();
+        $html = $this->getBlockCard(
+            get_lang('StudentsInformationsGraph'),
+            $this->getContent()
+        );
 
-        $html = '<div class="panel panel-default" id="intro">
-                    <div class="panel-heading">
-                        '.get_lang('StudentsInformationsGraph').'
-                        <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
-                        <em class="fa fa-times"></em>
-                        </a></div>
-                    </div>
-                    <div class="panel-body" align="center">
-                        <div style="padding:10px;"><strong>'.get_lang('AttendancesFaults').'</strong></div>
-                        '.$students_attendance_graph.'
-                    </div>
-                </div>';
         $data['column'] = $column;
         $data['content_html'] = $html;
 
@@ -101,7 +90,7 @@ class BlockStudentGraph extends Block
      *
      * @return string img html
      */
-    public function get_students_attendance_graph()
+    public function getContent()
     {
         $students = $this->students;
         $attendance = new Attendance();

+ 9 - 21
plugin/dashboard/block_teacher/block_teacher.class.php

@@ -21,7 +21,6 @@ class BlockTeacher extends Block
 {
     private $user_id;
     private $teachers;
-    private $path;
     private $permission = [DRH];
 
     /**
@@ -65,24 +64,12 @@ class BlockTeacher extends Block
      */
     public function get_block()
     {
-        global $charset;
         $column = 1;
         $data = [];
-        $teacher_content_html = $this->get_teachers_content_html_for_drh();
-        $html = '
-                <div class="panel panel-default" id="intro">
-                    <div class="panel-heading">
-                        '.get_lang('TeachersInformationsList').'
-                        <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
-                        <em class="fa fa-times"></em>
-                        </a></div>
-                    </div>
-                    <div class="panel-body">
-                        '.$teacher_content_html.'
-                    </div>
-                </div>
-                ';
-
+        $html = $this->getBlockCard(
+            get_lang('TeachersInformationsList'),
+            $this->getContent()
+        );
         $data['column'] = $column;
         $data['content_html'] = $html;
 
@@ -95,11 +82,9 @@ class BlockTeacher extends Block
      *
      * @return string content html
      */
-    public function get_teachers_content_html_for_platform_admin()
+    public function getContent()
     {
         $teachers = $this->teachers;
-        $content = '<h4>'.get_lang('YourTeachers').'</h4>';
-
         $teachers_table = null;
         if (count($teachers) > 0) {
             $teachers_table .= '<table class="data_table" width:"95%">';
@@ -139,7 +124,7 @@ class BlockTeacher extends Block
             $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
         }
 
-        $content .= $teachers_table;
+        $content = $teachers_table;
 
         if (count($teachers) > 0) {
             $content .= '<div style="text-align:right;margin-top:10px;">
@@ -149,6 +134,9 @@ class BlockTeacher extends Block
         return $content;
     }
 
+    /**
+     * @return string
+     */
     public function get_teachers_content_html_for_drh()
     {
         $teachers = $this->teachers;

+ 13 - 21
plugin/dashboard/block_teacher_graph/block_teacher_graph.class.php

@@ -1,4 +1,9 @@
 <?php
+
+use CpChart\Cache as pCache;
+use CpChart\Data as pData;
+use CpChart\Image as pImage;
+
 /**
  * This file is part of teacher graph block plugin for dashboard,
  * it should be required inside dashboard controller for showing it into dashboard interface from plattform.
@@ -11,13 +16,12 @@
 /**
  * required files for getting data.
  */
-use CpChart\Cache as pCache;
-use CpChart\Data as pData;
-use CpChart\Image as pImage;
+
 
 /**
  * This class is used like controller for teacher graph block plugin,
- * the class name must be registered inside path.info file (e.g: controller = "BlockTeacherGraph"), so dashboard controller will be instantiate it.
+ * the class name must be registered inside path.info file (e.g: controller = "BlockTeacherGraph"),
+ * so dashboard controller will be instantiate it.
  *
  * @package chamilo.dashboard
  */
@@ -25,7 +29,6 @@ class BlockTeacherGraph extends Block
 {
     private $user_id;
     private $teachers;
-    private $path;
     private $permission = [DRH];
 
     /**
@@ -67,23 +70,12 @@ class BlockTeacherGraph extends Block
      */
     public function get_block()
     {
-        global $charset;
         $column = 1;
         $data = [];
-        $teacher_information_graph = $this->get_teachers_information_graph();
-        $html = '
-                <div class="panel panel-default" id="intro">
-                    <div class="panel-heading">'.get_lang('TeachersInformationsGraph').'
-                        <div class="pull-right"><a class="btn btn-danger btn-xs"  onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
-                        <em class="fa fa-times"></em>
-                        </a></div>
-                    </div>
-                    <div class="panel-body" align="center">
-                        <div style="padding:10px;"><strong>'.get_lang('TimeSpentOnThePlatformLastWeekByDay').'</strong></div>
-                        '.$teacher_information_graph.'
-                    </div>
-                </div>
-                ';
+        $html = $this->getBlockCard(
+            get_lang('TeachersInformationsGraph'),
+            $this->getContent()
+        );
 
         $data['column'] = $column;
         $data['content_html'] = $html;
@@ -96,7 +88,7 @@ class BlockTeacherGraph extends Block
      *
      * @return string content html
      */
-    public function get_teachers_information_graph()
+    public function getContent()
     {
         $teachers = $this->teachers;
         $graph = '';

+ 14 - 10
src/CoreBundle/Resources/views/Admin/switcher_links.html.twig

@@ -1,22 +1,26 @@
-<div class="btn-group">
-    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
+<div class="btn-group" role="group">
+    <button
+        type="button"
+        class="btn btn-secondary dropdown-toggle"
+        data-toggle="dropdown"
+        aria-haspopup="true"
+        aria-expanded="false"
+    >
         <span class="flag-icon flag-icon-{{ current_locale_iso }}"></span>
         {{ current_locale_iso }}
         <span class="caret">
         </span>
     </button>
-    <ul class="dropdown-menu" role="menu">
+    <div class="dropdown-menu" role="menu">
         {% autoescape false %}
             {% for index, locale in available_locales %}
-                <li>
-                    <a href="{{ app.request.attributes.get('_route') }}?_locale={{ index }}">
-                        <span class="flag-icon flag-icon-{{ index }}"></span>
-                        {{ locale }}
-                    </a>
-                </li>
+                <a class="dropdown-item" href="{{ app.request.attributes.get('_route') }}?_locale={{ index }}">
+                    <span class="flag-icon flag-icon-{{ index }}"></span>
+                    {{ locale }}
+                </a>
             {% endfor %}
         {% endautoescape %}
-    </ul>
+    </div>
 </div>