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 local_downloadcenter for 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
/**
18
 * Download center plugin
19
 *
20
 * @package       local_downloadcenter
21
 * @author        Simeon Naydenov (moniNaydenov@gmail.com)
22
 * @copyright     2020 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
23
 * @license       http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
require_once($CFG->libdir . '/formslib.php');
29
require_once(__DIR__ . '/locallib.php');
30
 
31
/**
32
 * Class local_downloadcenter_download_form
33
 */
34
class local_downloadcenter_download_form extends moodleform {
35
    /**
36
     * @throws coding_exception
37
     */
38
    public function definition() {
39
        global $COURSE;
40
        $mform = $this->_form;
41
 
42
        $resources = $this->_customdata['res'];
43
 
44
        $mform->addElement('hidden', 'courseid', $COURSE->id);
45
        $mform->setType('courseid', PARAM_INT);
46
 
47
        $mform->addElement('html',
48
            html_writer::tag('div',
49
                get_string('warningmessage', 'local_downloadcenter'),
50
                array('class' => 'alert alert-info alert-block')
51
            )
52
        );
53
        $mform->addElement('static', 'warning', '', ''); // Hack to work around fieldsets!
54
 
55
        $empty = true;
56
        $excludeempty = get_config('local_downloadcenter', 'exclude_empty_topics');
57
        foreach ($resources as $sectionid => $sectioninfo) {
58
            if ($excludeempty && empty($sectioninfo->res)) { // Only display the sections that are not empty.
59
                continue;
60
            }
61
 
62
            $empty = false;
63
            $sectionname = 'item_topic_' . $sectionid;
64
            $mform->addElement('html', html_writer::start_tag('div', array('class' => 'card block mb-3')));
65
            $sectiontitle = html_writer::span($sectioninfo->title, 'sectiontitle');
66
            $mform->addElement('checkbox', $sectionname, $sectiontitle);
67
 
68
            $mform->setDefault($sectionname, 1);
69
            foreach ($sectioninfo->res as $res) {
70
                $name = 'item_' . $res->modname . '_' . $res->instanceid;
71
                $title = html_writer::span($res->name) . ' ' . $res->icon;
72
                $title = html_writer::tag('span', $title, array('class' => 'itemtitle'));
73
                $mform->addElement('checkbox', $name, $title);
74
                $mform->setDefault($name, 1);
75
            }
76
            $mform->addElement('html', html_writer::end_tag('div'));
77
        }
78
 
79
        if ($empty) {
80
            $mform->addElement('html', html_writer::tag('h2', get_string('no_downloadable_content', 'local_downloadcenter')));
81
        }
82
        // Create a new section for the download options!
83
        $mform->addElement('header', 'downloadoptions', get_string('downloadoptions', 'local_downloadcenter'));
84
        $mform->addElement('checkbox', 'filesrealnames', get_string('downloadoptions:filesrealnames', 'local_downloadcenter'));
85
        $mform->setDefault('filesrealnames', 0);
86
        $mform->addHelpButton('filesrealnames', 'downloadoptions:filesrealnames', 'local_downloadcenter');
87
        $mform->addElement('checkbox', 'addnumbering', get_string('downloadoptions:addnumbering', 'local_downloadcenter'));
88
        $mform->setDefault('addnumbering', 0);
89
        $mform->addHelpButton('addnumbering', 'downloadoptions:addnumbering', 'local_downloadcenter');
90
 
91
        $this->add_action_buttons(true, get_string('createzip', 'local_downloadcenter'));
92
 
93
    }
94
}