Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
/**
17
 * Form for creating new H5P Content
18
 *
19
 * @package    mod_hvp
20
 * @copyright  2016 Joubel AS <contact@joubel.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
require_once('../../config.php');
25
 
26
// Get Course ID.
27
$id = optional_param('id', 0, PARAM_INT);
28
 
29
// Set URL.
30
$url = new \moodle_url('/mod/hvp/index.php', array('id' => $id));
31
$PAGE->set_url($url);
32
 
33
// Load Course.
34
$course = $DB->get_record('course', array('id' => $id));
35
if (!$course) {
36
    print_error('invalidcourseid');
37
}
38
 
39
// Require login.
40
require_course_login($course);
41
$PAGE->set_pagelayout('incourse');
42
$coursecontext = context_course::instance($course->id);
43
 
44
// Trigger instances list viewed event.
45
$params = array(
46
    'context' => context_course::instance($course->id)
47
);
48
$event = \mod_hvp\event\course_module_instance_list_viewed::create($params);
49
$event->add_record_snapshot('course', $course);
50
$event->trigger();
51
 
52
// Set title and heading.
53
$PAGE->set_title($course->shortname . ': ' . get_string('modulenameplural', 'mod_hvp'));
54
$PAGE->set_heading($course->fullname);
55
 
56
echo $OUTPUT->header();
57
 
58
// Load H5P list data.
59
$rawh5ps = $DB->get_records_sql("SELECT cm.id AS coursemodule,
60
                                     cw.section,
61
                                     cm.visible,
62
                                     h.name,
63
                                     hl.title AS librarytitle
64
                                FROM {course_modules} cm,
65
                                     {course_sections} cw,
66
                                     {modules} md,
67
                                     {hvp} h,
68
                                     {hvp_libraries} hl
69
                               WHERE cm.course = ?
70
                                 AND cm.instance = h.id
71
                                 AND cm.section = cw.id
72
                                 AND md.name = 'hvp'
73
                                 AND md.id = cm.module
74
                                 AND hl.id = h.main_library_id
75
                             ", array($course->id));
76
if (!$rawh5ps) {
77
    notice(get_string('noh5ps', 'mod_hvp'), "../../course/view.php?id={$course->id}");
78
    die;
79
}
80
 
81
$modinfo = get_fast_modinfo($course, null);
82
if (empty($modinfo->instances['hvp'])) {
83
    $h5ps = $rawh5ps;
84
} else {
85
    // Lets try to order these bad boys.
86
    $h5ps = [];
87
    foreach ($modinfo->instances['hvp'] as $cm) {
88
        if (!$cm->uservisible || !isset($rawh5ps[$cm->id])) {
89
            continue; // Not visible or not found.
90
        }
91
        if (!empty($cm->extra)) {
92
            $rawh5ps[$cm->id]->extra = $cm->extra;
93
        }
94
        $h5ps[] = $rawh5ps[$cm->id];
95
    }
96
}
97
 
98
// Print H5P list.
99
$table = new html_table();
100
$table->attributes['class'] = 'generaltable mod_index';
101
 
102
$table->head = array();
103
$table->align = array();
104
 
105
$usesections = course_format_uses_sections($course->format);
106
if ($usesections) {
107
    // Section name.
108
    $table->head[] = get_string('sectionname', 'format_'.$course->format);
109
    $table->align[] = 'center';
110
}
111
 
112
// Activity name.
113
$table->head[] = get_string('name');
114
$table->align[] = 'left';
115
 
116
// Content type.
117
$table->head[] = 'Content Type';
118
$table->align[] = 'left';
119
 
120
// Add data rows.
121
foreach ($h5ps as $h5p) {
122
    $row = [];
123
 
124
    if ($usesections) {
125
        // Section name.
126
        $row[] = get_section_name($course, $h5p->section);
127
    }
128
 
129
    // Activity name.
130
    $attrs = ($h5p->visible ? '' : ' class="dimmed"');
131
    $h5p->name = format_string($h5p->name);
132
    $row[] = "<a href=\"view.php?id={$h5p->coursemodule}\"{$attrs}>{$h5p->name}</a>";
133
 
134
    // Activity type.
135
    $row[] = $h5p->librarytitle;
136
 
137
    $table->data[] = $row;
138
}
139
 
140
echo html_writer::table($table);
141
 
142
echo $OUTPUT->footer();