Minor - format code

pull/2487/head
jmontoyaa 8 years ago
parent 33a4ff908c
commit ee625ef1bc
  1. 20
      main/coursecopy/copy_course_session.php
  2. 34
      main/webservices/access_url.php
  3. 9
      plugin/buycourses/src/service_process_confirm.php
  4. 25
      plugin/buycourses/src/service_success.php
  5. 5
      plugin/buycourses/src/services_edit.php
  6. 16
      plugin/buycourses/src/success.php
  7. 14
      plugin/dashboard/block_course/block_course.class.php
  8. 6
      plugin/dashboard/block_daily/block_daily.class.php
  9. 232
      plugin/dashboard/block_evaluation_graph/block_evaluation_graph.class.php
  10. 120
      plugin/dashboard/block_global_info/block_global_info.class.php
  11. 212
      plugin/dashboard/block_session/block_session.class.php
  12. 358
      plugin/dashboard/block_student/block_student.class.php
  13. 195
      plugin/dashboard/block_student_graph/block_student_graph.class.php
  14. 3
      plugin/dashboard/block_teacher/block_teacher.class.php
  15. 157
      plugin/dashboard/block_teacher_graph/block_teacher_graph.class.php

@ -48,8 +48,12 @@ $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
/* FUNCTIONS */ /**
* @param string $name
* @param array $sessions
* @param array $attr
* @return string
*/
function make_select_session_list($name, $sessions, $attr = array()) function make_select_session_list($name, $sessions, $attr = array())
{ {
$attributes = ''; $attributes = '';
@ -83,6 +87,9 @@ function make_select_session_list($name, $sessions, $attr = array())
return $output; return $output;
} }
/**
* @return string
*/
function display_form() function display_form()
{ {
$html = ''; $html = '';
@ -138,6 +145,11 @@ function display_form()
echo $html; echo $html;
} }
/**
* @param int $id_session
* @param string $type
* @return xajaxResponse
*/
function search_courses($id_session, $type) function search_courses($id_session, $type)
{ {
global $tbl_course, $tbl_session_rel_course, $course_list; global $tbl_course, $tbl_session_rel_course, $course_list;
@ -221,12 +233,12 @@ function search_courses($id_session, $type)
); );
} }
} }
return $xajax_response; return $xajax_response;
} }
$xajax->processRequests(); $xajax->processRequests();
/* HTML head extra */ /* HTML head extra */
$htmlHeadXtra[] = $xajax->getJavascript(api_get_path(WEB_LIBRARY_PATH).'xajax/'); $htmlHeadXtra[] = $xajax->getJavascript(api_get_path(WEB_LIBRARY_PATH).'xajax/');
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
function checkSelected(id_select,id_radio,id_title,id_destination) { function checkSelected(id_select,id_radio,id_title,id_destination) {
@ -278,7 +290,7 @@ if (Security::check_token('post') && (
// Clear token // Clear token
Security::clear_token(); Security::clear_token();
$destination_course = $origin_course = $destination_session = $origin_session = ''; $destination_course = $origin_course = $destination_session = $origin_session = '';
if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') { if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
$destination_course = $_POST['destination_course']; $destination_course = $_POST['destination_course'];
$origin_course = $_POST['origin_course']; $origin_course = $_POST['origin_course'];
$destination_session = $_POST['destination_session']; $destination_session = $_POST['destination_session'];

@ -62,19 +62,22 @@ function WSHelperVerifyKey($params)
list($ip1, $ip2) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); list($ip1, $ip2) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = trim($ip1); $ip = trim($ip1);
} }
if ($debug) if ($debug) {
error_log("ip: $ip"); error_log("ip: $ip");
}
// Check if a file that limits access from webservices exists and contains // Check if a file that limits access from webservices exists and contains
// the restraining check // the restraining check
if (is_file('webservice-auth-ip.conf.php')) { if (is_file('webservice-auth-ip.conf.php')) {
include 'webservice-auth-ip.conf.php'; include 'webservice-auth-ip.conf.php';
if ($debug) if ($debug) {
error_log("webservice-auth-ip.conf.php file included"); error_log("webservice-auth-ip.conf.php file included");
}
if (!empty($ws_auth_ip)) { if (!empty($ws_auth_ip)) {
$check_ip = true; $check_ip = true;
$ip_matches = api_check_ip_in_range($ip, $ws_auth_ip); $ip_matches = api_check_ip_in_range($ip, $ws_auth_ip);
if ($debug) if ($debug) {
error_log("ip_matches: $ip_matches"); error_log("ip_matches: $ip_matches");
}
} }
} }
@ -91,8 +94,9 @@ function WSHelperVerifyKey($params)
$result = api_is_valid_secret_key($secret_key, $security_key); $result = api_is_valid_secret_key($secret_key, $security_key);
//error_log($secret_key.'-'.$security_key); //error_log($secret_key.'-'.$security_key);
if ($debug) if ($debug) {
error_log('WSHelperVerifyKey result: '.intval($result)); error_log('WSHelperVerifyKey result: '.intval($result));
}
return $result; return $result;
} }
@ -114,8 +118,6 @@ $server->soap_defencoding = 'UTF-8';
// Initialize WSDL support // Initialize WSDL support
$server->configureWSDL('WSAccessUrl', 'urn:WSAccessUrl'); $server->configureWSDL('WSAccessUrl', 'urn:WSAccessUrl');
$server->wsdl->addComplexType( $server->wsdl->addComplexType(
'portalItem', 'portalItem',
'complexType', 'complexType',
@ -135,7 +137,13 @@ $server->wsdl->addComplexType(
'', '',
'SOAP-ENC:Array', 'SOAP-ENC:Array',
array(), array(),
array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:portalItem[]')), 'tns:portalItem' array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:portalItem[]',
),
),
'tns:portalItem'
); );
$server->wsdl->addComplexType( $server->wsdl->addComplexType(
@ -197,7 +205,8 @@ $server->wsdl->addComplexType(
); );
// Register the method to expose // Register the method to expose
$server->register('WSAddUserToPortal', // method name $server->register(
'WSAddUserToPortal', // method name
array('addUserToPortal' => 'tns:AddUserToPortal'), // input parameters array('addUserToPortal' => 'tns:AddUserToPortal'), // input parameters
array('return' => 'xsd:string'), // output parameters array('return' => 'xsd:string'), // output parameters
'urn:WSAccessUrl', // namespace 'urn:WSAccessUrl', // namespace
@ -228,7 +237,8 @@ function WSAddUserToPortal($params)
} }
// Register the method to expose // Register the method to expose
$server->register('WSRemoveUserFromPortal', // method name $server->register(
'WSRemoveUserFromPortal', // method name
array('removeUserFromPortal' => 'tns:AddUserToPortal'), // input parameters array('removeUserFromPortal' => 'tns:AddUserToPortal'), // input parameters
array('return' => 'xsd:string'), // output parameters array('return' => 'xsd:string'), // output parameters
'urn:WSAccessUrl', // namespace 'urn:WSAccessUrl', // namespace
@ -271,7 +281,8 @@ $server->wsdl->addComplexType(
); );
// Register the method to expose // Register the method to expose
$server->register('WSGetPortalListFromUser', // method name $server->register(
'WSGetPortalListFromUser', // method name
array('getPortalListFromUser' => 'tns:getPortalListFromUser'), // input parameters array('getPortalListFromUser' => 'tns:getPortalListFromUser'), // input parameters
array('return' => 'tns:portalList'), // output parameters array('return' => 'tns:portalList'), // output parameters
'urn:WSAccessUrl', // namespace 'urn:WSAccessUrl', // namespace
@ -315,7 +326,8 @@ $server->wsdl->addComplexType(
); );
// Register the method to expose // Register the method to expose
$server->register('WSGetPortalListFromCourse', // method name $server->register(
'WSGetPortalListFromCourse', // method name
array('getPortalListFromCourse' => 'tns:getPortalListFromCourse'), // input parameters array('getPortalListFromCourse' => 'tns:getPortalListFromCourse'), // input parameters
array('return' => 'tns:portalList'), // output parameters array('return' => 'tns:portalList'), // output parameters
'urn:WSAccessUrl', // namespace 'urn:WSAccessUrl', // namespace

@ -83,7 +83,14 @@ switch ($serviceSale['payment_type']) {
case BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER: case BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER:
$transferAccounts = $plugin->getTransferAccounts(); $transferAccounts = $plugin->getTransferAccounts();
$form = new FormValidator('success', 'POST', api_get_self(), null, null, FormValidator::LAYOUT_INLINE); $form = new FormValidator(
'success',
'POST',
api_get_self(),
null,
null,
FormValidator::LAYOUT_INLINE
);
if ($form->validate()) { if ($form->validate()) {
$formValues = $form->getSubmitValues(); $formValues = $form->getSubmitValues();

@ -15,7 +15,6 @@ if (!$paypalEnabled) {
} }
$serviceSaleId = $_SESSION['bc_service_sale_id']; $serviceSaleId = $_SESSION['bc_service_sale_id'];
$serviceSale = $plugin->getServiceSale($serviceSaleId); $serviceSale = $plugin->getServiceSale($serviceSaleId);
$itemPrice = $serviceSale['price']; $itemPrice = $serviceSale['price'];
@ -34,8 +33,20 @@ require_once("paypalfunctions.php");
$buyerInformation = GetShippingDetails(urlencode($_SESSION['TOKEN'])); $buyerInformation = GetShippingDetails(urlencode($_SESSION['TOKEN']));
$form = new FormValidator('success', 'POST', api_get_self(), null, null, FormValidator::LAYOUT_INLINE); $form = new FormValidator(
$form->addButton('confirm', $plugin->get_lang('ConfirmOrder'), 'check', 'success'); 'success',
'POST',
api_get_self(),
null,
null,
FormValidator::LAYOUT_INLINE
);
$form->addButton(
'confirm',
$plugin->get_lang('ConfirmOrder'),
'check',
'success'
);
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel'); $form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
if ($form->validate()) { if ($form->validate()) {
@ -54,7 +65,6 @@ if ($form->validate()) {
} }
$confirmPayments = ConfirmPayment($itemPrice); $confirmPayments = ConfirmPayment($itemPrice);
if ($confirmPayments['ACK'] !== 'Success') { if ($confirmPayments['ACK'] !== 'Success') {
$erroMessage = vsprintf( $erroMessage = vsprintf(
$plugin->get_lang('ErrorOccurred'), $plugin->get_lang('ErrorOccurred'),
@ -154,16 +164,17 @@ if ($form->validate()) {
} }
$token = isset($_GET['token']) ? Security::remove_XSS($_GET['token']) : null; $token = isset($_GET['token']) ? Security::remove_XSS($_GET['token']) : null;
if (empty($token)) { if (empty($token)) {
api_not_allowed(true); api_not_allowed(true);
} }
$interbreadcrumb[] = array("url" => "service_catalog.php", "name" => $plugin->get_lang('ListOfServicesOnSale')); $interbreadcrumb[] = array(
"url" => "service_catalog.php",
"name" => $plugin->get_lang('ListOfServicesOnSale'),
);
$templateName = $plugin->get_lang('PaymentMethods'); $templateName = $plugin->get_lang('PaymentMethods');
$tpl = new Template($templateName); $tpl = new Template($templateName);
$tpl->assign('title', $serviceSale['service']['name']); $tpl->assign('title', $serviceSale['service']['name']);
$tpl->assign('price', $serviceSale['price']); $tpl->assign('price', $serviceSale['price']);
$tpl->assign('currency', $serviceSale['currency_id']); $tpl->assign('currency', $serviceSale['currency_id']);

@ -131,21 +131,16 @@ if ($form->validate()) {
$values = $form->getSubmitValues(); $values = $form->getSubmitValues();
if (isset($values['delete_service'])) { if (isset($values['delete_service'])) {
$plugin->deleteService($serviceId); $plugin->deleteService($serviceId);
Display::addFlash( Display::addFlash(
Display::return_message($plugin->get_lang('ServiceDeleted'), 'error') Display::return_message($plugin->get_lang('ServiceDeleted'), 'error')
); );
} else { } else {
$plugin->updateService($values, $serviceId); $plugin->updateService($values, $serviceId);
Display::addFlash( Display::addFlash(
Display::return_message($plugin->get_lang('ServiceEdited'), 'success') Display::return_message($plugin->get_lang('ServiceEdited'), 'success')
); );
} }
header('Location: configuration.php'); header('Location: configuration.php');
exit; exit;
} }

@ -44,7 +44,14 @@ $paypalSignature = $paypalParams['signature'];
require_once("paypalfunctions.php"); require_once("paypalfunctions.php");
$form = new FormValidator('success', 'POST', api_get_self(), null, null, FormValidator::LAYOUT_INLINE); $form = new FormValidator(
'success',
'POST',
api_get_self(),
null,
null,
FormValidator::LAYOUT_INLINE
);
$form->addButton('confirm', $plugin->get_lang('ConfirmOrder'), 'check', 'success'); $form->addButton('confirm', $plugin->get_lang('ConfirmOrder'), 'check', 'success');
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel'); $form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
@ -74,13 +81,12 @@ if ($form->validate()) {
exit; exit;
} }
$transactionId = $confirmPayments["PAYMENTINFO_0_TRANSACTIONID"]; $transactionId = $confirmPayments['PAYMENTINFO_0_TRANSACTIONID'];
$transactionType = $confirmPayments["PAYMENTINFO_0_TRANSACTIONTYPE"]; $transactionType = $confirmPayments['PAYMENTINFO_0_TRANSACTIONTYPE'];
switch ($confirmPayments["PAYMENTINFO_0_PAYMENTSTATUS"]) { switch ($confirmPayments['PAYMENTINFO_0_PAYMENTSTATUS']) {
case 'Completed': case 'Completed':
$saleIsCompleted = $plugin->completeSale($sale['id']); $saleIsCompleted = $plugin->completeSale($sale['id']);
if ($saleIsCompleted && $buyingSession) { if ($saleIsCompleted && $buyingSession) {
Display::addFlash( Display::addFlash(
Display::return_message( Display::return_message(

@ -7,7 +7,8 @@
*/ */
/** /**
* This class is used like controller for this course block plugin, * This class is used like controller for this course block plugin,
* the class name must be registered inside path.info file (e.g: controller = "BlockCourse"), so dashboard controller will be instantiate it * the class name must be registered inside path.info file
* (e.g: controller = "BlockCourse"), so dashboard controller will be instantiate it
* @package chamilo.dashboard * @package chamilo.dashboard
*/ */
class BlockCourse extends Block class BlockCourse extends Block
@ -51,7 +52,8 @@ class BlockCourse extends Block
} }
/** /**
* This method return content html containing information about courses and its position for showing it inside dashboard interface * 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 * it's important to use the name 'get_block' for beeing used from dashboard controller
* @return array column and content html * @return array column and content html
*/ */
@ -92,10 +94,7 @@ class BlockCourse extends Block
public function get_content_html() public function get_content_html()
{ {
$course_data = $this->get_course_information_data(); $course_data = $this->get_course_information_data();
//$content = '<div style="margin:10px;">'; $content = '<h4>'.get_lang('YourCourseList').'</h4>';
$content = '<h4>'.get_lang(
'YourCourseList'
).'</h4>';
$data_table = null; $data_table = null;
if (!empty($course_data)) { if (!empty($course_data)) {
$data_table .= '<table class="data_table" width:"95%">'; $data_table .= '<table class="data_table" width:"95%">';
@ -172,7 +171,8 @@ class BlockCourse extends Block
if (count($users) > 0) { if (count($users) > 0) {
$nb_students_in_course = count($users); $nb_students_in_course = count($users);
$avg_time_spent_in_course = api_time_to_hms( $avg_time_spent_in_course = api_time_to_hms(
Tracking::get_time_spent_on_the_course($users, $courseId) / $nb_students_in_course); Tracking::get_time_spent_on_the_course($users, $courseId) / $nb_students_in_course
);
} else { } else {
$avg_time_spent_in_course = null; $avg_time_spent_in_course = null;
} }

@ -66,7 +66,6 @@ class BlockDaily extends Block
*/ */
public function get_block() public function get_block()
{ {
global $charset; global $charset;
$column = 2; $column = 2;
$data = array(); $data = array();
@ -101,10 +100,7 @@ class BlockDaily extends Block
public function get_content_html() public function get_content_html()
{ {
$course_data = $this->get_course_information_data(); $course_data = $this->get_course_information_data();
//$content = '<div style="margin:10px;">'; $content = '<h4>'.get_lang('YourCourseList').'</h4>';
$content = '<h4>'.get_lang(
'YourCourseList'
).'</h4>';
$data_table = null; $data_table = null;
if (!empty($course_data)) { if (!empty($course_data)) {
$data_table .= '<table class="data_table" width:"95%">'; $data_table .= '<table class="data_table" width:"95%">';

@ -5,7 +5,6 @@ use CpChart\Chart\Data as pData;
use CpChart\Chart\Image as pImage; use CpChart\Chart\Image as pImage;
use CpChart\Chart\Cache as pCache; use CpChart\Chart\Cache as pCache;
/** /**
* Class BlockEvaluationGraph * Class BlockEvaluationGraph
* This class is used like controller for this evaluations graph block plugin, * This class is used like controller for this evaluations graph block plugin,
@ -23,59 +22,59 @@ use CpChart\Chart\Cache as pCache;
class BlockEvaluationGraph extends Block class BlockEvaluationGraph extends Block
{ {
private $user_id; private $user_id;
private $courses; private $courses;
private $sessions; private $sessions;
private $path; private $path;
private $permission = array(DRH, SESSIONADMIN); private $permission = array(DRH, SESSIONADMIN);
/** /**
* Constructor * Constructor
*/ */
public function __construct($user_id) public function __construct($user_id)
{ {
$this->path = 'block_evaluation_graph'; $this->path = 'block_evaluation_graph';
$this->user_id = $user_id; $this->user_id = $user_id;
$this->bg_width = 450; $this->bg_width = 450;
$this->bg_height = 350; $this->bg_height = 350;
if ($this->is_block_visible_for_user($user_id)) { if ($this->is_block_visible_for_user($user_id)) {
if (!api_is_session_admin()) { if (!api_is_session_admin()) {
$this->courses = CourseManager::get_courses_followed_by_drh($user_id); $this->courses = CourseManager::get_courses_followed_by_drh($user_id);
} }
$this->sessions = SessionManager::get_sessions_followed_by_drh($user_id); $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id);
} }
} }
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) public function is_block_visible_for_user($user_id)
{ {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
* This method return content html containing information about sessions and its position for showing it inside dashboard interface * This method return content html containing
* information about sessions and its position for showing it inside dashboard interface
* it's important to use the name 'get_block' for beeing used from dashboard controller * it's important to use the name 'get_block' for beeing used from dashboard controller
* @return array column and content html * @return array column and content html
*/ */
public function get_block() public function get_block()
{ {
global $charset; global $charset;
$column = 1; $column = 1;
$data = array(); $data = array();
$evaluations_base_courses_graph = $this->get_evaluations_base_courses_graph();
$evaluations_base_courses_graph = $this->get_evaluations_base_courses_graph(); $evaluations_courses_in_sessions_graph = $this->get_evaluations_courses_in_sessions_graph();
$evaluations_courses_in_sessions_graph = $this->get_evaluations_courses_in_sessions_graph();
$html = '<div class="panel panel-default" id="intro"> $html = '<div class="panel panel-default" id="intro">
<div class="panel-heading"> <div class="panel-heading">
'.get_lang('EvaluationsGraph').' '.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.'"> <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.'">
@ -105,43 +104,51 @@ class BlockEvaluationGraph extends Block
} }
} }
} }
$html .= '</div> $html .= '</div>
</div>'; </div>';
$data['column'] = $column; $data['column'] = $column;
$data['content_html'] = $html; $data['content_html'] = $html;
return $data; return $data;
} }
/** /**
* This method return a graph containing informations about evaluations * This method return a graph containing informations about evaluations
* inside base courses, it's used inside get_block method for showing * inside base courses, it's used inside get_block method for showing
* it inside dashboard interface * it inside dashboard interface
* @return string img html * @return string img html
*/ */
public function get_evaluations_base_courses_graph() public function get_evaluations_base_courses_graph()
{ {
$graphs = array(); $graphs = array();
if (!empty($this->courses)) { if (!empty($this->courses)) {
$courses_code = array_keys($this->courses); $courses_code = array_keys($this->courses);
foreach ($courses_code as $course_code) { foreach ($courses_code as $course_code) {
$cats = Category::load(null, null, $course_code, null, null, null, false); $cats = Category::load(
null,
if (isset($cats) && isset($cats[0])) { null,
$alleval = $cats[0]->get_evaluations(null, true, $course_code); $course_code,
$alllinks = $cats[0]->get_links(null, true); null,
$users = GradebookUtils::get_all_users($alleval, $alllinks); null,
$datagen = new FlatViewDataGenerator($users, $alleval, $alllinks); null,
$evaluation_sumary = $datagen->get_evaluation_sumary_results(); false
if (!empty($evaluation_sumary)) { );
$items = array_keys($evaluation_sumary);
$max = $min = $avg = array(); if (isset($cats) && isset($cats[0])) {
foreach ($evaluation_sumary as $evaluation) { $alleval = $cats[0]->get_evaluations(null, true, $course_code);
$max[] = $evaluation['max']; $alllinks = $cats[0]->get_links(null, true);
$users = GradebookUtils::get_all_users($alleval, $alllinks);
$datagen = new FlatViewDataGenerator($users, $alleval, $alllinks);
$evaluation_sumary = $datagen->get_evaluation_sumary_results();
if (!empty($evaluation_sumary)) {
$items = array_keys($evaluation_sumary);
$max = $min = $avg = array();
foreach ($evaluation_sumary as $evaluation) {
$max[] = $evaluation['max'];
$min[] = !empty($evaluation['min']) ? $evaluation['min'] : 0; $min[] = !empty($evaluation['min']) ? $evaluation['min'] : 0;
$avg[] = $evaluation['avg']; $avg[] = $evaluation['avg'];
} }
// Dataset definition // Dataset definition
$dataSet = new pData(); $dataSet = new pData();
$dataSet->addPoints($min, 'Serie3'); $dataSet->addPoints($min, 'Serie3');
@ -283,43 +290,43 @@ class BlockEvaluationGraph extends Block
if (!empty($imgPath)) { if (!empty($imgPath)) {
$courses_graph[$course_code] = '<img src="'.$imgPath.'">'; $courses_graph[$course_code] = '<img src="'.$imgPath.'">';
} }
} }
} }
} // end for } // end for
} }
return $graphs; return $graphs;
} }
/** /**
* This method return a graph containing information about evaluations * This method return a graph containing information about evaluations
* inside courses in sessions, it's used inside get_block method for * inside courses in sessions, it's used inside get_block method for
* showing it inside dashboard interface * showing it inside dashboard interface
* @return string img html * @return string img html
*/ */
public function get_evaluations_courses_in_sessions_graph() public function get_evaluations_courses_in_sessions_graph()
{ {
$graphs = array(); $graphs = array();
if (!empty($this->sessions)) { if (!empty($this->sessions)) {
$session_ids = array_keys($this->sessions); $session_ids = array_keys($this->sessions);
foreach ($session_ids as $session_id) { foreach ($session_ids as $session_id) {
$courses_code = array_keys(Tracking::get_courses_list_from_session($session_id)); $courses_code = array_keys(Tracking::get_courses_list_from_session($session_id));
$courses_graph = array(); $courses_graph = array();
foreach ($courses_code as $course_code) { foreach ($courses_code as $course_code) {
$cats = Category::load(null, null, $course_code, null, null, $session_id); $cats = Category::load(null, null, $course_code, null, null, $session_id);
if (isset($cats) && isset($cats[0])) { if (isset($cats) && isset($cats[0])) {
$alleval = $cats[0]->get_evaluations(null, true, $course_code); $alleval = $cats[0]->get_evaluations(null, true, $course_code);
$alllinks = $cats[0]->get_links(null, true); $alllinks = $cats[0]->get_links(null, true);
$users = GradebookUtils::get_all_users($alleval, $alllinks); $users = GradebookUtils::get_all_users($alleval, $alllinks);
$datagen = new FlatViewDataGenerator($users, $alleval, $alllinks); $datagen = new FlatViewDataGenerator($users, $alleval, $alllinks);
$evaluation_sumary = $datagen->get_evaluation_sumary_results(); $evaluation_sumary = $datagen->get_evaluation_sumary_results();
if (!empty($evaluation_sumary)) { if (!empty($evaluation_sumary)) {
$items = array_keys($evaluation_sumary); $items = array_keys($evaluation_sumary);
$max = $min = $avg = array(); $max = $min = $avg = array();
foreach ($evaluation_sumary as $evaluation) { foreach ($evaluation_sumary as $evaluation) {
$max[] = $evaluation['max']; $max[] = $evaluation['max'];
$min[] = $evaluation['min']; $min[] = $evaluation['min'];
$avg[] = $evaluation['avg']; $avg[] = $evaluation['avg'];
} }
// Dataset definition // Dataset definition
$dataSet = new pData(); $dataSet = new pData();
$dataSet->addPoints($min, 'Serie3'); $dataSet->addPoints($min, 'Serie3');
@ -331,16 +338,21 @@ class BlockEvaluationGraph extends Block
$dataSet->setSerieDescription('Serie2', get_lang('Avg')); $dataSet->setSerieDescription('Serie2', get_lang('Avg'));
$dataSet->setSerieDescription('Serie3', get_lang('Min')); $dataSet->setSerieDescription('Serie3', get_lang('Min'));
$dataSet->setAbscissa('Labels'); $dataSet->setAbscissa('Labels');
$dataSet->setAbscissaName(get_lang('EvaluationName')); $dataSet->setAbscissaName(get_lang('EvaluationName'));
$dataSet->normalize(100, '%'); $dataSet->normalize(100, '%');
$dataSet->loadPalette(api_get_path(SYS_CODE_PATH).'palettes/pchart/default.color', true); $dataSet->loadPalette(api_get_path(SYS_CODE_PATH).'palettes/pchart/default.color', true);
// Cache definition // Cache definition
$cachePath = api_get_path(SYS_ARCHIVE_PATH); $cachePath = api_get_path(SYS_ARCHIVE_PATH);
$myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1))); $myCache = new pCache(
array(
'CacheFolder' => substr(
$cachePath,
0,
strlen($cachePath) - 1
),
)
);
$chartHash = $myCache->getHash($dataSet); $chartHash = $myCache->getHash($dataSet);
if ($myCache->isInCache($chartHash)) { if ($myCache->isInCache($chartHash)) {
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash; $imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash;
@ -455,14 +467,14 @@ class BlockEvaluationGraph extends Block
if (!empty($imgPath)) { if (!empty($imgPath)) {
$courses_graph[$course_code] = '<img src="'.$imgPath.'">'; $courses_graph[$course_code] = '<img src="'.$imgPath.'">';
} }
} }
} }
} }
if (!empty($courses_graph)) { if (!empty($courses_graph)) {
$graphs[$session_id] = $courses_graph; $graphs[$session_id] = $courses_graph;
} }
} }
} }
return $graphs; return $graphs;
} }
} }

@ -40,84 +40,84 @@ class BlockGlobalInfo extends Block
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) public function is_block_visible_for_user($user_id)
{ {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
* This method return content html containing information about courses and its position for showing it inside dashboard interface * 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 * it's important to use the name 'get_block' for beeing used from dashboard controller
* @return array column and content html * @return array column and content html
*/ */
public function get_block() public function get_block()
{ {
global $charset; global $charset;
$column = 2; $column = 2;
$data = array(); $data = array();
$content = $this->get_content_html(); $content = $this->get_content_html();
$html = ' $html = '<div class="panel panel-default" id="intro">
<div class="panel panel-default" id="intro"> <div class="panel-heading">'.get_lang('GlobalPlatformInformation').'
<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.'">
<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>
<em class="fa fa-times"></em> </a></div>
</a></div> </div>
</div> <div class="panel-body">
<div class="panel-body"> '.$content.'
'.$content.' </div>
</div> </div>
</div> ';
'; $data['column'] = $column;
$data['column'] = $column; $data['content_html'] = $html;
$data['content_html'] = $html;
return $data; return $data;
} }
/** /**
* This method return a content html, it's used inside get_block method for showing it inside dashboard interface * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
* @return string content html * @return string content html
*/ */
public function get_content_html() public function get_content_html()
{ {
$global_data = $this->get_global_information_data(); $global_data = $this->get_global_information_data();
//$content = '<div style="margin:10px;">'; $content = '<h4>'.get_lang('GlobalPlatformInformation').'</h4>';
$content = '<h4>'.get_lang('GlobalPlatformInformation').'</h4>'; $data_table = null;
$data_table = null; if (!empty($global_data)) {
if (!empty($global_data)) { $data_table = '<table class="table table-bordered" width="95%">';
$data_table = '<table class="table table-bordered" width="95%">'; $i = 1;
$i = 1; foreach ($global_data as $data) {
foreach ($global_data as $data) { if ($i % 2 == 0) {
if ($i % 2 == 0) { $class_tr = 'row_odd';
$class_tr = 'row_odd'; } else {
} else { $class_tr = 'row_even';
$class_tr = 'row_even'; }
} $data_table .= '<tr class="'.$class_tr.'">';
$data_table .= '<tr class="'.$class_tr.'">'; foreach ($data as $cell) {
foreach ($data as $cell) { $data_table .= '<td align="right">'.$cell.'</td>';
$data_table .= '<td align="right">'.$cell.'</td>'; }
} $data_table .= '</tr>';
$data_table .= '</tr>'; $i++;
$i++; }
} $data_table .= '</table>';
$data_table .= '</table>'; } else {
} else { $data_table .= get_lang('ThereIsNoInformationAboutThePlatform');
$data_table .= get_lang('ThereIsNoInformationAboutThePlatform'); }
} $content .= $data_table;
$content .= $data_table;
//$content .= '</div>'; //$content .= '</div>';
return $content; return $content;
} }
/** /**

@ -15,101 +15,92 @@
class BlockSession extends Block class BlockSession extends Block
{ {
private $user_id; private $user_id;
private $sessions; private $sessions;
private $path; private $path;
private $permission = array(DRH, SESSIONADMIN); private $permission = array(DRH, SESSIONADMIN);
/** /**
* Constructor * Constructor
*/ */
public function __construct($user_id) public function __construct($user_id)
{ {
$this->user_id = $user_id; $this->user_id = $user_id;
$this->path = 'block_session'; $this->path = 'block_session';
if ($this->is_block_visible_for_user($user_id)) { if ($this->is_block_visible_for_user($user_id)) {
$this->sessions = SessionManager::get_sessions_followed_by_drh($user_id); $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id);
} }
} }
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) public function is_block_visible_for_user($user_id)
{ {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
* This method return content html containing information about sessions and its position for showing it inside dashboard interface * This method return content html containing
* information about sessions and its position for showing it inside dashboard interface
* it's important to use the name 'get_block' for beeing used from dashboard controller * it's important to use the name 'get_block' for beeing used from dashboard controller
* @return array column and content html * @return array column and content html
*/ */
public function get_block() public function get_block()
{ {
global $charset;
global $charset; $column = 2;
$data = array();
$column = 2; $content = $this->get_content_html();
$data = array(); $content_html = '<div class="panel panel-default" id="intro">
<div class="panel-heading">
$content = $this->get_content_html(); '.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.'">
$content_html = ' <em class="fa fa-times"></em>
<div class="panel panel-default" id="intro"> </a></div>
<div class="panel-heading"> </div>
'.get_lang('SessionsInformation').' <div class="panel-body">
<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.'"> '.$content.'
<em class="fa fa-times"></em> </div>
</a></div> </div>
</div> ';
<div class="panel-body">
'.$content.' $data['column'] = $column;
</div> $data['content_html'] = $content_html;
</div>
'; return $data;
$data['column'] = $column;
$data['content_html'] = $content_html;
return $data;
} }
/** /**
* This method return a content html, it's used inside get_block method for showing it inside dashboard interface * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
* @return string content html * @return string content html
*/ */
public function get_content_html() public function get_content_html()
{ {
$content = '';
$content = ''; $sessions = $this->sessions;
$sessions = $this->sessions; $content .= '<h4>'.get_lang('YourSessionsList').'</h4>';
if (count($sessions) > 0) {
//$content = '<div style="margin:10px;">'; $sessions_table = '<table class="data_table" width:"95%">';
$content .= '<h4>'.get_lang('YourSessionsList').'</h4>'; $sessions_table .= '<tr>
<th >'.get_lang('Title').'</th>
if (count($sessions) > 0) { <th >'.get_lang('Date').'</th>
$sessions_table = '<table class="data_table" width:"95%">'; <th width="100px">'.get_lang('NbCoursesPerSession').'</th>
$sessions_table .= '<tr> </tr>';
<th >'.get_lang('Title').'</th> $i = 1;
<th >'.get_lang('Date').'</th> foreach ($sessions as $session) {
<th width="100px">'.get_lang('NbCoursesPerSession').'</th> $session_id = intval($session['id']);
</tr>'; $title = $session['name'];
$i = 1;
foreach ($sessions as $session) { if (!empty($session['access_start_date'])) {
$dateFrom = api_convert_and_format_date(
$session_id = intval($session['id']);
$title = $session['name'];
if (!empty($session['access_start_date'])) {
$dateFrom = api_convert_and_format_date(
$session['access_start_date'], $session['access_start_date'],
DATE_FORMAT_SHORT, DATE_FORMAT_SHORT,
date_default_timezone_get() date_default_timezone_get()
@ -121,44 +112,45 @@ class BlockSession extends Block
); );
$date = vsprintf(get_lang('FromDateXToDateY'), [$dateFrom, $dateUntil]); $date = vsprintf(get_lang('FromDateXToDateY'), [$dateFrom, $dateUntil]);
} else { } else {
$date = ' - '; $date = ' - ';
} }
$count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id)); $count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id));
if ($i % 2 == 0) $class_tr = 'row_odd'; if ($i % 2 == 0) {
else $class_tr = 'row_even'; $class_tr = 'row_odd';
} else {
$sessions_table .= '<tr class="'.$class_tr.'"> $class_tr = 'row_even';
<td>'.$title.'</td> }
<td align="center">'.$date.'</td>
<td align="center">'.$count_courses_in_session.'</td> $sessions_table .= '<tr class="'.$class_tr.'">
</tr>'; <td>'.$title.'</td>
$i++; <td align="center">'.$date.'</td>
} <td align="center">'.$count_courses_in_session.'</td>
$sessions_table .= '</table>'; </tr>';
$content .= $sessions_table; $i++;
} else { }
$content .= get_lang('ThereIsNoInformationAboutYourSessions'); $sessions_table .= '</table>';
} $content .= $sessions_table;
} else {
if (count($sessions) > 0) { $content .= get_lang('ThereIsNoInformationAboutYourSessions');
$content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/session.php">'.get_lang('SeeMore').'</a></div>'; }
}
if (count($sessions) > 0) {
//$content .= '</div>'; $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/session.php">'.get_lang('SeeMore').'</a></div>';
}
return $content;
} return $content;
}
/** /**
* Get number of sessions * Get number of sessions
* @return int * @return int
*/ */
function get_number_of_sessions() function get_number_of_sessions()
{ {
return count($this->sessions); return count($this->sessions);
} }
} }

@ -8,57 +8,58 @@
/** /**
* This class is used like controller for student block plugin, * This class is used like controller for student block plugin,
* the class name must be registered inside path.info file (e.g: controller = "BlockStudent"), so dashboard controller will be instantiate it * the class name must be registered inside path.info file
* (e.g: controller = "BlockStudent"), so dashboard controller will be instantiate it
* @package chamilo.dashboard * @package chamilo.dashboard
*/ */
class BlockStudent extends Block class BlockStudent extends Block
{ {
private $user_id; private $user_id;
private $students; private $students;
private $path; private $path;
private $permission = array(DRH); private $permission = array(DRH);
/** /**
* Constructor * Constructor
*/ */
public function __construct($user_id) public function __construct($user_id)
{ {
$this->user_id = $user_id; $this->user_id = $user_id;
$this->path = 'block_student'; $this->path = 'block_student';
if ($this->is_block_visible_for_user($user_id)) { if ($this->is_block_visible_for_user($user_id)) {
$this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT); $this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT);
} }
} }
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) public function is_block_visible_for_user($user_id)
{ {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
* This method return content html containing information about students and its position for showing it inside dashboard interface * This method return content html containing information
* about students and its position for showing it inside dashboard interface
* it's important to use the name 'get_block' for beeing used from dashboard controller * it's important to use the name 'get_block' for beeing used from dashboard controller
* @return array column and content html * @return array column and content html
*/ */
public function get_block() public function get_block()
{ {
global $charset; global $charset;
$column = 1; $column = 1;
$data = array(); $data = array();
$student_content_html = $this->get_students_content_html_for_drh(); $student_content_html = $this->get_students_content_html_for_drh();
$html = '<div class="panel panel-default" id="intro"> $html = '<div class="panel panel-default" id="intro">
<div class="panel-heading"> <div class="panel-heading">
'.get_lang('StudentsInformationsList').' '.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.'"> <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.'">
@ -70,173 +71,180 @@ class BlockStudent extends Block
'.$student_content_html.' '.$student_content_html.'
</div> </div>
</div>'; </div>';
$data['column'] = $column; $data['column'] = $column;
$data['content_html'] = $html; $data['content_html'] = $html;
return $data;
return $data;
} }
/** /**
* This method return a content html, it's used inside get_block method for showing it inside dashboard interface * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
* @return string content html * @return string content html
*/ */
public function get_students_content_html_for_platform_admin() public function get_students_content_html_for_platform_admin()
{ {
$students = $this->students; $students = $this->students;
//$content = '<div style="margin:10px;">'; $content = '<h4>'.get_lang('YourStudents').'</h4>';
$content = '<h4>'.get_lang('YourStudents').'</h4>';
$students_table = null; $students_table = null;
if (count($students) > 0) { if (count($students) > 0) {
$students_table .= '<table class="data_table">'; $students_table .= '<table class="data_table">';
$students_table .= '<tr> $students_table .= '<tr>
<th width="10%" rowspan="2">'.get_lang('FirstName').'</th> <th width="10%" rowspan="2">'.get_lang('FirstName').'</th>
<th width="10%" rowspan="2">'.get_lang('LastName').'</th> <th width="10%" rowspan="2">'.get_lang('LastName').'</th>
<th width="30%" colspan="2">'.get_lang('CourseInformation').'</th> <th width="30%" colspan="2">'.get_lang('CourseInformation').'</th>
</tr> </tr>
<tr> <tr>
<th width="10%">'.get_lang('Courses').'</th> <th width="10%">'.get_lang('Courses').'</th>
<th width="10%">'.get_lang('Time').'</th> <th width="10%">'.get_lang('Time').'</th>
</tr>'; </tr>';
$i = 1; $i = 1;
foreach ($students as $student) { foreach ($students as $student) {
$courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true);
$courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true); $count_courses = count($courses_by_user);
$count_courses = count($courses_by_user); $rowspan = $count_courses ? $count_courses + 1 : 2;
$rowspan = $count_courses ? $count_courses + 1 : 2;
if ($i % 2 == 0) {
if ($i % 2 == 0) {
$style = ' style="background-color:#F2F2F2" '; $style = ' style="background-color:#F2F2F2" ';
} else { } else {
$style = ' style="background-color:#FFF" '; $style = ' style="background-color:#FFF" ';
} }
$students_table .= '<tr '.$style.'> $students_table .= '<tr '.$style.'>
<td rowspan="'.$rowspan.'">'.$student['firstname'].'</td> <td rowspan="'.$rowspan.'">'.$student['firstname'].'</td>
<td rowspan="'.$rowspan.'">'.$student['lastname'].'</td> <td rowspan="'.$rowspan.'">'.$student['lastname'].'</td>
</tr>'; </tr>';
// courses information about the student // courses information about the student
if (!empty($courses_by_user)) { if (!empty($courses_by_user)) {
foreach ($courses_by_user as $course) { foreach ($courses_by_user as $course) {
$course_code = $course['code']; $course_code = $course['code'];
$courseInfo = api_get_course_info($course_code); $courseInfo = api_get_course_info($course_code);
$courseId = $courseInfo['real_id']; $courseId = $courseInfo['real_id'];
$course_title = $course['title']; $course_title = $course['title'];
$time = api_time_to_hms(Tracking::get_time_spent_on_the_course($student['user_id'], $courseId)); $time = api_time_to_hms(Tracking::get_time_spent_on_the_course($student['user_id'], $courseId));
$students_table .= '<tr '.$style.'> $students_table .= '<tr '.$style.'>
<td align="right">'.$course_title.'</td> <td align="right">'.$course_title.'</td>
<td align="right">'.$time.'</td> <td align="right">'.$time.'</td>
</tr>'; </tr>';
} }
} else { } else {
$students_table .= '<tr '.$style.'> $students_table .= '<tr '.$style.'>
<td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td> <td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td>
</tr>'; </tr>';
} }
$i++; $i++;
} }
$students_table .= '</table>'; $students_table .= '</table>';
} else { } else {
$students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
} }
$content .= $students_table; $content .= $students_table;
if (count($students) > 0) { 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 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>'; //$content .= '</div>';
return $content; return $content;
} }
public function get_students_content_html_for_drh() { /**
$attendance = new Attendance(); * @return string
$students = $this->students; */
//$content = '<div style="margin:5px;">'; public function get_students_content_html_for_drh()
$content = '<h4>'.get_lang('YourStudents').'</h4>'; {
$attendance = new Attendance();
$students = $this->students;
$content = '<h4>'.get_lang('YourStudents').'</h4>';
$students_table = null; $students_table = null;
if (count($students) > 0) { if (count($students) > 0) {
$students_table .= '<table class="data_table">'; $students_table .= '<table class="data_table">';
$students_table .= '<tr> $students_table .= '<tr>
<th>'.get_lang('User').'</th> <th>'.get_lang('User').'</th>
<th>'.get_lang('AttendancesFaults').'</th> <th>'.get_lang('AttendancesFaults').'</th>
<th>'.get_lang('Evaluations').'</th> <th>'.get_lang('Evaluations').'</th>
</tr>'; </tr>';
$i = 1; $i = 1;
foreach ($students as $student) { foreach ($students as $student) {
$student_id = $student['user_id'];
$student_id = $student['user_id']; $firstname = $student['firstname'];
$firstname = $student['firstname']; $lastname = $student['lastname'];
$lastname = $student['lastname']; $username = $student['username'];
$username = $student['username']; // get average of faults in attendances by student
$results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
if (!empty($results_faults_avg)) {
// get average of faults in attendances by student $attendances_faults_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>';
$results_faults_avg = $attendance->get_faults_average_inside_courses($student_id); } else {
if (!empty($results_faults_avg)) { $attendances_faults_avg = '0%';
$attendances_faults_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>'; }
} else {
$attendances_faults_avg = '0%'; $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
} $evaluations_avg = 0;
$score = $weight = 0;
$courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true); foreach ($courses_by_user as $course) {
$evaluations_avg = 0; $course_code = $course['code'];
$score = $weight = 0; $cats = Category::load(
foreach ($courses_by_user as $course) { null,
$course_code = $course['code']; null,
$cats = Category::load(null, null, $course_code, null, null, null, false); $course_code,
$scoretotal = array(); null,
if (isset($cats) && isset($cats[0])) { null,
$scoretotal = $cats[0]->calc_score($student_id, null, $course_code); null,
} false
);
if (!empty($scoretotal)) { $scoretotal = array();
$score += $scoretotal[0]; if (isset($cats) && isset($cats[0])) {
$weight += $scoretotal[1]; $scoretotal = $cats[0]->calc_score($student_id, null, $course_code);
} }
}
if (!empty($scoretotal)) {
if (!empty($weight)) { $score += $scoretotal[0];
$evaluations_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.round($score, 2).'/'.round($weight, 2).'('.round(($score / $weight) * 100, 2).' %)</a>'; $weight += $scoretotal[1];
} }
}
if ($i % 2 == 0) {
if (!empty($weight)) {
$evaluations_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.round($score, 2).'/'.round($weight, 2).'('.round(($score / $weight) * 100, 2).' %)</a>';
}
if ($i % 2 == 0) {
$class_tr = 'row_odd'; $class_tr = 'row_odd';
} else { } else {
$class_tr = 'row_even'; $class_tr = 'row_even';
} }
$students_table .= '<tr class="'.$class_tr.'"> $students_table .= '<tr class="'.$class_tr.'">
<td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td> <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
<td>'.$attendances_faults_avg.'</td> <td>'.$attendances_faults_avg.'</td>
<td>'.$evaluations_avg.'</td> <td>'.$evaluations_avg.'</td>
</tr>'; </tr>';
$i++; $i++;
} }
$students_table .= '</table>'; $students_table .= '</table>';
} else { } else {
$students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
} }
$content .= $students_table; $content .= $students_table;
if (count($students) > 0) { if (count($students) > 0) {
$content .= '<div style="text-align:right;margin-top:10px;"> $content .= '<div style="text-align:right;margin-top:10px;">
<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a> <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a>
</div>'; </div>';
} }
//$content .= '</div>'; //$content .= '</div>';
return $content; return $content;
} }
/** /**
* Get number of students * Get number of students
* @return int * @return int
*/ */
function get_number_of_students() function get_number_of_students()
{ {
return count($this->students); return count($this->students);
} }
} }

@ -15,47 +15,47 @@ use CpChart\Chart\Cache as pCache;
/** /**
* This class is used like controller for student graph block plugin, * This class is used like controller for student graph block plugin,
* the class name must be registered inside path.info file (e.g: controller = "BlockStudentGraph"), so dashboard controller will be instantiate it * the class name must be registered inside path.info file
* (e.g: controller = "BlockStudentGraph"), so dashboard controller will be instantiate it
* @package chamilo.dashboard * @package chamilo.dashboard
*/ */
class BlockStudentGraph extends Block class BlockStudentGraph extends Block
{ {
private $user_id; private $user_id;
private $students; private $students;
private $path; private $path;
private $permission = array(DRH); private $permission = array(DRH);
/** /**
* Constructor * Constructor
*/ */
public function __construct($user_id) public function __construct($user_id)
{ {
$this->user_id = $user_id; $this->user_id = $user_id;
$this->path = 'block_student_graph'; $this->path = 'block_student_graph';
if ($this->is_block_visible_for_user($user_id)) { if ($this->is_block_visible_for_user($user_id)) {
/*if (api_is_platform_admin()) { /*if (api_is_platform_admin()) {
$this->students = UserManager::get_user_list(array('status' => STUDENT)); $this->students = UserManager::get_user_list(array('status' => STUDENT));
} else if (api_is_drh()) {*/ } else if (api_is_drh()) {*/
$this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT); $this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT);
//} //}
} }
} }
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) public function is_block_visible_for_user($user_id)
{ {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
@ -66,70 +66,66 @@ class BlockStudentGraph extends Block
*/ */
public function get_block() public function get_block()
{ {
global $charset;
global $charset; $column = 1;
$column = 1; $data = array();
$data = array(); $students_attendance_graph = $this->get_students_attendance_graph();
$students_attendance_graph = $this->get_students_attendance_graph();
$html = '<div class="panel panel-default" id="intro">
$html = '<div class="panel panel-default" id="intro"> <div class="panel-heading">
<div class="panel-heading"> '.get_lang('StudentsInformationsGraph').'
'.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.'">
<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>
<em class="fa fa-times"></em> </a></div>
</a></div> </div>
</div> <div class="panel-body" align="center">
<div class="panel-body" align="center"> <div style="padding:10px;"><strong>'.get_lang('AttendancesFaults').'</strong></div>
<div style="padding:10px;"><strong>'.get_lang('AttendancesFaults').'</strong></div> '.$students_attendance_graph.'
'.$students_attendance_graph.' </div>
</div> </div>';
</div>'; $data['column'] = $column;
$data['column'] = $column; $data['content_html'] = $html;
$data['content_html'] = $html; return $data;
return $data;
} }
/** /**
* This method return a graph containing information about students evaluation, * This method return a graph containing information about students evaluation,
* it's used inside get_block method for showing it inside dashboard interface * it's used inside get_block method for showing it inside dashboard interface
* @return string img html * @return string img html
*/ */
public function get_students_attendance_graph() public function get_students_attendance_graph()
{ {
$students = $this->students;
$attendance = new Attendance();
// get data
$attendances_faults_avg = array();
if (is_array($students) && count($students) > 0) {
foreach ($students as $student) {
$student_id = $student['user_id'];
//$student_info = api_get_user_info($student_id);
// get average of faults in attendances by student
$results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
if (!empty($results_faults_avg)) {
$attendances_faults_avg[$student['lastname']] = $results_faults_avg['porcent'];
} else {
$attendances_faults_avg[$student['lastname']] = 0;
}
}
}
$students = $this->students; arsort($attendances_faults_avg);
$attendance = new Attendance(); $usernames = array_keys($attendances_faults_avg);
// get data
$attendances_faults_avg = array();
if (is_array($students) && count($students) > 0) {
foreach ($students as $student) {
$student_id = $student['user_id'];
//$student_info = api_get_user_info($student_id);
// get average of faults in attendances by student
$results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
if (!empty($results_faults_avg)) {
$attendances_faults_avg[$student['lastname']] = $results_faults_avg['porcent'];
} else {
$attendances_faults_avg[$student['lastname']] = 0;
}
}
}
arsort($attendances_faults_avg);
$usernames = array_keys($attendances_faults_avg);
$faults = array();
foreach ($usernames as $username) {
$faults[] = $attendances_faults_avg[$username];
}
$graph = '';
$img_file = '';
if (is_array($usernames) && count($usernames) > 0) { $faults = array();
foreach ($usernames as $username) {
$faults[] = $attendances_faults_avg[$username];
}
$graph = '';
$img_file = '';
if (is_array($usernames) && count($usernames) > 0) {
// Defining data // Defining data
$dataSet = new pData(); $dataSet = new pData();
$dataSet->addPoints($faults, 'Serie1'); $dataSet->addPoints($faults, 'Serie1');
@ -152,14 +148,21 @@ class BlockStudentGraph extends Block
); );
// Cache definition // Cache definition
$cachePath = api_get_path(SYS_ARCHIVE_PATH); $cachePath = api_get_path(SYS_ARCHIVE_PATH);
$myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1))); $myCache = new pCache(
array(
'CacheFolder' => substr(
$cachePath,
0,
strlen($cachePath) - 1
),
)
);
$chartHash = $myCache->getHash($dataSet); $chartHash = $myCache->getHash($dataSet);
if ($myCache->isInCache($chartHash)) { if ($myCache->isInCache($chartHash)) {
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash; $imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash;
$myCache->saveFromCache($chartHash, $imgPath); $myCache->saveFromCache($chartHash, $imgPath);
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; $imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
} else { } else {
$maxCounts = max(count($usernames), count($faults)); $maxCounts = max(count($usernames), count($faults));
if ($maxCounts < 5) { if ($maxCounts < 5) {
$heightSize = 200; $heightSize = 200;
@ -233,19 +236,19 @@ class BlockStudentGraph extends Block
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; $imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
} }
$graph = '<img src="'.$imgPath.'" >'; $graph = '<img src="'.$imgPath.'" >';
} else { } else {
$graph = '<p>'.api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8').'</p>'; $graph = '<p>'.api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8').'</p>';
} }
return $graph; return $graph;
} }
/** /**
* Get number of students * Get number of students
* @return int * @return int
*/ */
function get_number_of_students() function get_number_of_students()
{ {
return count($this->students); return count($this->students);
} }
} }

@ -62,7 +62,6 @@ class BlockTeacher extends Block
$column = 1; $column = 1;
$data = array(); $data = array();
$teacher_content_html = $this->get_teachers_content_html_for_drh(); $teacher_content_html = $this->get_teachers_content_html_for_drh();
$html = ' $html = '
<div class="panel panel-default" id="intro"> <div class="panel panel-default" id="intro">
<div class="panel-heading"> <div class="panel-heading">
@ -139,8 +138,6 @@ class BlockTeacher extends Block
<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin">'.get_lang('SeeMore').'</a></div>'; <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin">'.get_lang('SeeMore').'</a></div>';
} }
//$content .= '</div>';
return $content; return $content;
} }

