Added one global information block only visible to admins + one method in the admin stats class

skala
Yannick Warnier 13 years ago
parent be0121c630
commit 281286bade
  1. 27
      main/admin/statistics/statistics.lib.php
  2. 143
      plugin/dashboard/block_global_info/block_global_info.class.php
  3. 6
      plugin/dashboard/block_global_info/block_global_info.info
  4. 79
      plugin/dashboard/block_global_info/css/default.css
  5. 8
      plugin/dashboard/block_global_info/css/index.html
  6. 8
      plugin/dashboard/block_global_info/index.html
  7. 4
      plugin/dashboard/block_session/css/default.css

@ -46,6 +46,33 @@ class Statistics {
return $obj->number;
}
/**
* Count courses by visibility
* @param int Visibility (0 = closed, 1 = private, 2 = open, 3 = public)
* all courses.
* @return int Number of courses counted
*/
static function count_courses_by_visibility($vis = null) {
if (!isset($vis)) { return 0; }
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
if ($_configuration['multiple_access_urls']) {
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." as c, ".$access_url_rel_course_table." as u WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'";
if (isset ($vis)) {
$sql .= " AND visibility = ".intval($vis);
}
} else {
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." ";
if (isset ($vis)) {
$sql .= " WHERE visibility = ".intval($vis);
}
}
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->number;
}
/**
* Count users
* @param int optional, user status (COURSEMANAGER or STUDENT), if it's not setted it'll count all users.

@ -0,0 +1,143 @@
<?php
/**
* This file is part of global info block plugin for dashboard,
* it should be required inside the dashboard controller for
* showing it into the dashboard interface.
* @package chamilo.dashboard
* @author Yannick Warnier
*/
/**
* required files for getting data
*/
require_once api_get_path(SYS_CODE_PATH).'admin/statistics/statistics.lib.php';
/**
* This class is used like controller for this global info block plugin
* the class name must be registered inside path.info file
* (e.g: controller = "BlockGlobalInfo"), so dashboard controller can
* instantiate it
* @package chamilo.dashboard
*/
class BlockGlobalInfo extends Block {
private $user_id;
private $courses;
private $path;
private $permission = array();
/**
* Constructor
*/
public function __construct ($user_id) {
$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);
}
}
/**
* This method check if a user is allowed to see the block inside dashboard interface
* @param int User id
* @return bool Is block visible for user
*/
public function is_block_visible_for_user($user_id) {
$user_info = api_get_user_info($user_id);
$user_status = $user_info['status'];
$is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true;
}
return $is_block_visible_for_user;
}
/**
* This method return content html containing information about courses and its position for showing it inside dashboard interface
* it's important to use the name 'get_block' for beeing used from dashboard controller
* @return array column and content html
*/
public function get_block() {
global $charset;
$column = 2;
$data = array();
$content = '';
$data_table = '';
$content = $this->get_content_html();
$html = '
<li class="widget color-red" id="intro">
<div class="widget-head">
<h3>'.get_lang('GlobalPlatformInformation').'</h3>
<div class="widget-actions"><a onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">'.Display::return_icon('close.gif',get_lang('Close')).'</a></div>
</div>
<div class="widget-content">
'.$content.'
</div>
</li>
';
$data['column'] = $column;
$data['content_html'] = $html;
return $data;
}
/**
* This method return a content html, it's used inside get_block method for showing it inside dashboard interface
* @return string content html
*/
public function get_content_html() {
$global_data = $this->get_global_information_data();
$content = '<div style="margin:10px;">';
$content .= '<h3><font color="#000">'.get_lang('PortalInformation').'</font></h3>';
if (!empty($global_data)) {
$data_table = '<table class="data_table" width:"95%">';
$i = 1;
foreach ($global_data as $data) {
if ($i%2 == 0) {
$class_tr = 'row_odd';
} else {
$class_tr = 'row_even';
}
$data_table .= '<tr class="'.$class_tr.'">';
foreach ($data as $cell) {
$data_table .= '<td align="right">'.$cell.'</td>';
}
$data_table .= '</tr>';
$i++;
}
$data_table .= '</table>';
} else {
$data_table .= get_lang('ThereIsNoInformationAboutThePlatform');
}
$content .= $data_table;
$content .= '</div>';
return $content;
}
/**
* Get global information data
* @return array
*/
function get_global_information_data() {
// Two-dimensional array with data about the system
$global_info = array();
// Check total number of users
$global_info[] = array(get_lang('CountUsers'), statistics::count_users());
// Check only active users
$global_info[] = array(get_lang('NumberOfUsersActive'), statistics::count_users(null,null,null,true));
// Check number of courses
$global_info[] = array(get_lang('NumberOfCoursesTotal'), statistics::count_courses());
$global_info[] = array(get_lang('NumberOfCoursesClosed'), statistics::count_courses_by_visibility(COURSE_VISIBILITY_CLOSED));
$global_info[] = array(get_lang('NumberOfCoursesPrivate'), statistics::count_courses_by_visibility(COURSE_VISIBILITY_REGISTERED));
$global_info[] = array(get_lang('NumberOfCoursesOpen'), statistics::count_courses_by_visibility(COURSE_VISIBILITY_OPEN_PLATFORM));
$global_info[] = array(get_lang('NumberOfCoursesPublic'), statistics::count_courses_by_visibility(COURSE_VISIBILITY_OPEN_WORLD));
return $global_info;
}
}

