Răsfoiți Sursa

Remove use of app_view and View class, use Template class.

- Remove unused layout.php and dashboard.php
- Remove unused classes inside block.class.php
jmontoyaa 7 ani în urmă
părinte
comite
179959c10e

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

@@ -16,25 +16,4 @@ class Block
     public function __construct()
     {
     }
-
-    /**
-     * Display small blocks, @todo it will be implemented for next version
-     */
-    public function display_small()
-    {
-    }
-
-    /**
-     * Display larges blocks, @todo it will be implemented for next version
-     */
-    public function display_large()
-    {
-    }
-
-    public function get_block_path()
-    {
-        $result = get_class($this);
-
-        return $result;
-    }
 }

+ 0 - 96
main/dashboard/dashboard.php

@@ -1,96 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-/**
-* Template (view in MVC pattern) used for displaying blocks for dashboard
-* @author Christian Fasanando <christian1827@gmail.com>
-* @package chamilo.dashboard
-*/
-
-// protect script
-api_block_anonymous_users();
-
-// menu actions for dashboard views
-$views = array('blocks', 'list');
-
-if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
-    $dashboard_view = $_GET['view'];
-}
-
-$link_blocks_view = $link_list_view = null;
-
-if (isset($dashboard_view) && $dashboard_view == 'list') {
-    $link_blocks_view = '<a href="'.api_get_self().'?view=blocks">'.
-        Display::return_icon('blocks.png', get_lang('DashboardBlocks'), '', ICON_SIZE_MEDIUM).'</a>';
-} else {
-    $link_list_view = '<a href="'.api_get_self().'?view=list">'.
-        Display::return_icon('edit.png', get_lang('EditBlocks'), '', ICON_SIZE_MEDIUM).'</a>';
-}
-
-$configuration_link = null;
-if (api_is_platform_admin()) {
-    $configuration_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'
-    .Display::return_icon('settings.png', get_lang('ConfigureDashboardPlugin'), '', ICON_SIZE_MEDIUM).'</a>';
-}
-
-echo '<div class="actions">';
-echo $link_blocks_view.$link_list_view.$configuration_link;
-echo '</div>';
-
-// block dashboard view
-if (isset($dashboard_view) && $dashboard_view == 'blocks') {
-    if (isset($blocks) && count($blocks) > 0) {
-        $columns = array();
-        // group content html by number of column
-        if (is_array($blocks)) {
-            $tmp_columns = array();
-            foreach ($blocks as $block) {
-                $tmp_columns[] = $block['column'];
-                if (in_array($block['column'], $tmp_columns)) {
-                    $columns['column_'.$block['column']][] = $block['content_html'];
-                }
-            }
-        }
-
-        echo '<div id="columns" class="row">';
-        if (count($columns) > 0) {
-            $columns_name = array_keys($columns);
-            // blocks for column 1
-            if (in_array('column_1', $columns_name)) {
-                echo '<div id="column1" class="col-md-6">';
-                foreach ($columns['column_1'] as $content) {
-                    echo $content;
-                }
-                echo '</div>';
-            } else {
-                echo '<div id="column1" class="col-md-6">';
-                echo '&nbsp;';
-                echo '</div>';
-            }
-            // blocks for column 2
-            if (in_array('column_2', $columns_name)) {
-                // blocks for column 1
-                echo '<div id="column2" class="col-md-6">';
-                foreach ($columns['column_2'] as $content) {
-                    echo $content;
-                }
-                echo '</div>';
-            } else {
-                echo '<div id="column2" class="col-md-6">';
-                echo '&nbsp;';
-                echo '</div>';
-            }
-        }
-        echo '</div>';
-    } else {
-        echo '<div style="margin-top:20px;">'.get_lang('YouHaveNotEnabledBlocks').'</div>';
-    }
-
-} else {
-    // block dashboard list
-    if (isset($success)) {
-        echo Display::return_message(get_lang('BlocksHaveBeenUpdatedSuccessfully'), 'confirm');
-    }
-    $user_id = api_get_user_id();
-    DashboardManager::display_user_dashboard_list($user_id);
-}

+ 90 - 41
main/dashboard/dashboard_controller.php

@@ -5,16 +5,12 @@
  * Controller script. Prepares the common background
  * variables to give to the scripts corresponding to
  * the requested action
