Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1453 ariadna 1
<?php
2
class block_cursos_recientes_ajax_renderer extends plugin_renderer_base
3
{
4
 
5
    public function procesar()
6
    {
7
 
8
        global $USER, $DB, $CFG;
9
        require_once $CFG->dirroot . "/blocks/course_list/block_course_list.php";
10
 
11
        $userid = $USER->id;
12
 
13
        $mycourses = enrol_get_users_courses($userid);
14
 
15
        $category_ids = [];
16
        $categories = [];
17
        foreach ($mycourses as $course) {
18
 
19
            if (!$course->visible) {
20
                continue;
21
            }
22
 
23
            /*
24
             stdClass Object ( [id] => 61 [category] => 13 [sortorder] => 20001 [shortname] => MAS - Diseño de landing pages [fullname] => MAS - Diseño de landing pages [idnumber] => [startdate] => 1645324020 [visible] => 1 [defaultgroupingid] => 0 [groupmode] => 0 [groupmodeforce] => 0 [ctxid] => 1606 [ctxpath] => /1/1005/3521/1606 [ctxdepth] => 4 [ctxlevel] => 50 [ctxinstance] => 61 [ctxlocked] => 0 )
25
             */
26
 
27
            if (!in_array($course->category, $category_ids)) {
28
                $category = $DB->get_record('course_categories', array('id' => $course->category, 'visible' => 1));
29
                if ($category) {
30
 
31
 
32
 
33
                    array_push($category_ids, $course->category);
34
                    array_push($categories, [
35
                        'id' => $category->id,
36
                        'name' => trim($category->name),
37
                    ]);
38
                }
39
            }
40
        }
41
 
42
 
43
        usort($categories, function ($a, $b) {
44
            return $a['name'] <=> $b['name']; //  strnatcmp($a['name'],$b['name']); // or other function/code
45
        });
46
 
47
 
48
        $data = [
49
            'categories' => $categories
50
        ];
51
 
52
        return $this->render_from_template('block_cursos_recientes_ajax/form', $data);
53
    }
54
}