user_id = $user_id;
$this->path = 'block_course';
if ($this->is_block_visible_for_user($user_id)) {
/*if (api_is_platform_admin()) {
$this->courses = CourseManager::get_real_course_list();
} else {*/
$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 = '
'.$content.'
';
$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() {
$course_data = $this->get_course_information_data();
$content = '';
$content .= '
'.get_lang('YourCourseList').'
';
if (!empty($course_data)) {
$data_table = '
';
$data_table .= '
| '.get_lang('CourseTitle').' |
'.get_lang('NbStudents').' |
'.get_lang('AvgTimeSpentInTheCourse').' |
'.get_lang('ThematicAdvance').' |
';
$i = 1;
foreach ($course_data as $course) {
if ($i%2 == 0) $class_tr = 'row_odd';
else $class_tr = 'row_even';
$data_table .= '';
foreach ($course as $cell) {
$data_table .= '| '.$cell.' | ';
}
$data_table .= '
';
$i++;
}
$data_table .= '
';
} else {
$data_table .= get_lang('ThereIsNoInformationAboutYourCourses');
}
$content .= $data_table;
if (!empty($course_data)) {
$content .= '
';
}
$content .= '
';
return $content;
}
/**
* Get number of courses
* @return int
*/
function get_number_of_courses() {
return count($this->courses);
}
/**
* Get course information data
* @return array
*/
function get_course_information_data() {
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$a_course_students = array();
$course_data = array();
$courses = $this->courses;
$course_description = new CourseDescription();
foreach ($courses as $row_course) {
$course_code = $row_course['code'];
$avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0;
// students directly subscribed to the course
$sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code'";
$rs = Database::query($sql);
$users = array();
while ($row = Database::fetch_array($rs)) {
$users[] = $row['user_id'];
}
if (count($users) > 0) {
$nb_students_in_course = count($users);
$avg_time_spent_in_course = api_time_to_hms(Tracking::get_time_spent_on_the_course($users, $course_code)/$nb_students_in_course);
} else {
$avg_time_spent_in_course = null;
}
$tematic_advance_progress = 0;
$course_description->set_session_id(0);
$tematic_advance = $course_description->get_data_by_description_type(8, $course_code);
if (!empty($tematic_advance)) {
$tematic_advance_progress = ''.$tematic_advance['progress'].'%';
} else {
$tematic_advance_progress = '0%';
}
$table_row = array();
$table_row[] = $row_course['title'];
$table_row[] = $nb_students_in_course;
$table_row[] = $avg_time_spent_in_course;
$table_row[] = $tematic_advance_progress;
$course_data[] = $table_row;
}
return $course_data;
}
}
?>