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
 * Class containing data for learning plan template competencies page
19
 *
20
 * @package    report_competency
21
 * @copyright  2015 Damyon Wiese
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
namespace report_competency\output;
25
 
26
use context_course;
27
use renderable;
28
use core_user;
29
use templatable;
30
use renderer_base;
31
use moodle_url;
32
use stdClass;
33
use core_competency\api;
34
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
use core_competency\user_competency;
39
use tool_lp\external\competency_summary_exporter;
40
use core_course\external\course_summary_exporter;
41
 
42
/**
43
 * Class containing data for learning plan template competencies page
44
 *
45
 * @copyright  2015 Damyon Wiese
46
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
47
 */
48
class report implements renderable, templatable {
49
 
50
    /** @var context $context */
51
    protected $context;
52
    /** @var int $courseid */
53
    protected $courseid;
54
    /** @var int $moduleid */
55
    protected $moduleid;
56
    /** @var array $competencies */
57
    protected $competencies;
58
    /** @var int The user id */
59
    protected $userid;
60
 
61
    /**
62
     * Construct this renderable.
63
     *
64
     * @param int $courseid The course id
65
     * @param int $userid The user id
66
     * @param int $moduleid The module id
67
     */
68
    public function __construct($courseid, $userid, $moduleid) {
69
        $this->courseid = $courseid;
70
        $this->userid = $userid;
71
        $this->moduleid = $moduleid;
72
        $this->context = context_course::instance($courseid);
73
    }
74
 
75
    /**
76
     * Export this data so it can be used as the context for a mustache template.
77
     *
78
     * @param \renderer_base $output
79
     * @return stdClass
80
     */
81
    public function export_for_template(renderer_base $output) {
82
        global $DB;
83
 
84
        $data = new stdClass();
85
        $data->courseid = $this->courseid;
86
        $data->moduleid = $this->moduleid;
87
        if (empty($data->moduleid)) {
88
            $data->moduleid = 0;
89
        }
90
 
91
        $course = $DB->get_record('course', array('id' => $this->courseid));
92
        $coursecontext = context_course::instance($course->id);
93
        $exporter = new course_summary_exporter($course, array('context' => $coursecontext));
94
        $coursecompetencysettings = api::read_course_competency_settings($course->id);
95
        $data->pushratingstouserplans = $coursecompetencysettings->get('pushratingstouserplans');
96
        $data->course = $exporter->export($output);
97
 
98
        $data->usercompetencies = array();
99
        $user = core_user::get_user($this->userid);
100
 
101
        $exporter = new user_summary_exporter($user);
102
        $data->user = $exporter->export($output);
103
        $data->usercompetencies = array();
104
        $coursecompetencies = api::list_course_competencies($this->courseid);
105
        $usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $user->id);
106
        if ($this->moduleid > 0) {
107
            $modulecompetencies = api::list_course_module_competencies_in_course_module($this->moduleid);
108
            foreach ($usercompetencycourses as $ucid => $usercompetency) {
109
                $found = false;
110
                foreach ($modulecompetencies as $mcid => $modulecompetency) {
111
                    if ($modulecompetency->get('competencyid') == $usercompetency->get('competencyid')) {
112
                        $found = true;
113
                        break;
114
                    }
115
                }
116
 
117
                if (!$found) {
118
                    // We need to filter out this competency.
119
                    unset($usercompetencycourses[$ucid]);
120
                }
121
            }
122
        }
123
 
124
        $helper = new performance_helper();
125
        foreach ($usercompetencycourses as $usercompetencycourse) {
126
            $onerow = new stdClass();
127
            $competency = null;
128
            foreach ($coursecompetencies as $coursecompetency) {
129
                if ($coursecompetency['competency']->get('id') == $usercompetencycourse->get('competencyid')) {
130
                    $competency = $coursecompetency['competency'];
131
                    break;
132
                }
133
            }
134
            if (!$competency) {
135
                continue;
136
            }
137
 
138
            $framework = $helper->get_framework_from_competency($competency);
139
            $scale = $helper->get_scale_from_competency($competency);
140
 
141
            $exporter = new user_competency_course_exporter($usercompetencycourse, array('scale' => $scale));
142
            $record = $exporter->export($output);
143
            $onerow->usercompetencycourse = $record;
144
            $exporter = new competency_summary_exporter(null, array(
145
                'competency' => $competency,
146
                'framework' => $framework,
147
                'context' => $framework->get_context(),
148
                'relatedcompetencies' => array(),
149
                'linkedcourses' => array()
150
            ));
151
            $onerow->competency = $exporter->export($output);
152
            array_push($data->usercompetencies, $onerow);
153
        }
154
 
155
        return $data;
156
    }
157
}