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
pull/2487/head
jmontoyaa 8 years ago
parent b07c67ff32
commit 179959c10e
  1. 21
      main/dashboard/block.class.php
  2. 96
      main/dashboard/dashboard.php
  3. 131
      main/dashboard/dashboard_controller.php
  4. 5
      main/dashboard/index.php
  5. 20
      main/dashboard/layout.php
  6. 1
      main/inc/lib/app_view.php
  7. 72
      main/inc/lib/dashboard.lib.php

@ -16,25 +16,4 @@ class Block
public function __construct() 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;
}
} }

@ -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);
}

@ -5,16 +5,12 @@
* Controller script. Prepares the common background * Controller script. Prepares the common background
* variables to give to the scripts corresponding to * variables to give to the scripts corresponding to
* the requested action * 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> * @author Christian Fasanando <christian1827@gmail.com>
* @todo move to main/inc/lib * @todo move to main/inc/lib
* @package chamilo.dashboard * @package chamilo.dashboard
*/ */
class DashboardController class DashboardController
{ {
private $toolname;
private $view;
private $user_id; private $user_id;
/** /**
@ -23,8 +19,6 @@ class DashboardController
public function __construct() public function __construct()
{ {
$this->user_id = api_get_user_id(); $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) * @param string $msg (optional)
* render to dashboard.php view * render to dashboard.php view
*/ */
public function display($msg = false) public function display()
{ {
$data = array();
$user_id = $this->user_id; $user_id = $this->user_id;
$block_data_without_plugin = DashboardManager::get_block_data_without_plugin();
$dashboard_blocks = DashboardManager::get_enabled_dashboard_blocks(); $dashboard_blocks = DashboardManager::get_enabled_dashboard_blocks();
$user_block_data = DashboardManager::get_user_block_data($user_id); $user_block_data = DashboardManager::get_user_block_data($user_id);
$user_blocks_id = array_keys($user_block_data); $user_blocks_id = array_keys($user_block_data);
$blocks = null;
$data_block = null;
if (!empty($dashboard_blocks)) { if (!empty($dashboard_blocks)) {
foreach ($dashboard_blocks as $block) { foreach ($dashboard_blocks as $block) {
// display only user blocks // 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 // 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; $configuration_link = null;
$data['dashboard_view'] = 'blocks'; 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) { $content = '<div class="actions">';
$data['msg'] = $msg; $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 $tpl = new Template(get_lang('Dashboard'));
$this->view->set_data($data); $tpl->assign('content', $content);
$this->view->set_layout('layout'); $tpl->display_one_col_template();
$this->view->set_template('dashboard');
$this->view->render();
} }
/** /**
@ -94,24 +152,14 @@ class DashboardController
*/ */
public function store_user_block() public function store_user_block()
{ {
$data = array();
$user_id = $this->user_id;
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
$enabled_blocks = $_POST['enabled_blocks']; $enabled_blocks = $_POST['enabled_blocks'];
$columns = $_POST['columns']; $columns = $_POST['columns'];
$affected_rows = DashboardManager::store_user_blocks($user_id, $enabled_blocks, $columns); DashboardManager::store_user_blocks($this->user_id, $enabled_blocks, $columns);
if ($affected_rows) { Display::addFlash(Display::return_message(get_lang('Saved')));
$data['success'] = true;
} }
} header('Location: '.api_get_path(WEB_CODE_PATH).'dashboard/index.php');
exit;
$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();
} }
/** /**
@ -120,8 +168,9 @@ class DashboardController
*/ */
public function close_user_block($path) public function close_user_block($path)
{ {
$user_id = $this->user_id; DashboardManager::close_user_block($this->user_id, $path);
$result = DashboardManager::close_user_block($user_id, $path); Display::addFlash(Display::return_message(get_lang('Saved')));
$this->display($result); header('Location: '.api_get_path(WEB_CODE_PATH).'dashboard/index.php');
exit;
} }
} }

@ -19,8 +19,6 @@ require_once 'block.class.php';
// protect script // protect script
api_block_anonymous_users(); api_block_anonymous_users();
// defining constants
// current section // current section
$this_section = SECTION_DASHBOARD; $this_section = SECTION_DASHBOARD;
Session::erase('this_section'); //for hmtl editor repository 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 // load styles from dashboard plugins
$dashboar_plugin_styles = DashboardManager::get_links_for_styles_from_dashboard_plugins(); $htmlHeadXtra[] = DashboardManager::get_links_for_styles_from_dashboard_plugins();
$htmlHeadXtra[] = $dashboar_plugin_styles;
// course description controller object // course description controller object
$dashboard_controller = new DashboardController(); $dashboard_controller = new DashboardController();

@ -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();

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

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

Loading…
Cancel
Save