- * This file contains class used like controller,
- * it should be included inside a dispatcher file (e.g: index.php)
  * @author Christian Fasanando <christian1827@gmail.com>
  * @todo move to main/inc/lib
  * @package chamilo.dashboard
  */
 class DashboardController
 {
-    private $toolname;
-    private $view;
     private $user_id;
 
     /**
@@ -23,8 +19,6 @@ class DashboardController
     public function __construct()
     {
         $this->user_id = api_get_user_id();
-        $this->toolname = 'dashboard';
-        $this->view = new View($this->toolname);
     }
 
     /**
@@ -32,18 +26,13 @@ class DashboardController
      * @param string $msg (optional)
      * render to dashboard.php view
      */
-    public function display($msg = false)
+    public function display()
     {
-        $data = array();
         $user_id = $this->user_id;
-
-        $block_data_without_plugin = DashboardManager::get_block_data_without_plugin();
         $dashboard_blocks = DashboardManager::get_enabled_dashboard_blocks();
         $user_block_data  = DashboardManager::get_user_block_data($user_id);
         $user_blocks_id = array_keys($user_block_data);
-
-        $data_block = null;
-
+        $blocks = null;
         if (!empty($dashboard_blocks)) {
             foreach ($dashboard_blocks as $block) {
                 // display only user blocks
@@ -67,25 +56,94 @@ class DashboardController
                         }
                     }
 
-                    $data_block[$path] = $obj->get_block();
+                    $blocks[$path] = $obj->get_block();
                     // set user block column
-                    $data_block[$path]['column'] = $user_block_data[$block['id']]['column'];
+                    $blocks[$path]['column'] = $user_block_data[$block['id']]['column'];
                 }
             }
+        }
+
+        $view = isset($_GET['view']) ? $_GET['view'] : 'blocks';
+        api_block_anonymous_users();
+        $link_blocks_view = $link_list_view = null;
+        if ($view == 'list') {
+            $link_blocks_view = '<a href="'.api_get_self().'?view=blocks">'.
+                Display::return_icon('blocks.png', get_lang('DashboardBlocks'), '', ICON_SIZE_MEDIUM).'</a>';
+        } else {
+            $link_list_view = '<a href="'.api_get_self().'?view=list">'.
+                Display::return_icon('edit.png', get_lang('EditBlocks'), '', ICON_SIZE_MEDIUM).'</a>';
+        }
 
-            $data['blocks'] = $data_block;
-            $data['dashboard_view'] = 'blocks';
+        $configuration_link = null;
+        if (api_is_platform_admin()) {
+            $configuration_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'
+                .Display::return_icon('settings.png', get_lang('ConfigureDashboardPlugin'), '', ICON_SIZE_MEDIUM).'</a>';
         }
 
-        if ($msg) {
-            $data['msg'] = $msg;
+        $content = '<div class="actions">';
+        $content .= $link_blocks_view.$link_list_view.$configuration_link;
+        $content .= '</div>';
+
+        // block dashboard view
+        if (isset($view) && $view == 'blocks') {
+            if (isset($blocks) && count($blocks) > 0) {
+                $columns = array();
+                // group content html by number of column
+                if (is_array($blocks)) {
+                    $tmp_columns = array();
+                    foreach ($blocks as $block) {
+                        $tmp_columns[] = $block['column'];
+                        if (in_array($block['column'], $tmp_columns)) {
+                            $columns['column_'.$block['column']][] = $block['content_html'];
+                        }
+                    }
+                }
+
+                $content .= '<div id="columns" class="row">';
+                if (count($columns) > 0) {
+                    $columns_name = array_keys($columns);
+                    // blocks for column 1
+                    if (in_array('column_1', $columns_name)) {
+                        $content .= '<div id="column1" class="col-md-6">';
+                        foreach ($columns['column_1'] as $data) {
+                            $content .= $data;
+                        }
+                        $content .= '</div>';
+                    } else {
+                        $content .= '<div id="column1" class="col-md-6">';
+                        $content .= '&nbsp;';
+                        $content .= '</div>';
+                    }
+                    // blocks for column 2
+                    if (in_array('column_2', $columns_name)) {
+                        // blocks for column 1
+                        $content .= '<div id="column2" class="col-md-6">';
+                        foreach ($columns['column_2'] as $data) {
+                            $content .= $data;
+                        }
+                        $content .= '</div>';
+                    } else {
+                        $content .= '<div id="column2" class="col-md-6">';
+                        $content .= '&nbsp;';
+                        $content .= '</div>';
+                    }
+                }
+                $content .= '</div>';
+            } else {
+                $content .= '<div style="margin-top:20px;">'.get_lang('YouHaveNotEnabledBlocks').'</div>';
+            }
+        } else {
+            // block dashboard list
+            if (isset($success)) {
+                Display::addFlash(Display::return_message(get_lang('BlocksHaveBeenUpdatedSuccessfully'), 'confirm'));
+            }
+            $user_id = api_get_user_id();
+            $content .= DashboardManager::display_user_dashboard_list($user_id);
         }
 
-        // render to the view
-        $this->view->set_data($data);
-        $this->view->set_layout('layout');
-        $this->view->set_template('dashboard');
-        $this->view->render();
+        $tpl = new Template(get_lang('Dashboard'));
+        $tpl->assign('content', $content);
+        $tpl->display_one_col_template();
     }
 
     /**
@@ -94,24 +152,14 @@ class DashboardController
      */
     public function store_user_block()
     {
-        $data = array();
-        $user_id = $this->user_id;
         if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
             $enabled_blocks = $_POST['enabled_blocks'];
             $columns = $_POST['columns'];
-            $affected_rows = DashboardManager::store_user_blocks($user_id, $enabled_blocks, $columns);
-            if ($affected_rows) {
-                $data['success'] = true;
-            }
+            DashboardManager::store_user_blocks($this->user_id, $enabled_blocks, $columns);
+            Display::addFlash(Display::return_message(get_lang('Saved')));
         }
