Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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