| Línea 21... |
Línea 21... |
| 21 |
$sql .= "ORDER BY timecreated DESC LIMIT 1";
|
21 |
$sql .= "ORDER BY timecreated DESC LIMIT 1";
|
| Línea 22... |
Línea 22... |
| 22 |
|
22 |
|
| Línea 23... |
Línea 23... |
| 23 |
$lastcourse = $DB->get_record_sql($sql, ['userid' => $userid]);
|
23 |
$lastcourse = $DB->get_record_sql($sql, ['userid' => $userid]);
|
| 24 |
|
24 |
|
| Línea 25... |
Línea 25... |
| 25 |
if ($lastcourse) {
|
25 |
if ($lastcourse) {
|
| - |
|
26 |
$course = get_course($lastcourse->id);
|
| 26 |
$course = get_course($lastcourse->courseid);
|
27 |
|
| - |
|
28 |
if ($course) {
|
| 27 |
|
29 |
if ($course instanceof stdClass) {
|
| 28 |
if ($course) {
|
30 |
$courseInList = new core_course_list_element($course);
|
| 29 |
$courseInList = new core_course_list_element($course);
|
31 |
}
|
| 30 |
|
32 |
|
| 31 |
// Manejo de imagen
|
33 |
// Obtener la imagen del curso o usar la imagen por defecto
|
| 32 |
$image = $url_noimage;
|
34 |
$image = $url_noimage;
|
| 33 |
foreach ($courseInList->get_course_overviewfiles() as $file) {
|
35 |
foreach ($courseInList->get_course_overviewfiles() as $file) {
|
| 34 |
if ($file->is_valid_image()) {
|
36 |
if ($file->is_valid_image()) {
|
| 35 |
$image = file_encode_url("{$CFG->wwwroot}/pluginfile.php", "/{$file->get_contextid()}/{$file->get_component()}/{$file->get_filearea()}{$file->get_filepath()}{$file->get_filename()}");
|
37 |
$image = file_encode_url("{$CFG->wwwroot}/pluginfile.php", "/{$file->get_contextid()}/{$file->get_component()}/{$file->get_filearea()}{$file->get_filepath()}{$file->get_filename()}");
|
| 36 |
break;
|
38 |
break;
|
| - |
|
39 |
}
|
| - |
|
40 |
}
|
| - |
|
41 |
|
| - |
|
42 |
// Obtener el último acceso al curso por el usuario
|
| - |
|
43 |
$sql = "SELECT timecreated FROM {logstore_standard_log} WHERE courseid = :courseid AND userid = :userid ";
|
| - |
|
44 |
$sql .= "AND eventname = '\\\\core\\\\event\\\\course_viewed' ORDER BY id DESC LIMIT 1";
|
| 37 |
}
|
45 |
$timecreated = $DB->get_field_sql($sql, ['courseid' => $course->id, 'userid' => $userid]);
|
| - |
|
46 |
$lastaccess = $timecreated ? date('d/m/Y h:i a', $timecreated) : null;
|
| - |
|
47 |
|
| - |
|
48 |
// Obtener el progreso del usuario en el curso
|
| - |
|
49 |
$progress = progress::get_course_progress_percentage($course);
|
| - |
|
50 |
$progress = $progress ? floatval($progress) : 0.0;
|
| - |
|
51 |
$miProgreso = number_format($progress, 2);
|
| 38 |
}
|
52 |
|
| - |
|
53 |
// Verificar roles del usuario en el curso
|
| - |
|
54 |
$course_context = context_course::instance($course->id);
|
| 39 |
|
55 |
$roles = get_user_roles($course_context, $USER->id, true);
|
| - |
|
56 |
$completion_edit_curso = false;
|
| - |
|
57 |
foreach ($roles as $role) {
|
| - |
|
58 |
if ($role->shortname == 'companydepartmentmanager' || $role->shortname == 'companycoursenoneditor') {
|
| - |
|
59 |
$completion_edit_curso = true;
|
| - |
|
60 |
break;
|
| - |
|
61 |
}
|
| - |
|
62 |
}
|
| - |
|
63 |
|
| - |
|
64 |
// Si el usuario tiene ciertos roles, forzar la URL al curso
|
| 40 |
// Obtener categoría
|
65 |
if ($completion_edit_curso) {
|
| 41 |
$category = $DB->get_record('course_categories', ['id' => $course->category]);
|
66 |
$linkurl = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
|
| 42 |
$categoryName = $category ? $category->name : get_string('unknowncategory', 'block_cesa_lastcourse');
|
67 |
}
|
| 43 |
|
68 |
|
| 44 |
// Obtener primera sección (número)
|
69 |
// Obtener la primera sección visible del curso
|
| 45 |
$first_section_number = 0;
|
70 |
$first_section = 0;
|
| 46 |
$sections = $DB->get_records('course_sections', ['course' => $course->id], 'section ASC', 'id, section, sequence, visible');
|
71 |
$sections = $DB->get_records('course_sections', ['course' => $course->id], 'section ASC', 'id,name,section,sequence,visible');
|
| 47 |
foreach ($sections as $section) {
|
72 |
foreach ($sections as $section) {
|
| 48 |
if ($section->section > 0) {
|
73 |
if (!empty($section->section)) {
|
| 49 |
$first_section_number = $section->section;
|
74 |
$first_section = $section->id;
|
| 50 |
break;
|
75 |
break;
|
| 51 |
}
|
76 |
}
|
| 52 |
}
|
- |
|
| 53 |
|
77 |
}
|
| - |
|
78 |
|
| 54 |
// Buscar módulo en la primera sección
|
79 |
// Obtener el primer módulo visible del curso
|
| 55 |
$linkurl = '';
|
80 |
$modules = get_fast_modinfo($course->id)->get_cms();
|
| - |
|
81 |
$linkurl = '';
|
| - |
|
82 |
foreach ($modules as $module) {
|
| - |
|
83 |
if (!$module->uservisible || $module->is_stealth() || empty($module->url) || empty($module->section)) {
|
| - |
|
84 |
continue;
|
| 56 |
$modules = get_fast_modinfo($course->id)->get_cms();
|
85 |
}
|
| 57 |
foreach ($modules as $module) {
|
86 |
|
| 58 |
if ($module->uservisible && !$module->is_stealth() && $module->url && $module->section == $first_section_number) {
|
87 |
if ($module->section == $first_section || $completion_edit_curso) {
|
| 59 |
$linkurl = new moodle_url($module->url, ['forceview' => 1]);
|
88 |
$linkurl = new moodle_url($module->url, ['forceview' => 1]);
|
| Línea 60... |
Línea -... |
| 60 |
break;
|
- |
|
| 61 |
}
|
89 |
break;
|
| 62 |
}
|
90 |
}
|
| 63 |
|
- |
|
| Línea 64... |
Línea 91... |
| 64 |
// Si el usuario tiene ciertos roles, forzar la URL al curso
|
91 |
}
|
| 65 |
if ($completion_edit_curso) {
|
92 |
|
| 66 |
$linkurl = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
|
93 |
// Obtener categoría
|
| 67 |
}
|
94 |
$category = $DB->get_record('course_categories', ['id' => $course->category]);
|
| Línea 96... |
Línea 123... |
| 96 |
'timeaccess' => $lastaccess,
|
123 |
'timeaccess' => $lastaccess,
|
| 97 |
'viewurl' => $CFG->wwwroot . '/course/view.php?id=' . $course->id,
|
124 |
'viewurl' => $CFG->wwwroot . '/course/view.php?id=' . $course->id,
|
| 98 |
'viewurlnew' => $linkurl,
|
125 |
'viewurlnew' => $linkurl,
|
| 99 |
'visible' => true,
|
126 |
'visible' => true,
|
| 100 |
];
|
127 |
];
|
| - |
|
128 |
}
|
| 101 |
}
|
129 |
}
|
| Línea 102... |
Línea 130... |
| 102 |
|
130 |
|
| 103 |
// Renderizar la plantilla con los datos del curso
|
131 |
// Renderizar la plantilla con los datos del curso
|
| 104 |
return $this->render_from_template('block_cesa_lastcourse/full', $data);
|
132 |
return $this->render_from_template('block_cesa_lastcourse/full', $data);
|