-
-        $data['dashboard_view'] = 'list';
-
-        // render to the view
-        $this->view->set_data($data);
-        $this->view->set_layout('layout');
-        $this->view->set_template('dashboard');
-        $this->view->render();
+        header('Location: '.api_get_path(WEB_CODE_PATH).'dashboard/index.php');
+        exit;
     }
 
     /**
@@ -120,8 +168,9 @@ class DashboardController
      */
     public function close_user_block($path)
     {
-        $user_id = $this->user_id;
-        $result = DashboardManager::close_user_block($user_id, $path);
-        $this->display($result);
+        DashboardManager::close_user_block($this->user_id, $path);
+        Display::addFlash(Display::return_message(get_lang('Saved')));
+        header('Location: '.api_get_path(WEB_CODE_PATH).'dashboard/index.php');
+        exit;
     }
 }

+ 1 - 4
main/dashboard/index.php

@@ -19,8 +19,6 @@ require_once 'block.class.php';
 // protect script
 api_block_anonymous_users();
 
-// defining constants
-
 // current section
 $this_section = SECTION_DASHBOARD;
 Session::erase('this_section'); //for hmtl editor repository
@@ -33,8 +31,7 @@ if (isset($_GET['action']) && in_array($_GET['action'], $actions)) {
 }
 
 // load styles from dashboard plugins
-$dashboar_plugin_styles = DashboardManager::get_links_for_styles_from_dashboard_plugins();
-$htmlHeadXtra[] = $dashboar_plugin_styles;
+$htmlHeadXtra[] = DashboardManager::get_links_for_styles_from_dashboard_plugins();
 
 // course description controller object
 $dashboard_controller = new DashboardController();

+ 0 - 20
main/dashboard/layout.php

@@ -1,20 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-/**
-* Layout (principal view) used for structuring other views
-* @author Christian Fasanando <christian1827@gmail.com>
-* @package chamilo.dashboard
-*/
-
-// protect script
-api_block_anonymous_users();
-$tool_name = get_lang('Dashboard');
-
-// Header
-Display::display_header($tool_name);
-
-// Display
-echo $content;
-
-Display::display_footer();

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

@@ -15,6 +15,7 @@ class View
 
     /**
      * Constructor, init tool path for rendering
+     * @deprecated
      * @param string $toolname tool name (optional)
      * @param string $template_path
      */

+ 37 - 35
main/inc/lib/dashboard.lib.php

