2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Courses analyser working at course level (insights for the course teachers).
20 * @package core_analytics
21 * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_analytics\local\analyser
;
27 defined('MOODLE_INTERNAL') ||
die();
30 * Courses analyser working at course level (insights for the course teachers).
32 * @package core_analytics
33 * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class courses
extends by_course
{
38 public function get_samples_origin() {
43 * get_sample_analysable
45 * @param int $sampleid
46 * @return \core_analytics\analysable
48 public function get_sample_analysable($sampleid) {
49 return new \core_analytics\
course($sampleid);
52 protected function provided_sample_data() {
53 return array('course', 'context');
56 public function sample_access_context($sampleid) {
57 return \context_course
::instance($sampleid);
63 * @param \core_analytics\analysable $course
66 protected function get_all_samples(\core_analytics\analysable
$course) {
69 $context = \context_course
::instance($course->get_id());
71 // Just 1 sample per analysable.
73 array($course->get_id() => $course->get_id()),
74 array($course->get_id() => array('course' => $course->get_course_data(), 'context' => $context))
81 * @param int[] $sampleids
84 public function get_samples($sampleids) {
87 list($sql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED
);
88 $courses = $DB->get_records_select('course', "id $sql", $params);
90 $courseids = array_keys($courses);
91 $sampleids = array_combine($courseids, $courseids);
93 $courses = array_map(function($course) {
94 return array('course' => $course, 'context' => \context_course
::instance($course->id
));
97 // No related data attached.
98 return array($sampleids, $courses);
104 * @param int $sampleid
105 * @param int $contextid
106 * @param array $sampledata
109 public function sample_description($sampleid, $contextid, $sampledata) {
110 $description = format_string($sampledata['course']->fullname
, true, array('context' => $sampledata['context']));
111 $courseimage = new \
pix_icon('i/course', get_string('course'));
112 return array($description, $courseimage);