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
 
18
/**
19
 * Course competencies element.
20
 *
21
 * @package   tool_lp
22
 * @copyright 2016 Damyon Wiese
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
global $CFG;
29
 
30
use core_competency\api;
31
use core_competency\external\competency_exporter;
32
require_once($CFG->libdir . '/form/autocomplete.php');
33
 
34
/**
35
 * Course competencies element.
36
 *
37
 * @package   tool_lp
38
 * @copyright 2016 Damyon Wiese
39
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 */
41
class tool_lp_course_competencies_form_element extends MoodleQuickForm_autocomplete {
42
 
43
    /**
44
     * Constructor
45
     *
46
     * @param string $elementName Element name
47
     * @param mixed $elementLabel Label(s) for an element
48
     * @param array $options Options to control the element's display
49
     * @param mixed $attributes Either a typical HTML attribute string or an associative array.
50
     */
51
    public function __construct($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
52
        global $OUTPUT;
53
 
54
        if ($elementName == null) {
55
            // This is broken quickforms messing with the constructors.
56
            return;
57
        }
58
 
59
        if (!isset($options['courseid'])) {
60
            throw new coding_exception('Course id is required for the course_competencies form element');
61
        }
62
        $courseid = $options['courseid'];
63
 
64
        if (!empty($options['cmid'])) {
65
            $current = \core_competency\api::list_course_module_competencies_in_course_module($options['cmid']);
66
            $ids = array();
67
            foreach ($current as $coursemodulecompetency) {
68
                array_push($ids, $coursemodulecompetency->get('competencyid'));
69
            }
70
            $this->setValue($ids);
71
        }
72
 
73
        $competencies = api::list_course_competencies($courseid);
74
        $validoptions = array();
75
 
76
        $context = context_course::instance($courseid);
77
        foreach ($competencies as $competency) {
78
            // We don't need to show the description as part of the options, so just set this to null.
79
            $competency['competency']->set('description', null);
80
            $exporter = new competency_exporter($competency['competency'], array('context' => $context));
81
            $templatecontext = array('competency' => $exporter->export($OUTPUT));
82
            $id = $competency['competency']->get('id');
83
            $validoptions[$id] = $OUTPUT->render_from_template('tool_lp/competency_summary', $templatecontext);
84
        }
85
        $attributes['tags'] = false;
86
        $attributes['multiple'] = 'multiple';
87
        parent::__construct($elementName, $elementLabel, $validoptions, $attributes);
88
    }
89
}