@@ -343,26 +343,26 @@ class DashboardManager
     {
         $enabled_dashboard_plugins = self::get_enabled_dashboard_blocks();
         $user_block_data = self::get_user_block_data($user_id);
-
+        $html = '';
         if (count($enabled_dashboard_plugins) > 0) {
-            echo '<div style="margin-top:20px">';
-            echo '<div><strong>'.get_lang('SelectBlockForDisplayingInsideBlocksDashboardView').'</strong></div><br />';
-            echo '<form name="dashboard_list" method="post" action="index.php?action=store_user_block">';
-            echo '<table class="data_table">';
-            echo '<tr>';
-            echo '<th width="5%">';
-            echo get_lang('Enabled');
-            echo '</th>';
-            echo '<th width="30%">';
-            echo get_lang('Name');
-            echo '</th>';
-            echo '<th width="40%">';
-            echo get_lang('Description');
-            echo '</th>';
-            echo '<th>';
-            echo get_lang('ColumnPosition');
-            echo '</th>';
-            echo '</tr>';
+            $html .= '<div style="margin-top:20px">';
+            $html .= '<div><strong>'.get_lang('SelectBlockForDisplayingInsideBlocksDashboardView').'</strong></div><br />';
+            $html .= '<form name="dashboard_list" method="post" action="index.php?action=store_user_block">';
+            $html .= '<table class="data_table">';
+            $html .= '<tr>';
+            $html .= '<th width="5%">';
+            $html .= get_lang('Enabled');
+            $html .= '</th>';
+            $html .= '<th width="30%">';
+            $html .= get_lang('Name');
+            $html .= '</th>';
+            $html .= '<th width="40%">';
+            $html .= get_lang('Description');
+            $html .= '</th>';
+            $html .= '<th>';
+            $html .= get_lang('ColumnPosition');
+            $html .= '</th>';
+            $html .= '</tr>';
 
             // We display all enabled plugins and the checkboxes
             foreach ($enabled_dashboard_plugins as $block) {
@@ -382,35 +382,36 @@ class DashboardManager
                         }
                     }
 
-                    echo '<tr>';
+                    $html .= '<tr>';
                     // checkboxes
-                    self::display_user_dashboard_list_checkboxes($user_id, $block['id']);
-                    echo '<td>'.$block['name'].'</td>';
-                    echo '<td>'.$block['description'].'</td>';
-                    echo '<td>
+                    $html .= self::display_user_dashboard_list_checkboxes($user_id, $block['id']);
+                    $html .= '<td>'.$block['name'].'</td>';
+                    $html .= '<td>'.$block['description'].'</td>';
+                    $html .= '<td>
                             <select class="selectpicker show-tick form-control" name="columns['.$block['id'].']">
                             <option value="1" '.(isset($user_block_data[$block['id']]) && $user_block_data[$block['id']]['column'] == 1 ? 'selected' : '').' >1</option>
                             <option value="2" '.(isset($user_block_data[$block['id']]) && $user_block_data[$block['id']]['column'] == 2 ? 'selected' : '').' >2</option>
                             </select>
                           </td>';
-                    echo '</tr>';
+                    $html .= '</tr>';
                 } else {
-                    echo Display::tag('tr', Display::tag('td', get_lang('Error').' '.$controller_class, array('colspan'=>'3')));
+                    $html .= Display::tag('tr', Display::tag('td', get_lang('Error').' '.$controller_class, array('colspan'=>'3')));
                 }
             }
 
-            echo '</table>';
-            echo '<div class="row"><div class="col-md-12">';
-            echo '<button class="btn btn-default" type="submit" name="submit_dashboard_list" value="'.get_lang('EnableDashboardBlock').'"><em class="fa fa-check-square"></em> '.
+            $html .= '</table>';
+            $html .= '<div class="row"><div class="col-md-12">';
+            $html .= '<button class="btn btn-default" type="submit" name="submit_dashboard_list" value="'.get_lang('EnableDashboardBlock').'"><em class="fa fa-check-square"></em> '.
                 get_lang('EnableDashboardBlock').'</button></form>';
-            echo '</div></div>';
+            $html .= '</div></div>';
         } else {
-            echo '<div style="margin-top:20px">'.get_lang('ThereAreNoEnabledDashboardPlugins').'</div>';
+            $html .= '<div style="margin-top:20px">'.get_lang('ThereAreNoEnabledDashboardPlugins').'</div>';
             if (api_is_platform_admin()) {
-                echo '<a class="btn btn-default" href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'.
+                $html .= '<a class="btn btn-default" href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'.
                     get_lang('ConfigureDashboardPlugin').'</a>';
             }
         }
+        return $html;
     }
 
     /**
@@ -429,9 +430,10 @@ class DashboardManager
             $checked = "checked";
         }
 
-        echo "<td align=\"center\">";
-        echo '<input type="checkbox" name="enabled_blocks['.$block_id.']" value="true" '.$checked.'/>';
-        echo "</td>";
+        $html = "<td align=\"center\">";
+        $html .= '<input type="checkbox" name="enabled_blocks['.$block_id.']" value="true" '.$checked.'/>';
+        $html .= "</td>";
+        return $html;
     }
 
     /**