1 |
efrain |
1 |
<?php
|
|
|
2 |
use core_completion\progress;
|
|
|
3 |
|
|
|
4 |
class block_cursosrecientes_renderer extends plugin_renderer_base {
|
|
|
5 |
|
|
|
6 |
public function procesar($instance_id) {
|
|
|
7 |
|
|
|
8 |
global $USER, $DB, $CFG, $PAGE;
|
|
|
9 |
require_once $CFG->libdir . '/coursecatlib.php';
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
$userid = $USER->id;
|
|
|
15 |
$url_noimage = $CFG->wwwroot . '/theme/' . $PAGE->theme->name . '/pix/coursenoimage.jpg';
|
|
|
16 |
$type = isset($_GET['type']) ? filter_var($_GET['type'], FILTER_SANITIZE_STRING) : '';
|
|
|
17 |
if($type != 'grid' && $type != 'listing') {
|
|
|
18 |
$type = 'grid';
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
$search = isset($_GET['search']) ? filter_var($_GET['search'], FILTER_SANITIZE_STRING) : '';
|
|
|
22 |
|
|
|
23 |
$data = [
|
|
|
24 |
'user_id' => $userid,
|
|
|
25 |
'instance_id' => $instance_id,
|
|
|
26 |
'courses' => [],
|
|
|
27 |
'grid' => $type == 'grid' ? true : false,
|
|
|
28 |
'listing' => $type == 'listing' ? true : false
|
|
|
29 |
];
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
$courselist = array();
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
$mycourses = enrol_get_users_courses($userid);
|
|
|
37 |
$courselist = array();
|
|
|
38 |
foreach ($mycourses as $key => $val) {
|
|
|
39 |
if($search) {
|
|
|
40 |
if(stripos($val->fullname, $search) === false) {
|
|
|
41 |
continue;
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
$courselist[] = $val->id;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
/*
|
|
|
50 |
$paramsql = array('userid' => $userid);
|
|
|
51 |
$sql = "SELECT DISTINCT rai.courseid, rai.*
|
|
|
52 |
FROM {block_recentlyaccesseditems} rai
|
|
|
53 |
JOIN {course} c ON c.id = rai.courseid
|
|
|
54 |
WHERE userid = :userid
|
|
|
55 |
ORDER BY rai.timeaccess DESC";
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
$records = $DB->get_records_sql($sql, $paramsql);
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
foreach ($records as $record) {
|
|
|
62 |
$courselist[] = $record->courseid;
|
|
|
63 |
}*/
|
|
|
64 |
|
|
|
65 |
for ($x = 1; $x <= sizeof($courselist); $x++) {
|
|
|
66 |
$course = get_course($courselist[$x - 1]);
|
|
|
67 |
|
|
|
68 |
if ($course instanceof stdClass) {
|
|
|
69 |
|
|
|
70 |
$courseInList = new course_in_list($course);
|
|
|
71 |
}
|
|
|
72 |
$image = $url_noimage;
|
|
|
73 |
foreach ($courseInList->get_course_overviewfiles() as $file)
|
|
|
74 |
{
|
|
|
75 |
$isimage = $file->is_valid_image();
|
|
|
76 |
$image = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
|
|
|
77 |
if (!$isimage) {
|
|
|
78 |
$image = $url_noimage;
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
$lastaccess = $DB->get_field('report_training_lastaccess', 'timeaccess', array('courseid' => $course->id, 'userid' => $userid));
|
|
|
83 |
|
|
|
84 |
$category = $DB->get_record('course_categories',array('id'=>$course->category));
|
|
|
85 |
|
|
|
86 |
$miProgreso = number_format(progress::get_course_progress_percentage($course),2); // Progreso por curso
|
|
|
87 |
$data['courses'][] = [
|
|
|
88 |
|
|
|
89 |
'coursecategory' => $category->name,
|
|
|
90 |
'courseimage' => $image,
|
|
|
91 |
'enddate' => $course->enddate,
|
|
|
92 |
'fullname' => $course->fullname,
|
|
|
93 |
'fullnamedisplay' => get_course_display_name_for_list($course),
|
|
|
94 |
'hasprogress' => true,
|
|
|
95 |
'hidden' => false,
|
|
|
96 |
'id' => $course->id,
|
|
|
97 |
'idnumber' => $course->idnumber,
|
|
|
98 |
'isfavourite' => false,
|
|
|
99 |
'progress' => $miProgreso,
|
|
|
100 |
'shortname' => $course->shortname,
|
|
|
101 |
'showshortname' => false,
|
|
|
102 |
'startdate' => $course->startdate,
|
|
|
103 |
'summary' => $course->summary,
|
|
|
104 |
'summaryformat' => $course->summaryformat,
|
|
|
105 |
'timeaccess' => $lastaccess,
|
|
|
106 |
'viewurl' => $CFG->wwwroot . '/course/view.php?id=' . $course->id,
|
|
|
107 |
'visible' => true
|
|
|
108 |
];
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
}
|
|
|
113 |
//var_dump($data);
|
|
|
114 |
//die();
|
|
|
115 |
return $this->render_from_template('block_cursosrecientes/full', $data);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
}
|