first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,115 @@
<?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/>.
/**
* Activities due indicator.
*
* @package core
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/calendar/externallib.php');
/**
* Activities due indicator.
*
* @package core
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activities_due extends \core_analytics\local\indicator\binary {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:activitiesdue');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
return array('user');
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $sampleorigin
* @param int $starttime
* @param int $endtime
* @return float
*/
protected function calculate_sample($sampleid, $sampleorigin, $starttime = false, $endtime = false) {
$user = $this->retrieve('user', $sampleid);
$actionevents = \core_calendar_external::get_calendar_action_events_by_timesort($starttime, $endtime, 0, 1,
true, $user->id);
$useractionevents = [];
if ($actionevents->events) {
// We first need to check that at least one of the core_calendar_provide_event_action
// callbacks has the $userid param.
foreach ($actionevents->events as $event) {
$nparams = $this->get_provide_event_action_num_params($event->modulename);
if ($nparams > 2) {
// Just the basic info for the insight as we want a low memory usage.
$useractionevents[$event->id] = (object)[
'name' => $event->name,
'url' => $event->url,
'time' => $event->timesort,
'coursename' => $event->course->fullnamedisplay,
'icon' => $event->icon,
];
}
}
if (!empty($useractionevents)) {
$this->add_shared_calculation_info($sampleid, $useractionevents);
return self::get_max_value();
}
}
return self::get_min_value();
}
/**
* Returns the number of params declared in core_calendar_provide_event_action's implementation.
*
* @param string $modulename The module name
* @return int
*/
private function get_provide_event_action_num_params(string $modulename) {
$functionname = 'mod_' . $modulename . '_core_calendar_provide_event_action';
$reflection = new \ReflectionFunction($functionname);
return $reflection->getNumberOfParameters();
}
}
@@ -0,0 +1,87 @@
<?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/>.
/**
* Completion enabled set indicator.
*
* @package core_course
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/lib/completionlib.php');
/**
* Completion enabled set indicator.
*
* @package core_course
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_enabled extends \core_analytics\local\indicator\binary {
/**
* get_name
*
* @return new \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:completionenabled', 'moodle');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
// Minimum course although it also accepts course_modules.
return array('course');
}
/**
* Is completion enabled? Work both with courses and activities.
*
* @param int $sampleid
* @param string $sampleorigin
* @param int|false $notusedstarttime
* @param int|false $notusedendtime
* @return float
*/
public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
$course = $this->retrieve('course', $sampleid);
// It may not be available, but if it is the indicator checks if completion is enabled for the cm.
$cm = $this->retrieve('course_modules', $sampleid);
$completion = new \completion_info($course);
if (!$completion->is_enabled($cm)) {
$value = self::get_min_value();
} else if (!$cm && !$completion->has_criteria()) {
// Course completion enabled with no criteria counts as nothing.
$value = self::get_min_value();
} else {
$value = self::get_max_value();
}
return $value;
}
}
@@ -0,0 +1,95 @@
<?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/>.
/**
* No student indicator.
*
* @package core_course
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* No student indicator.
*
* @package core_course
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class no_student extends \core_analytics\local\indicator\binary {
/**
* Student role ids.
*
* @var array|null
*/
protected $studentroleids = null;
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:nostudent', 'moodle');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
// We require course because, although calculate_sample only reads context, we need the context to be course
// or below.
return array('context', 'course');
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $sampleorigin
* @param int|false $notusedstarttime
* @param int|false $notusedendtime
* @return float
*/
public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
$context = $this->retrieve('context', $sampleid);
if (is_null($this->studentroleids)) {
$this->studentroleids = array_keys(get_archetype_roles('student'));
}
foreach ($this->studentroleids as $role) {
// We look for roles, not enrolments as a student assigned at category level is supposed to be a
// course student.
$students = get_role_users($role, $context, false, 'u.id', 'u.id');
if ($students) {
return self::get_max_value();
}
}
return self::get_min_value();
}
}
@@ -0,0 +1,95 @@
<?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/>.
/**
* No teacher indicator.
*
* @package core_course
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* No teacher indicator.
*
* @package core_course
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class no_teacher extends \core_analytics\local\indicator\binary {
/**
* Teacher role ids.
*
* @var array|null
*/
protected $teacherroleids = null;
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:noteacher', 'moodle');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
// We require course because, although calculate_sample only reads context, we need the context to be course
// or below.
return array('context', 'course');
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $sampleorigin
* @param int|false $notusedstarttime
* @param int|false $notusedendtime
* @return float
*/
public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
$context = $this->retrieve('context', $sampleid);
if (is_null($this->teacherroleids)) {
$this->teacherroleids = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher'));
}
foreach ($this->teacherroleids as $role) {
// We look for roles, not enrolments as a teacher assigned at category level is supposed to be a
// course teacher.
$teachers = get_role_users($role, $context, false, 'u.id', 'u.id');
if ($teachers) {
return self::get_max_value();
}
}
return self::get_min_value();
}
}
@@ -0,0 +1,136 @@
<?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/>.
/**
* Potential cognitive depth indicator.
*
* @package core_course
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
use \core_analytics\local\indicator\community_of_inquiry_activity;
/**
* Potential cognitive depth indicator.
*
* It extends linear instead of discrete as there is a linear relation between
* the different cognitive levels activities can reach.
*
* @package core_course
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class potential_cognitive_depth extends \core_analytics\local\indicator\linear {
/**
* get_name
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:potentialcognitive', 'moodle');
}
/**
* Specify the required data to process this indicator.
*
* @return string[]
*/
public static function required_sample_data() {
// We require course because, although this indicator can also work with course_modules we can't
// calculate anything without the course.
return array('course');
}
/**
* calculate_sample
*
* @throws \coding_exception
* @param int $sampleid
* @param string $sampleorigin
* @param int|false $notusedstarttime
* @param int|false $notusedendtime
* @return float
*/
public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
if ($sampleorigin === 'course_modules') {
$cm = $this->retrieve('course_modules', $sampleid);
$cminfo = \cm_info::create($cm);
$cognitivedepthindicator = $this->get_cognitive_indicator($cminfo->modname);
$potentiallevel = $cognitivedepthindicator->get_cognitive_depth_level($cminfo);
if ($potentiallevel > community_of_inquiry_activity::MAX_COGNITIVE_LEVEL) {
throw new \coding_exception('Maximum cognitive depth level is ' .
community_of_inquiry_activity::MAX_COGNITIVE_LEVEL . ', ' . $potentiallevel . ' provided by ' .
get_class($this));
}
} else {
$course = $this->retrieve('course', $sampleid);
$modinfo = get_fast_modinfo($course);
$cms = $modinfo->get_cms();
if (!$cms) {
return self::get_min_value();
}
$potentiallevel = 0;
foreach ($cms as $cm) {
if (!$cognitivedepthindicator = $this->get_cognitive_indicator($cm->modname)) {
continue;
}
$level = $cognitivedepthindicator->get_cognitive_depth_level($cm);
if ($level > community_of_inquiry_activity::MAX_COGNITIVE_LEVEL) {
throw new \coding_exception('Maximum cognitive depth level is ' .
community_of_inquiry_activity::MAX_COGNITIVE_LEVEL . ', ' . $level . ' provided by ' . get_class($this));
}
if ($level > $potentiallevel) {
$potentiallevel = $level;
}
}
}
// Values from -1 to 1 range split in 5 parts (the max cognitive depth level).
// Note that we divide by 4 because we start from -1.
$levelscore = round((self::get_max_value() - self::get_min_value()) / 4, 2);
// We substract $levelscore because we want to start from the lower score and there is no cognitive depth level 0.
return self::get_min_value() + ($levelscore * $potentiallevel) - $levelscore;
}
/**
* Returns the cognitive depth class of this indicator.
*
* @param string $modname
* @return \core_analytics\local\indicator\base|false
*/
protected function get_cognitive_indicator($modname) {
$indicators = \core_analytics\manager::get_all_indicators();
foreach ($indicators as $indicator) {
if ($indicator instanceof community_of_inquiry_activity &&
$indicator->get_indicator_type() === community_of_inquiry_activity::INDICATOR_COGNITIVE &&
$indicator->get_activity_type() === $modname) {
return $indicator;
}
}
return false;
}
}
@@ -0,0 +1,148 @@
<?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/>.
/**
* Potential social breadth indicator.
*
* @package core_course
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
use \core_analytics\local\indicator\community_of_inquiry_activity;
/**
* Potential social breadth indicator.
*
* It extends linear instead of discrete as there is a linear relation between
* the different social levels activities can reach.
*
* @package core_course
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class potential_social_breadth extends \core_analytics\local\indicator\linear {
/**
* get_name
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:potentialsocial', 'moodle');
}
/**
* Specify the required data to process this indicator.
*
* @return string[]
*/
public static function required_sample_data() {
// We require course because, although this indicator can also work with course_modules we can't
// calculate anything without the course.
return array('course');
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $sampleorigin
* @param int|false $notusedstarttime
* @param int|false $notusedendtime
* @return float
*/
public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
if ($sampleorigin === 'course_modules') {
$cm = $this->retrieve('course_modules', $sampleid);
$cminfo = \cm_info::create($cm);
$socialbreadthindicator = $this->get_social_indicator($cminfo->modname);
$potentiallevel = $socialbreadthindicator->get_social_breadth_level($cminfo);
if ($potentiallevel > community_of_inquiry_activity::MAX_SOCIAL_LEVEL) {
$this->level_not_accepted($potentiallevel);
}
} else {
$course = $this->retrieve('course', $sampleid);
$modinfo = get_fast_modinfo($course);
$cms = $modinfo->get_cms();
if (!$cms) {
return self::get_min_value();
}
$potentiallevel = 0;
foreach ($cms as $cm) {
if (!$socialbreadthindicator = $this->get_social_indicator($cm->modname)) {
continue;
}
$level = $socialbreadthindicator->get_social_breadth_level($cm);
if ($level > community_of_inquiry_activity::MAX_SOCIAL_LEVEL) {
$this->level_not_accepted($level);
}
if ($level > $potentiallevel) {
$potentiallevel = $level;
}
}
}
// Core activities social breadth only reaches level 2, until core activities social
// breadth do not reach level 5 we limit it to what we currently support, which is level 2.
if ($potentiallevel > 2) {
$potentiallevel = 2;
}
// Supporting only social breadth level 1 and 2 the possible values are -1 or 1.
$levelscore = round(self::get_max_value() - self::get_min_value(), 2);
// We substract $levelscore because we want to start from the lower socre and there is no cognitive depth level 0.
return self::get_min_value() + ($levelscore * $potentiallevel) - $levelscore;
}
/**
* Returns the social breadth class of this indicator.
*
* @param string $modname
* @return \core_analytics\local\indicator\base|false
*/
protected function get_social_indicator($modname) {
$indicators = \core_analytics\manager::get_all_indicators();
foreach ($indicators as $indicator) {
if ($indicator instanceof community_of_inquiry_activity &&
$indicator->get_indicator_type() === community_of_inquiry_activity::INDICATOR_SOCIAL &&
$indicator->get_activity_type() === $modname) {
return $indicator;
}
}
return false;
}
/**
* Throw a \coding_exception.
*
* @param int $level
*/
protected function level_not_accepted($level) {
throw new \coding_exception('Activities\' potential social breadth go from 1 to ' .
community_of_inquiry_activity::MAX_SOCIAL_LEVEL . '.');
}
}