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 |
//require_once $CFG->libdir . '/completionlib.php';
|
|
|
11 |
// require_once $CFG->dirroot . '/lib/datalib.php';
|
|
|
12 |
require_once $CFG->dirroot . '/course/classes/category.php';
|
|
|
13 |
require_once $CFG->dirroot."/blocks/course_list/block_course_list.php";
|
|
|
14 |
//require_once $CFG->dirroot . '/completion/classes/progress.php';
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
$userid = $USER->id;
|
|
|
21 |
$url_noimage = $CFG->wwwroot . '/theme/' . $PAGE->theme->name . '/pix/coursenoimage.jpg';
|
|
|
22 |
$type = isset($_GET['type']) ? filter_var($_GET['type'], FILTER_SANITIZE_STRING) : '';
|
|
|
23 |
if($type != 'grid' && $type != 'listing') {
|
|
|
24 |
$type = 'grid';
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
$search = isset($_GET['search']) ? filter_var($_GET['search'], FILTER_SANITIZE_STRING) : '';
|
|
|
28 |
|
|
|
29 |
$data = [
|
|
|
30 |
'user_id' => $userid,
|
|
|
31 |
'instance_id' => $instance_id,
|
|
|
32 |
'courses' => [],
|
|
|
33 |
'grid' => $type == 'grid' ? true : false,
|
|
|
34 |
'listing' => $type == 'listing' ? true : false
|
|
|
35 |
];
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
$courselist = array();
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
$mycourses = enrol_get_users_courses($userid);
|
|
|
43 |
$courselist = array();
|
|
|
44 |
foreach ($mycourses as $key => $val) {
|
|
|
45 |
if($search) {
|
|
|
46 |
if(stripos($val->fullname, $search) === false) {
|
|
|
47 |
continue;
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
$courselist[] = $val->id;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
/*
|
|
|
56 |
$paramsql = array('userid' => $userid);
|
|
|
57 |
$sql = "SELECT DISTINCT rai.courseid, rai.*
|
|
|
58 |
FROM {block_recentlyaccesseditems} rai
|
|
|
59 |
JOIN {course} c ON c.id = rai.courseid
|
|
|
60 |
WHERE userid = :userid
|
|
|
61 |
ORDER BY rai.timeaccess DESC";
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
$records = $DB->get_records_sql($sql, $paramsql);
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
foreach ($records as $record) {
|
|
|
68 |
$courselist[] = $record->courseid;
|
|
|
69 |
}*/
|
|
|
70 |
|
|
|
71 |
for ($x = 1; $x <= sizeof($courselist); $x++) {
|
|
|
72 |
$course = get_course($courselist[$x - 1]);
|
|
|
73 |
|
|
|
74 |
if ($course instanceof stdClass) {
|
|
|
75 |
$courseInList = new core_course_list_element($course);
|
|
|
76 |
}
|
|
|
77 |
$image = $url_noimage;
|
|
|
78 |
foreach ($courseInList->get_course_overviewfiles() as $file)
|
|
|
79 |
{
|
|
|
80 |
$isimage = $file->is_valid_image();
|
|
|
81 |
$image = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
|
|
|
82 |
if (!$isimage) {
|
|
|
83 |
$image = $url_noimage;
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
$lastaccess = null;
|
|
|
88 |
$sql = "select timecreated from {logstore_standard_log} where courseid = :courseid and userid = :userid " .
|
|
|
89 |
" and eventname = '\\\\core\\\\event\\\\course_viewed' order by id desc limit 1 ";
|
|
|
90 |
|
|
|
91 |
$timecreated = $DB->get_field_sql($sql, array('courseid' => $course->id, 'userid' => $userid));
|
|
|
92 |
if($timecreated) {
|
|
|
93 |
|
|
|
94 |
$lastaccess = date('d/m/Y h:i a', $timecreated);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
$category = $DB->get_record('course_categories',array('id'=>$course->category));
|
|
|
98 |
|
|
|
99 |
$miProgreso = number_format(progress::get_course_progress_percentage($course),2); // Progreso por curso
|
|
|
100 |
|
|
|
101 |
//$modules = get_fast_modinfo($course->id)->get_cms();
|
|
|
102 |
//print_r($modules);
|
|
|
103 |
// $sections = $DB->get_records('course_sections', ['course' => $course->id], 'section ASC', 'id,name,section,sequence,visible');
|
|
|
104 |
|
|
|
105 |
//print_r($modules);
|
|
|
106 |
|
|
|
107 |
$first_section = 0;
|
|
|
108 |
$sections = $DB->get_records('course_sections', ['course' => $course->id], 'section ASC', 'id,name,section,sequence,visible');
|
|
|
109 |
|
|
|
110 |
foreach($sections as $section)
|
|
|
111 |
{
|
|
|
112 |
if(!empty($section->section)) {
|
|
|
113 |
$first_section = $section->id;
|
|
|
114 |
break;
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
$course_context = context_course::instance($course->id);
|
|
|
118 |
$roles = get_user_roles($course_context, $USER->id, true);
|
|
|
119 |
|
|
|
120 |
$completion_edit_curso = false;
|
|
|
121 |
foreach ($roles as $role) {
|
|
|
122 |
if ($role->shortname == 'companydepartmentmanager' || $role->shortname == 'companycoursenoneditor') {
|
|
|
123 |
$completion_edit_curso = true;
|
|
|
124 |
break;
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
$modules = get_fast_modinfo($course->id)->get_cms();
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
$linkurl = '';
|
|
|
135 |
foreach ($modules as $module)
|
|
|
136 |
{
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
//print "!".$module->uservisible ."||". $module->is_stealth() ."||". $module->url ."||". $module->section."<br>";
|
|
|
142 |
if (!$module->uservisible || $module->is_stealth() || empty($module->url) || empty($module->section)) {
|
|
|
143 |
continue;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
if($module->section == $first_section || $completion_edit_curso) {
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
$linkurl = new moodle_url($module->url, array('forceview' => 1));
|
|
|
153 |
//print_r($linkurl);
|
|
|
154 |
//var_dump($linkurl);
|
|
|
155 |
break;
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
//$linkurl == "" &&
|
|
|
159 |
if( $completion_edit_curso){
|
|
|
160 |
$linkurl = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
/*el mio
|
|
|
165 |
foreach($sections as $section)
|
|
|
166 |
{
|
|
|
167 |
|
|
|
168 |
$first = true;
|
|
|
169 |
foreach ($modules as $module)
|
|
|
170 |
{
|
|
|
171 |
|
|
|
172 |
if($module->section != $section->id) {
|
|
|
173 |
continue;
|
|
|
174 |
}
|
|
|
175 |
$mods[$module->id] = $module;
|
|
|
176 |
|
|
|
177 |
$linkurl = new moodle_url($module->url, array('forceview' => 1));
|
|
|
178 |
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
/die();*/
|
|
|
185 |
|
|
|
186 |
/*echo '<pre>';
|
|
|
187 |
echo $first_activity_summary;
|
|
|
188 |
echo '</pre>';*/
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
$summary = trim(strip_tags($course->summary));
|
|
|
193 |
|
|
|
194 |
if(strlen($summary) > 80) {
|
|
|
195 |
|
|
|
196 |
$summary = substr($summary, 0, 80) . '...';
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
$data['courses'][] = [
|
|
|
200 |
|
|
|
201 |
'coursecategory' => $category->name,
|
|
|
202 |
'courseimage' => $image,
|
|
|
203 |
'enddate' => $course->enddate,
|
|
|
204 |
'fullname' => $course->fullname,
|
|
|
205 |
'fullnamedisplay' => get_course_display_name_for_list($course),
|
|
|
206 |
'hasprogress' => true,
|
|
|
207 |
'hidden' => false,
|
|
|
208 |
'id' => $course->id,
|
|
|
209 |
'idnumber' => $course->idnumber,
|
|
|
210 |
'isfavourite' => false,
|
|
|
211 |
'progress' => $miProgreso,
|
|
|
212 |
'shortname' => $course->shortname,
|
|
|
213 |
'showshortname' => false,
|
|
|
214 |
'startdate' => $course->startdate,
|
|
|
215 |
'summary' => $summary,
|
|
|
216 |
'summaryformat' => $course->summaryformat,
|
|
|
217 |
'timeaccess' => $lastaccess,
|
|
|
218 |
'viewurl' => $CFG->wwwroot . '/course/view.php?id=' . $course->id,
|
|
|
219 |
'viewurlnew' => $linkurl,
|
|
|
220 |
'visible' => true,
|
|
|
221 |
|
|
|
222 |
];
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
}
|
|
|
226 |
//var_dump($data);
|
|
|
227 |
// die();
|
|
|
228 |
return $this->render_from_template('block_cursosrecientes/full', $data);
|
|
|
229 |
}
|
|
|
230 |
}
|
|
|
231 |
|