user_id = $user_id;
$this->path = 'block_session';
if ($this->is_block_visible_for_user($user_id)) {
/*if (api_is_platform_admin()) {
$this->sessions = SessionManager::get_sessions_list();
} else {*/
$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
* @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 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
* @return array column and content html
*/
public function get_block() {
global $charset;
$column = 2;
$data = array();
$content = $this->get_content_html();
$content_html = '
'.$content.'
';
$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
* @return string content html
*/
public function get_content_html() {
$content = '';
$sessions = $this->sessions;
$content = '';
$content .= '
'.get_lang('YourSessionsList').'
';
if (count($sessions) > 0) {
$sessions_table = '
';
$sessions_table .= '
'.get_lang('Title').' |
'.get_lang('Date').' |
'.get_lang('NbCoursesPerSession').' |
';
$i = 1;
foreach ($sessions as $session) {
$session_id = intval($session['id']);
$title = $session['name'];
if ($session['date_start'] != '0000-00-00' && $session['date_end'] != '0000-00-00') {
$date = get_lang('From').' '.api_convert_and_format_date($session['date_start'], DATE_FORMAT_SHORT, date_default_timezone_get()).' '.get_lang('To').' '.api_convert_and_format_date($session['date_end'], DATE_FORMAT_SHORT, date_default_timezone_get());
} else {
$date = ' - ';
}
$count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id));
if ($i%2 == 0) $class_tr = 'row_odd';
else $class_tr = 'row_even';
$sessions_table .= '
'.$title.' |
'.$date.' |
'.$count_courses_in_session.' |
';
$i++;
}
$sessions_table .= '
';
$content .= $sessions_table;
} else {
$content .= get_lang('ThereIsNoInformationAboutYourSessions');
}
if (count($sessions) > 0) {
$content .= '
';
}
$content .= '
';
return $content;
}
/**
* Get number of sessions
* @return int
*/
function get_number_of_sessions() {
return count($this->sessions);
}
}