Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
namespace core_badges\form;
18
 
19
defined('MOODLE_INTERNAL') || die();
20
 
21
require_once($CFG->libdir . '/formslib.php');
22
require_once($CFG->libdir . '/badgeslib.php');
23
 
24
use html_writer;
25
use moodleform;
26
 
27
/**
28
 * Form to select backpack collections.
29
 *
1441 ariadna 30
 * @package    core_badges
1 efrain 31
 * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1441 ariadna 33
 * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
1 efrain 34
 */
35
class collections extends moodleform {
36
 
37
    /**
38
     * Defines the form
39
     */
40
    public function definition() {
41
        global $USER;
42
        $mform = $this->_form;
43
        $email = $this->_customdata['email'];
44
        $backpackweburl = $this->_customdata['backpackweburl'];
45
        $selected = $this->_customdata['selected'];
46
 
47
        if (isset($this->_customdata['groups'])) {
48
            $groups = $this->_customdata['groups'];
49
            $nogroups = null;
50
        } else {
51
            $groups = null;
52
            $nogroups = $this->_customdata['nogroups'];
53
        }
54
 
55
        $backpack = get_backpack_settings($USER->id);
56
        $sitebackpack = badges_get_site_backpack($backpack->backpackid);
57
 
58
        $mform->addElement('header', 'backpackheader', get_string('backpackconnection_connected', 'badges'));
59
        $mform->addElement('static', 'url', get_string('url'), $backpackweburl);
60
 
61
        $status = html_writer::tag('span', get_string('connected', 'badges'), array('class' => 'connected'));
62
        $mform->addElement('static', 'status', get_string('status'), $status);
63
        $mform->addElement('static', 'email', get_string('email'), $email);
64
        $mform->addElement('submit', 'disconnect', get_string('disconnect', 'badges'));
65
 
66
        $mform->addElement('header', 'collectionheader', get_string('backpackimport', 'badges'));
67
        $mform->addHelpButton('collectionheader', 'backpackimport', 'badges');
68
 
69
        $hasgroups = false;
70
        if (!empty($groups)) {
71
            foreach ($groups as $group) {
72
                $count = 0;
73
                // Handle attributes based on backpack's supported version.
1441 ariadna 74
                if (empty($group->published)) {
75
                    // Only public collections.
76
                    continue;
1 efrain 77
                }
1441 ariadna 78
                // Get the number of badges associated with this collection from the assertions array returned.
79
                $count = count($group->assertions);
1 efrain 80
 
81
                if (!$hasgroups) {
82
                    $mform->addElement('static', 'selectgroup', '', get_string('selectgroup_start', 'badges'));
83
                }
84
                $hasgroups = true;
85
                $name = $group->name . ' (' . $count . ')';
86
                $mform->addElement(
87
                    'advcheckbox',
88
                    'group[' . $group->entityId . ']',
89
                    null,
90
                    $name,
91
                    array('group' => 1),
92
                    array(false, $group->entityId)
93
                );
94
                if (in_array($group->entityId, $selected)) {
95
                    $mform->setDefault('group[' . $group->entityId . ']', $group->entityId);
96
                }
97
            }
98
            $mform->addElement('static', 'selectgroup', '', get_string('selectgroup_end', 'badges', $backpackweburl));
99
        }
100
        if (!$hasgroups) {
101
            $mform->addElement('static', 'selectgroup', '', $nogroups);
102
        }
103
 
104
        $this->add_action_buttons();
105
    }
106
}