MDL-65585 analytics: Global on/off switch
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
if ($hassiteconfig) {
|
||||
if ($hassiteconfig && \core_analytics\manager::is_analytics_enabled()) {
|
||||
|
||||
$settings = new admin_settingpage('analyticssite', new lang_string('analyticssiteinfo', 'analytics'));
|
||||
$ADMIN->add('analytics', $settings);
|
||||
|
||||
@@ -48,4 +48,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
|
||||
$optionalsubsystems->add(new admin_setting_configcheckbox('allowstealth', new lang_string('allowstealthmodules'),
|
||||
new lang_string('allowstealthmodules_help'), 0, 1, 0));
|
||||
|
||||
$optionalsubsystems->add(new admin_setting_configcheckbox('enableanalytics', new lang_string('enableanalytics', 'admin'),
|
||||
new lang_string('configenableanalytics', 'admin'), 1, 1, 0));
|
||||
}
|
||||
|
||||
@@ -229,4 +229,26 @@ class renderer extends plugin_renderer_base {
|
||||
$data = $invalidanalysables->export_for_template($this);
|
||||
return parent::render_from_template('tool_analytics/invalid_analysables', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an analytics disabled notification.
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function render_analytics_disabled() {
|
||||
global $OUTPUT, $PAGE, $FULLME;
|
||||
|
||||
$PAGE->set_url($FULLME);
|
||||
$PAGE->set_title(get_string('pluginname', 'tool_analytics'));
|
||||
$PAGE->set_heading(get_string('pluginname', 'tool_analytics'));
|
||||
|
||||
$output = $OUTPUT->header();
|
||||
$output .= $OUTPUT->notification(get_string('analyticsdisabled', 'analytics'), \core\output\notification::NOTIFY_INFO);
|
||||
$output .= \html_writer::tag('a', get_string('continue'), ['class' => 'btn btn-primary',
|
||||
'href' => (new \moodle_url('/'))->out()]);
|
||||
$output .= $OUTPUT->footer();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,6 +52,11 @@ class predict_models extends \core\task\scheduled_task {
|
||||
public function execute() {
|
||||
global $OUTPUT, $PAGE;
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
mtrace(get_string('analyticsdisabled', 'analytics'));
|
||||
return;
|
||||
}
|
||||
|
||||
$models = \core_analytics\manager::get_all_models(true, true);
|
||||
if (!$models) {
|
||||
mtrace(get_string('errornoenabledandtrainedmodels', 'tool_analytics'));
|
||||
|
||||
@@ -52,6 +52,11 @@ class train_models extends \core\task\scheduled_task {
|
||||
public function execute() {
|
||||
global $OUTPUT, $PAGE;
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
mtrace(get_string('analyticsdisabled', 'analytics'));
|
||||
return;
|
||||
}
|
||||
|
||||
$models = \core_analytics\manager::get_all_models(true);
|
||||
if (!$models) {
|
||||
mtrace(get_string('errornoenabledmodels', 'tool_analytics'));
|
||||
|
||||
@@ -57,6 +57,11 @@ if ($options['help']) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
echo get_string('analyticsdisabled', 'analytics') . PHP_EOL;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if ($options['list'] || $options['modelid'] === false) {
|
||||
\tool_analytics\clihelper::list_models();
|
||||
exit(0);
|
||||
|
||||
@@ -67,6 +67,11 @@ if ($options['help']) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
echo get_string('analyticsdisabled', 'analytics') . PHP_EOL;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if ($options['list']) {
|
||||
\tool_analytics\clihelper::list_models();
|
||||
exit(0);
|
||||
|
||||
@@ -27,6 +27,13 @@ require_once(__DIR__ . '/../../../config.php');
|
||||
require_login();
|
||||
\core_analytics\manager::check_can_manage_models();
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
$PAGE->set_context(\context_system::instance());
|
||||
$renderer = $PAGE->get_renderer('tool_analytics');
|
||||
echo $renderer->render_analytics_disabled();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$returnurl = new \moodle_url('/admin/tool/analytics/index.php');
|
||||
$url = new \moodle_url('/admin/tool/analytics/createmodel.php');
|
||||
$title = get_string('createmodel', 'tool_analytics');
|
||||
|
||||
@@ -27,6 +27,13 @@ require_once(__DIR__ . '/../../../config.php');
|
||||
require_login();
|
||||
\core_analytics\manager::check_can_manage_models();
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
$PAGE->set_context(\context_system::instance());
|
||||
$renderer = $PAGE->get_renderer('tool_analytics');
|
||||
echo $renderer->render_analytics_disabled();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$returnurl = new \moodle_url('/admin/tool/analytics/index.php');
|
||||
$url = new \moodle_url('/admin/tool/analytics/importmodel.php');
|
||||
$title = get_string('importmodel', 'tool_analytics');
|
||||
@@ -56,4 +63,4 @@ if ($form->is_cancelled()) {
|
||||
|
||||
echo $OUTPUT->header();
|
||||
$form->display();
|
||||
echo $OUTPUT->footer();
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -33,6 +33,13 @@ require_login();
|
||||
$model = new \core_analytics\model($id);
|
||||
\core_analytics\manager::check_can_manage_models();
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
$PAGE->set_context(\context_system::instance());
|
||||
$renderer = $PAGE->get_renderer('tool_analytics');
|
||||
echo $renderer->render_analytics_disabled();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$returnurl = new \moodle_url('/admin/tool/analytics/index.php');
|
||||
$params = array('id' => $id, 'action' => $action);
|
||||
$url = new \moodle_url('/admin/tool/analytics/model.php', $params);
|
||||
|
||||
@@ -27,6 +27,13 @@ require_once(__DIR__ . '/../../../config.php');
|
||||
require_login();
|
||||
\core_analytics\manager::check_can_manage_models();
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
$PAGE->set_context(\context_system::instance());
|
||||
$renderer = $PAGE->get_renderer('tool_analytics');
|
||||
echo $renderer->render_analytics_disabled();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
$restoreids = optional_param_array('restoreid', [], PARAM_ALPHANUM);
|
||||
|
||||
|
||||
@@ -24,5 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$ADMIN->add('analytics', new admin_externalpage('analyticmodels', get_string('analyticmodels', 'tool_analytics'),
|
||||
"$CFG->wwwroot/$CFG->admin/tool/analytics/index.php", 'moodle/analytics:managemodels'));
|
||||
if (\core_analytics\manager::is_analytics_enabled()) {
|
||||
$ADMIN->add('analytics', new admin_externalpage('analyticmodels', get_string('analyticmodels', 'tool_analytics'),
|
||||
"$CFG->wwwroot/$CFG->admin/tool/analytics/index.php", 'moodle/analytics:managemodels'));
|
||||
}
|
||||
|
||||
@@ -99,6 +99,22 @@ class manager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is analytics enabled globally?
|
||||
*
|
||||
* return bool
|
||||
*/
|
||||
public static function is_analytics_enabled(): bool {
|
||||
global $CFG;
|
||||
|
||||
if (isset($CFG->enableanalytics)) {
|
||||
return $CFG->enableanalytics;
|
||||
}
|
||||
|
||||
// Enabled by default.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all system models that match the provided filters.
|
||||
*
|
||||
|
||||
@@ -209,6 +209,7 @@ $string['configdefaultuserroleid'] = 'All logged in users will be given the capa
|
||||
$string['configdeleteincompleteusers'] = 'After this period, any account without the first name, last name or email field filled in is deleted.';
|
||||
$string['configdeleteunconfirmed'] = 'For certain authentication methods, such as email-based self-registration, users must confirm their account within a certain time. After this period, any old unconfirmed accounts are deleted.';
|
||||
$string['configdenyemailaddresses'] = 'To deny email addresses from particular domains list them here in the same way. All other domains will be accepted. To deny subdomains add the domain with a preceding \'.\'. eg <strong>hotmail.com yahoo.co.uk .live.com</strong>';
|
||||
$string['configenableanalytics'] = 'Analytics models, such as \'Students at risk of dropping out\' or \'Upcoming activities due\', can generate predictions, send insight notifications and offer further actions such as messaging users.';
|
||||
$string['configenableblogs'] = 'This switch provides all site users with their own blog.';
|
||||
$string['configenabledevicedetection'] = 'Enables detection of mobiles, smartphones, tablets or default devices (desktop PCs, laptops, etc) for the application of themes and other features.';
|
||||
$string['configdisableuserimages'] = 'Disable the ability for users to change user profile images.';
|
||||
@@ -514,6 +515,7 @@ $string['emoticons_desc'] = 'This form defines the emoticons (or smileys) used a
|
||||
$string['emoticonsreset'] = 'Reset emoticons setting to default values';
|
||||
$string['emptysettingvalue'] = 'Empty';
|
||||
$string['enableactivitychooser'] = 'Enable activity chooser';
|
||||
$string['enableanalytics'] = 'Analytics';
|
||||
$string['enableblogs'] = 'Enable blogs';
|
||||
$string['enablecalendarexport'] = 'Enable calendar export';
|
||||
$string['enablecomments'] = 'Enable comments';
|
||||
|
||||
@@ -26,6 +26,7 @@ $string['analysablenotused'] = 'Analysable {$a->analysableid} not used: {$a->err
|
||||
$string['analysablenotvalidfortarget'] = 'Analysable {$a->analysableid} is not valid for this target: {$a->result}';
|
||||
$string['analysisinprogress'] = 'Still being analysed by a previous execution';
|
||||
$string['analytics'] = 'Analytics';
|
||||
$string['analyticsdisabled'] = 'Analytics is disabled. You can enable it in "Site administration > Advanced features".';
|
||||
$string['analyticslogstore'] = 'Log store used for analytics';
|
||||
$string['analyticslogstore_help'] = 'The log store that will be used by the analytics API to read users\' activity.';
|
||||
$string['analyticssettings'] = 'Analytics settings';
|
||||
|
||||
@@ -50,6 +50,11 @@ class analytics_cleanup_task extends \core\task\scheduled_task {
|
||||
* @return void
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
mtrace(get_string('analyticsdisabled', 'analytics'));
|
||||
return;
|
||||
}
|
||||
$models = \core_analytics\manager::cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,13 @@ $predictionid = required_param('predictionid', PARAM_INT);
|
||||
$actionname = required_param('action', PARAM_ALPHANUMEXT);
|
||||
$forwardurl = required_param('forwardurl', PARAM_LOCALURL);
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
$PAGE->set_context(\context_system::instance());
|
||||
$renderer = $PAGE->get_renderer('report_insights');
|
||||
echo $renderer->render_analytics_disabled();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
list($model, $prediction, $context) = \core_analytics\manager::get_prediction($predictionid, true);
|
||||
if ($context->contextlevel < CONTEXT_COURSE) {
|
||||
// Only for higher levels than course.
|
||||
|
||||
@@ -121,4 +121,25 @@ class renderer extends plugin_renderer_base {
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an analytics disabled notification.
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function render_analytics_disabled() {
|
||||
global $OUTPUT, $PAGE, $FULLME;
|
||||
|
||||
$PAGE->set_url($FULLME);
|
||||
$PAGE->set_title(get_string('pluginname', 'report_insights'));
|
||||
$PAGE->set_heading(get_string('pluginname', 'report_insights'));
|
||||
|
||||
$output = $OUTPUT->header();
|
||||
$output .= $OUTPUT->notification(get_string('analyticsdisabled', 'analytics'), \core\output\notification::NOTIFY_INFO);
|
||||
$output .= \html_writer::tag('a', get_string('continue'), ['class' => 'btn btn-primary',
|
||||
'href' => (new \moodle_url('/'))->out()]);
|
||||
$output .= $OUTPUT->footer();
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,13 @@ $actionvisiblename = required_param('actionvisiblename', PARAM_NOTAGS);
|
||||
|
||||
$PAGE->set_pagelayout('popup');
|
||||
$PAGE->set_context(\context_system::instance());
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
$renderer = $PAGE->get_renderer('report_insights');
|
||||
echo $renderer->render_analytics_disabled();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$PAGE->set_title(get_site()->fullname);
|
||||
$PAGE->set_url(new \moodle_url('/report/insights/done.php'));
|
||||
|
||||
|
||||
@@ -41,6 +41,12 @@ if ($context->contextlevel < CONTEXT_COURSE) {
|
||||
$PAGE->set_context($context);
|
||||
}
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
$renderer = $PAGE->get_renderer('report_insights');
|
||||
echo $renderer->render_analytics_disabled();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
\core_analytics\manager::check_can_list_insights($context);
|
||||
|
||||
// Get all models that are enabled, trained and have predictions at this context.
|
||||
|
||||
+12
-10
@@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die;
|
||||
*/
|
||||
function report_insights_extend_navigation_course($navigation, $course, $context) {
|
||||
|
||||
if (has_capability('moodle/analytics:listinsights', $context)) {
|
||||
if (\core_analytics\manager::is_analytics_enabled() && has_capability('moodle/analytics:listinsights', $context)) {
|
||||
|
||||
$modelids = \core_analytics\manager::cached_models_with_insights($context);
|
||||
if (!empty($modelids)) {
|
||||
@@ -58,15 +58,17 @@ function report_insights_extend_navigation_course($navigation, $course, $context
|
||||
*/
|
||||
function report_insights_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
|
||||
|
||||
$context = \context_user::instance($user->id);
|
||||
if (\core_analytics\manager::check_can_list_insights($context, true)) {
|
||||
if (\core_analytics\manager::is_analytics_enabled()) {
|
||||
$context = \context_user::instance($user->id);
|
||||
if (\core_analytics\manager::check_can_list_insights($context, true)) {
|
||||
|
||||
$modelids = \core_analytics\manager::cached_models_with_insights($context);
|
||||
if (!empty($modelids)) {
|
||||
$url = new moodle_url('/report/insights/insights.php', array('contextid' => $context->id));
|
||||
$node = new core_user\output\myprofile\node('reports', 'insights', get_string('insights', 'report_insights'),
|
||||
null, $url);
|
||||
$tree->add_node($node);
|
||||
$modelids = \core_analytics\manager::cached_models_with_insights($context);
|
||||
if (!empty($modelids)) {
|
||||
$url = new moodle_url('/report/insights/insights.php', array('contextid' => $context->id));
|
||||
$node = new core_user\output\myprofile\node('reports', 'insights', get_string('insights', 'report_insights'),
|
||||
null, $url);
|
||||
$tree->add_node($node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +82,7 @@ function report_insights_myprofile_navigation(core_user\output\myprofile\tree $t
|
||||
*/
|
||||
function report_insights_extend_navigation_category_settings($navigation, $context) {
|
||||
|
||||
if (has_capability('moodle/analytics:listinsights', $context)) {
|
||||
if (\core_analytics\manager::is_analytics_enabled() && has_capability('moodle/analytics:listinsights', $context)) {
|
||||
|
||||
$modelids = \core_analytics\manager::cached_models_with_insights($context);
|
||||
if (!empty($modelids)) {
|
||||
|
||||
@@ -27,6 +27,13 @@ require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
$predictionid = required_param('id', PARAM_INT);
|
||||
|
||||
if (!\core_analytics\manager::is_analytics_enabled()) {
|
||||
$PAGE->set_context(\context_system::instance());
|
||||
$renderer = $PAGE->get_renderer('report_insights');
|
||||
echo $renderer->render_analytics_disabled();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
list($model, $prediction, $context) = \core_analytics\manager::get_prediction($predictionid, true);
|
||||
if ($context->contextlevel < CONTEXT_COURSE) {
|
||||
// Only for higher levels than course.
|
||||
|
||||
@@ -26,9 +26,11 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
// Just a link to course report.
|
||||
$ADMIN->add('reports', new admin_externalpage('reportinsights', get_string('insights', 'report_insights'),
|
||||
$CFG->wwwroot . "/report/insights/insights.php?contextid=" . SYSCONTEXTID, 'moodle/analytics:listinsights'));
|
||||
if (\core_analytics\manager::is_analytics_enabled()) {
|
||||
// Just a link to course report.
|
||||
$ADMIN->add('reports', new admin_externalpage('reportinsights', get_string('insights', 'report_insights'),
|
||||
$CFG->wwwroot . "/report/insights/insights.php?contextid=" . SYSCONTEXTID, 'moodle/analytics:listinsights'));
|
||||
|
||||
// No report settings.
|
||||
$settings = null;
|
||||
// No report settings.
|
||||
$settings = null;
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2019100800.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2019100800.04; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user