@ -26,32 +26,32 @@ class BlockTeacherGraph extends Block
private $path; private $path;
private $permission = array(DRH); private $permission = array(DRH);
/** /**
* Controller * Controller
*/ */
public function __construct($user_id) public function __construct($user_id)
{ {
$this->user_id = $user_id; $this->user_id = $user_id;
$this->path = 'block_teacher_graph'; $this->path = 'block_teacher_graph';
if ($this->is_block_visible_for_user($user_id)) { if ($this->is_block_visible_for_user($user_id)) {
$this->teachers = UserManager::get_users_followed_by_drh($user_id, COURSEMANAGER); $this->teachers = UserManager::get_users_followed_by_drh($user_id, COURSEMANAGER);
} }
} }
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) public function is_block_visible_for_user($user_id)
{ {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
@ -61,11 +61,11 @@ class BlockTeacherGraph extends Block
*/ */
public function get_block() public function get_block()
{ {
global $charset; global $charset;
$column = 1; $column = 1;
$data = array(); $data = array();
$teacher_information_graph = $this->get_teachers_information_graph(); $teacher_information_graph = $this->get_teachers_information_graph();
$html = ' $html = '
<div class="panel panel-default" id="intro"> <div class="panel panel-default" id="intro">
<div class="panel-heading">'.get_lang('TeachersInformationsGraph').' <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.'"> <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.'">
@ -77,55 +77,58 @@ class BlockTeacherGraph extends Block
'.$teacher_information_graph.' '.$teacher_information_graph.'
</div> </div>
</div> </div>
'; ';
$data['column'] = $column;
$data['content_html'] = $html;
return $data; $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 * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
* @return string content html * @return string content html
*/ */
public function get_teachers_information_graph() public function get_teachers_information_graph()
{ {
$teachers = $this->teachers; $teachers = $this->teachers;
$graph = ''; $graph = '';
$user_ids = array_keys($teachers);
$user_ids = array_keys($teachers); $a_last_week = get_last_week();
$a_last_week = get_last_week();
if (is_array($user_ids) && count($user_ids) > 0) {
if (is_array($user_ids) && count($user_ids) > 0) { $dataSet = new pData;
$dataSet = new pData; foreach ($user_ids as $user_id) {
foreach ($user_ids as $user_id) { $teacher_info = api_get_user_info($user_id);
$teacher_info = api_get_user_info($user_id); $username = $teacher_info['username'];
$username = $teacher_info['username']; $time_by_days = array();
$time_by_days = array(); foreach ($a_last_week as $day) {
foreach ($a_last_week as $day) { // day is received as y-m-d 12:00:00
// day is received as y-m-d 12:00:00 $start_date = api_get_utc_datetime($day);
$start_date = api_get_utc_datetime($day); $end_date = api_get_utc_datetime($day + (3600 * 24 - 1));
$end_date = api_get_utc_datetime($day + (3600 * 24 - 1));
$time_on_platform_by_day = Tracking::get_time_spent_on_the_platform(
$time_on_platform_by_day = Tracking::get_time_spent_on_the_platform($user_id, 'custom', $start_date, $end_date); $user_id,
$hours = floor($time_on_platform_by_day / 3600); 'custom',
$min = floor(($time_on_platform_by_day - ($hours * 3600)) / 60); $start_date,
$time_by_days[] = $min; $end_date
} );
$dataSet->addPoints($time_by_days, $username); $hours = floor($time_on_platform_by_day / 3600);
} $min = floor(($time_on_platform_by_day - ($hours * 3600)) / 60);
$time_by_days[] = $min;
$last_week = date('Y-m-d', $a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]); }
$days_on_week = array(); $dataSet->addPoints($time_by_days, $username);
foreach ($a_last_week as $weekday) { }
$days_on_week[] = date('d/m', $weekday);
} $last_week = date('Y-m-d', $a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
$days_on_week = array();
$dataSet->addPoints($days_on_week, 'Days'); foreach ($a_last_week as $weekday) {
$dataSet->setAbscissaName($last_week); $days_on_week[] = date('d/m', $weekday);
$dataSet->setAxisName(0, get_lang('Minutes')); }
$dataSet->addPoints($days_on_week, 'Days');
$dataSet->setAbscissaName($last_week);
$dataSet->setAxisName(0, get_lang('Minutes'));
$dataSet->setAbscissa('Days'); $dataSet->setAbscissa('Days');
$dataSet->loadPalette(api_get_path(SYS_CODE_PATH).'palettes/pchart/default.color', true); $dataSet->loadPalette(api_get_path(SYS_CODE_PATH).'palettes/pchart/default.color', true);
@ -138,12 +141,10 @@ class BlockTeacherGraph extends Block
$myCache->saveFromCache($chartHash, $imgPath); $myCache->saveFromCache($chartHash, $imgPath);
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; $imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
} else { } else {
/* Create the pChart object */ /* Create the pChart object */
$widthSize = 440; $widthSize = 440;
$heightSize = 350; $heightSize = 350;
$angle = 50; $angle = 50;
$myPicture = new pImage($widthSize, $heightSize, $dataSet); $myPicture = new pImage($widthSize, $heightSize, $dataSet);
/* Turn of Antialiasing */ /* Turn of Antialiasing */
@ -194,20 +195,20 @@ class BlockTeacherGraph extends Block
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; $imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
} }
$graph = '<img src="'.$imgPath.'" >'; $graph = '<img src="'.$imgPath.'" >';
} else { } else {
$graph = '<p>'.api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8').'</p>'; $graph = '<p>'.api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8').'</p>';
} }
return $graph; return $graph;
} }
/** /**
* Get number of teachers * Get number of teachers
* @return int * @return int
*/ */
function get_number_of_teachers() function get_number_of_teachers()
{ {
return count($this->teachers); return count($this->teachers);
} }
} }

Loading…
Cancel
Save