@ -0,0 +1,6 @@
name = "Global info Block"
controller = "BlockGlobalInfo"
description = "Display global platform information"
package = Dashboard
version = 1.0
author = Yannick Warnier <ywarnier@beeznest.org>

@ -0,0 +1,79 @@
/* Colors */
.color-yellow {background:#f2bc00;}
.color-red {background:#dd0000;}
.color-blue {background:#148ea4;}
.color-white {background:#dfdfdf;}
.color-orange {background:#f66e00;}
.color-green {background:#8dc100;}
.color-yellow h3,
.color-white h3,
.color-green h3
{color:#000;}
.color-red h3,
.color-blue h3,
.color-orange h3
{color:#FFF;}
/* End Colors */
//#columns #column1 .widget { margin: 30px 35px 0 25px; }
//#columns #column3 .widget { margin: 30px 25px 0 35px; }
.widget {
margin: 30px 20px 0 20px;
padding: 2px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
}
.widget .widget-head {
color: #000;
overflow: hidden;
width: 100%;
height: 30px;
line-height: 10px;
}
.widget .widget-head h3 {
padding: 0 5px;
float: left;
margin: 0px;
}
.widget .widget-content {
background: #FFF url(img/widget-content-bg.png) repeat-x;
padding: 0 5px;
color: #000;
-moz-border-radius-bottomleft: 2px;
-moz-border-radius-bottomright: 2px;
-webkit-border-bottom-left-radius: 2px;
-webkit-border-bottom-right-radius: 2px;
line-height: 1.2em;
overflow: hidden;
}
.widget .widget-content p {
padding: 0.8em 0;
border-bottom: 1px solid #666;
}
.widget .widget-content pre {
padding: 0.5em 5px;
color: #EEE;
font-size: 12px;
}
.widget .widget-content ul {
padding: 5px 0 5px 20px;
list-style: disc;
}
.widget .widget-content ul li {padding: 3px 0;}
.widget .widget-content ul.images {
padding: 7px 0 0 0;
list-style: none;
height: 1%;
}
.widget .widget-content ul.images li {
display: inline;
float: left;
}
.widget .widget-content ul.images img {
display: inline;
float: left;
margin: 0 0 7px 7px;
}
.widget-actions {text-align:right;margin-right:5px;margin-top:5px;}

@ -0,0 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
<br />
</body>
</html>

@ -0,0 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
<br />
</body>
</html>

@ -36,7 +36,7 @@
float: left;
}
.widget .widget-content {
background: #FFF url(img/widget-content-bg.png) repeat-x;
background: #FFF;/* url(img/widget-content-bg.png) repeat-x;*/
padding: 0 5px;
color: #000;
-moz-border-radius-bottomleft: 2px;
@ -75,4 +75,4 @@
margin: 0 0 7px 7px;
}
.widget-actions {text-align:right;margin-right:5px;margin-top:5px;}
.widget-actions {text-align:right;margin-right:5px;margin-top:5px;}

Loading…
Cancel
Save