report.php 4.67 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Class containing data for learning plan template competencies page
 *
 * @package    report_competency
 * @copyright  2015 Damyon Wiese
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
namespace report_competency\output;

use context_course;
use renderable;
28
use core_user;
29
30
use templatable;
use renderer_base;
31
use moodle_url;
32
use stdClass;
33
34
use core_competency\api;
use core_competency\external\user_competency_course_exporter;
35
use core_user\external\user_summary_exporter;
36
use core_competency\external\performance_helper;
37
use core_competency\url;
38
39
use core_competency\user_competency;
use tool_lp\external\competency_summary_exporter;
40
use core_course\external\course_summary_exporter;
41
42
43
44
45
46
47
48
49
50
51

/**
 * Class containing data for learning plan template competencies page
 *
 * @copyright  2015 Damyon Wiese
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class report implements renderable, templatable {

    /** @var context $context */
    protected $context;
52
53
54
55
    /** @var int $courseid */
    protected $courseid;
    /** @var array $competencies */
    protected $competencies;
56
57
58
59
60

    /**
     * Construct this renderable.
     *
     * @param int $courseid The course id
61
     * @param int $userid The user id
62
     */
63
    public function __construct($courseid, $userid) {
64
        $this->courseid = $courseid;
65
        $this->userid = $userid;
66
67
68
69
70
71
72
73
74
75
        $this->context = context_course::instance($courseid);
    }

    /**
     * Export this data so it can be used as the context for a mustache template.
     *
     * @param \renderer_base $output
     * @return stdClass
     */
    public function export_for_template(renderer_base $output) {
76
77
        global $DB;

78
        $data = new stdClass();
79
80
81
82
83
        $data->courseid = $this->courseid;

        $course = $DB->get_record('course', array('id' => $this->courseid));
        $coursecontext = context_course::instance($course->id);
        $exporter = new course_summary_exporter($course, array('context' => $coursecontext));
84
        $coursecompetencysettings = api::read_course_competency_settings($course->id);
85
        $data->pushratingstouserplans = $coursecompetencysettings->get('pushratingstouserplans');
86
87
        $data->course = $exporter->export($output);

88
        $data->usercompetencies = array();
89
90
91
92
93
94
        $user = core_user::get_user($this->userid);

        $exporter = new user_summary_exporter($user);
        $data->user = $exporter->export($output);
        $data->usercompetencies = array();
        $coursecompetencies = api::list_course_competencies($this->courseid);
95
        $usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $user->id);
96

97
        $helper = new performance_helper();
98
        foreach ($usercompetencycourses as $usercompetencycourse) {
99
            $onerow = new stdClass();
100
101
            $competency = null;
            foreach ($coursecompetencies as $coursecompetency) {
102
                if ($coursecompetency['competency']->get('id') == $usercompetencycourse->get('competencyid')) {
103
104
                    $competency = $coursecompetency['competency'];
                    break;
105
                }
106
107
108
109
110
            }
            if (!$competency) {
                continue;
            }

111
112
            $framework = $helper->get_framework_from_competency($competency);
            $scale = $helper->get_scale_from_competency($competency);
113

114
            $exporter = new user_competency_course_exporter($usercompetencycourse, array('scale' => $scale));
115
            $record = $exporter->export($output);
116
            $onerow->usercompetencycourse = $record;
117
118
119
120
121
122
123
            $exporter = new competency_summary_exporter(null, array(
                'competency' => $competency,
                'framework' => $framework,
                'context' => $framework->get_context(),
                'relatedcompetencies' => array(),
                'linkedcourses' => array()
            ));
124
            $onerow->competency = $exporter->export($output);
125
126
127
128
129
130
            array_push($data->usercompetencies, $onerow);
        }

        return $data;
    }
}