1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
defined('MOODLE_INTERNAL') || die();
|
|
|
4 |
|
|
|
5 |
use core_completion\progress;
|
|
|
6 |
|
1231 |
ariadna |
7 |
class block_cesa_lastcourse_renderer extends plugin_renderer_base
|
|
|
8 |
{
|
1 |
efrain |
9 |
|
1231 |
ariadna |
10 |
public function procesar()
|
|
|
11 |
{
|
|
|
12 |
|
1 |
efrain |
13 |
global $USER, $DB, $CFG, $PAGE;
|
1231 |
ariadna |
14 |
|
|
|
15 |
|
1 |
efrain |
16 |
$userid = $USER->id;
|
|
|
17 |
$url_noimage = $CFG->wwwroot . '/theme/' . $PAGE->theme->name . '/pix/coursenoimage.jpg';
|
1231 |
ariadna |
18 |
|
1 |
efrain |
19 |
$data = [
|
|
|
20 |
'course' => ''
|
|
|
21 |
];
|
1231 |
ariadna |
22 |
|
|
|
23 |
|
1 |
efrain |
24 |
$sql = "SELECT DISTINCT(courseid) AS courseid FROM {logstore_standard_log} WHERE ";
|
|
|
25 |
$sql .= "action = 'viewed' AND target IN ('course', 'course_module') AND userid = $userid ";
|
|
|
26 |
$sql .= "GROUP BY courseid ORDER BY timecreated DESC ";
|
1231 |
ariadna |
27 |
|
|
|
28 |
|
|
|
29 |
$courseid = null;
|
|
|
30 |
|
|
|
31 |
|
1 |
efrain |
32 |
$lastcourses = $DB->get_records_sql($sql);
|
1231 |
ariadna |
33 |
foreach ($lastcourses as $lastcourse) {
|
1 |
efrain |
34 |
//$course = get_course($lastcourse->courseid);
|
1231 |
ariadna |
35 |
|
|
|
36 |
$course = $DB->get_record('course', array('id' => $lastcourse->courseid));
|
|
|
37 |
|
|
|
38 |
if (!$course || !$course->visible) {
|
1 |
efrain |
39 |
continue;
|
|
|
40 |
}
|
1231 |
ariadna |
41 |
|
|
|
42 |
$category = $DB->get_record('course_categories', array('id' => $course->category));
|
|
|
43 |
if (!$category || !$category->visible) {
|
1 |
efrain |
44 |
continue;
|
|
|
45 |
}
|
1231 |
ariadna |
46 |
|
1 |
efrain |
47 |
$courseid = $course->id;
|
|
|
48 |
}
|
1231 |
ariadna |
49 |
|
|
|
50 |
if ($courseid) {
|
|
|
51 |
$course = get_course($courseid);
|
|
|
52 |
|
|
|
53 |
if ($course instanceof stdClass) {
|
|
|
54 |
$courseInList = new core_course_list_element($course);
|
|
|
55 |
}
|
|
|
56 |
$image = $url_noimage;
|
|
|
57 |
foreach ($courseInList->get_course_overviewfiles() as $file) {
|
|
|
58 |
$isimage = $file->is_valid_image();
|
|
|
59 |
$image = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
|
|
|
60 |
if (!$isimage) {
|
|
|
61 |
$image = $url_noimage;
|
1 |
efrain |
62 |
}
|
1231 |
ariadna |
63 |
}
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
$lastaccess = null;
|
|
|
67 |
$sql = "select timecreated from {logstore_standard_log} where courseid = :courseid and userid = :userid " .
|
|
|
68 |
" and eventname = '\\\\core\\\\event\\\\course_viewed' order by id desc limit 1 ";
|
|
|
69 |
|
|
|
70 |
$timecreated = $DB->get_field_sql($sql, array('courseid' => $course->id, 'userid' => $userid));
|
|
|
71 |
if ($timecreated) {
|
|
|
72 |
|
|
|
73 |
$lastaccess = date('d/m/Y h:i a', $timecreated);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
$category = $DB->get_record('course_categories', array('id' => $course->category));
|
|
|
77 |
|
|
|
78 |
$progress = progress::get_course_progress_percentage($course);
|
|
|
79 |
$progress = $progress ? floatval($progress) : 0.0;
|
|
|
80 |
$miProgreso = number_format($progress, 2); // Progreso por curso
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
$first_section = 0;
|
|
|
84 |
$sections = $DB->get_records('course_sections', ['course' => $course->id], 'section ASC', 'id,name,section,sequence,visible');
|
|
|
85 |
|
|
|
86 |
foreach ($sections as $section) {
|
|
|
87 |
if (!empty($section->section)) {
|
|
|
88 |
$first_section = $section->id;
|
|
|
89 |
break;
|
1 |
efrain |
90 |
}
|
1231 |
ariadna |
91 |
}
|
|
|
92 |
$course_context = context_course::instance($course->id);
|
|
|
93 |
$roles = get_user_roles($course_context, $USER->id, true);
|
|
|
94 |
|
|
|
95 |
$completion_edit_curso = false;
|
|
|
96 |
foreach ($roles as $role) {
|
|
|
97 |
if ($role->shortname == 'companydepartmentmanager' || $role->shortname == 'companycoursenoneditor') {
|
|
|
98 |
$completion_edit_curso = true;
|
|
|
99 |
break;
|
1 |
efrain |
100 |
}
|
1231 |
ariadna |
101 |
}
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
$modules = get_fast_modinfo($course->id)->get_cms();
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
$linkurl = '';
|
|
|
110 |
foreach ($modules as $module) {
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
//print "!".$module->uservisible ."||". $module->is_stealth() ."||". $module->url ."||". $module->section."<br>";
|
|
|
116 |
if (!$module->uservisible || $module->is_stealth() || empty($module->url) || empty($module->section)) {
|
|
|
117 |
continue;
|
1 |
efrain |
118 |
}
|
|
|
119 |
|
1231 |
ariadna |
120 |
if ($module->section == $first_section || $completion_edit_curso) {
|
|
|
121 |
$linkurl = new moodle_url($module->url, array('forceview' => 1));
|
|
|
122 |
break;
|
1 |
efrain |
123 |
}
|
1231 |
ariadna |
124 |
}
|
|
|
125 |
if ($completion_edit_curso) {
|
|
|
126 |
$linkurl = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
|
|
|
127 |
}
|
1 |
efrain |
128 |
|
1231 |
ariadna |
129 |
|
|
|
130 |
$summary = trim(strip_tags($course->summary));
|
|
|
131 |
|
|
|
132 |
if (empty($summary)) {
|
|
|
133 |
$summary = ' ';
|
|
|
134 |
} else if (strlen($summary) > 80) {
|
|
|
135 |
|
|
|
136 |
$summary = substr($summary, 0, 80) . '...';
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
$data['course'] = [
|
|
|
141 |
'courseid' => $course->id,
|
|
|
142 |
'coursecategory' => $category->name,
|
|
|
143 |
'courseimage' => $image,
|
|
|
144 |
'enddate' => $course->enddate,
|
|
|
145 |
'fullname' => $course->fullname,
|
|
|
146 |
'fullnamedisplay' => get_course_display_name_for_list($course),
|
|
|
147 |
'hasprogress' => true,
|
|
|
148 |
'hidden' => false,
|
|
|
149 |
'id' => $course->id,
|
|
|
150 |
'idnumber' => $course->idnumber,
|
|
|
151 |
'isfavourite' => false,
|
|
|
152 |
'progress' => $miProgreso,
|
|
|
153 |
'shortname' => $course->shortname,
|
|
|
154 |
'showshortname' => false,
|
|
|
155 |
'startdate' => $course->startdate,
|
|
|
156 |
'summary' => $summary,
|
|
|
157 |
'summaryformat' => $course->summaryformat,
|
|
|
158 |
'timeaccess' => $lastaccess,
|
|
|
159 |
'viewurl' => $CFG->wwwroot . '/course/view.php?id=' . $course->id,
|
|
|
160 |
'viewurlnew' => $linkurl,
|
|
|
161 |
'visible' => true,
|
|
|
162 |
|
|
|
163 |
];
|
1 |
efrain |
164 |
}
|
1231 |
ariadna |
165 |
|
|
|
166 |
|
1 |
efrain |
167 |
return $this->render_from_template('block_cesa_lastcourse/full', $data);
|
|
|
168 |
}
|
|
|
169 |
}
|