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 * Adds settings links to admin tree.
20 * @package core_analytics
21 * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 if ($hassiteconfig && \core_analytics\manager
::is_analytics_enabled()) {
29 $settings = new admin_settingpage('analyticssite', new lang_string('analyticssiteinfo', 'analytics'));
30 $ADMIN->add('analytics', $settings);
32 if ($ADMIN->fulltree
) {
34 'facetoface' => get_string('modeinstructionfacetoface', 'analytics'),
35 'blendedhybrid' => get_string('modeinstructionblendedhybrid', 'analytics'),
36 'fullyonline' => get_string('modeinstructionfullyonline', 'analytics'),
38 $settings->add(new admin_setting_configmultiselect('analytics/modeinstruction', get_string('modeinstruction', 'analytics'),
39 '', [], $modeinstructions));
41 $settings->add(new admin_setting_configtext_with_maxlength('analytics/percentonline',
42 get_string('percentonline', 'analytics'),
43 get_string('percentonline_help', 'analytics'), '', PARAM_INT
, 3, 3));
46 'typeinstitutionacademic' => get_string('typeinstitutionacademic', 'analytics'),
47 'typeinstitutiontraining' => get_string('typeinstitutiontraining', 'analytics'),
48 'typeinstitutionngo' => get_string('typeinstitutionngo', 'analytics'),
50 $settings->add(new admin_setting_configmultiselect('analytics/typeinstitution', get_string('typeinstitution', 'analytics'),
51 '', [], $typeinstitutions));
53 $levelinstitutions = [
54 'levelinstitutionisced0' => get_string('levelinstitutionisced0', 'analytics'),
55 'levelinstitutionisced1' => get_string('levelinstitutionisced1', 'analytics'),
56 'levelinstitutionisced2' => get_string('levelinstitutionisced2', 'analytics'),
57 'levelinstitutionisced3' => get_string('levelinstitutionisced3', 'analytics'),
58 'levelinstitutionisced4' => get_string('levelinstitutionisced4', 'analytics'),
59 'levelinstitutionisced5' => get_string('levelinstitutionisced5', 'analytics'),
60 'levelinstitutionisced6' => get_string('levelinstitutionisced6', 'analytics'),
61 'levelinstitutionisced7' => get_string('levelinstitutionisced7', 'analytics'),
62 'levelinstitutionisced8' => get_string('levelinstitutionisced8', 'analytics'),
64 $settings->add(new admin_setting_configmultiselect('analytics/levelinstitution',
65 get_string('levelinstitution', 'analytics'), '', [], $levelinstitutions));
68 $settings = new admin_settingpage('analyticssettings', new lang_string('analyticssettings', 'analytics'));
69 $ADMIN->add('analytics', $settings);
71 if ($ADMIN->fulltree
) {
74 // Select the site prediction's processor.
75 $predictionprocessors = \core_analytics\manager
::get_all_prediction_processors();
76 $predictors = array();
77 foreach ($predictionprocessors as $fullclassname => $predictor) {
78 $pluginname = substr($fullclassname, 1, strpos($fullclassname, '\\', 1) - 1);
79 $predictors[$fullclassname] = new lang_string('pluginname', $pluginname);
81 $settings->add(new \core_analytics\admin_setting_predictor
('analytics/predictionsprocessor',
82 new lang_string('defaultpredictionsprocessor', 'analytics'), new lang_string('predictionsprocessor_help', 'analytics'),
83 \core_analytics\manager
::default_mlbackend(), $predictors)
87 $logmanager = get_log_manager();
88 $readers = $logmanager->get_readers('core\log\sql_reader');
90 $defaultreader = null;
91 foreach ($readers as $plugin => $reader) {
92 if (!$reader->is_logging()) {
95 if (!isset($defaultreader)) {
96 // The top one as default reader.
97 $defaultreader = $plugin;
99 $options[$plugin] = $reader->get_name();
102 if (empty($defaultreader)) {
103 // We fall here during initial site installation because log stores are not
104 // enabled until admin/tool/log/db/install.php is executed and get_readers
107 if ($enabledlogstores = get_config('tool_log', 'enabled_stores')) {
108 $enabledlogstores = explode(',', $enabledlogstores);
109 $defaultreader = reset($enabledlogstores);
111 // No need to set the correct name, just the value, this will not be displayed.
112 $options[$defaultreader] = $defaultreader;
115 $settings->add(new admin_setting_configselect('analytics/logstore',
116 new lang_string('analyticslogstore', 'analytics'), new lang_string('analyticslogstore_help', 'analytics'),
117 $defaultreader, $options));
119 // Enable/disable time splitting methods.
120 $alltimesplittings = \core_analytics\manager
::get_time_splitting_methods_for_evaluation(true);
122 $timesplittingoptions = array();
123 $timesplittingdefaults = array('\core\analytics\time_splitting\quarters_accum',
124 '\core\analytics\time_splitting\quarters', '\core\analytics\time_splitting\single_range');
125 foreach ($alltimesplittings as $key => $timesplitting) {
126 $timesplittingoptions[$key] = $timesplitting->get_name();
128 $settings->add(new admin_setting_configmultiselect('analytics/defaulttimesplittingsevaluation',
129 new lang_string('defaulttimesplittingmethods', 'analytics'),
130 new lang_string('defaulttimesplittingmethods_help', 'analytics'),
131 $timesplittingdefaults, $timesplittingoptions)
134 // Predictions processor output dir.
135 $defaultmodeloutputdir = rtrim($CFG->dataroot
, '/') . DIRECTORY_SEPARATOR
. 'models';
136 if (empty(get_config('analytics', 'modeloutputdir')) && !file_exists($defaultmodeloutputdir) &&
137 is_writable($defaultmodeloutputdir)) {
138 // Automatically create the dir for them so users don't see the invalid value red cross.
139 mkdir($defaultmodeloutputdir, $CFG->directorypermissions
, true);
141 $settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'),
142 new lang_string('modeloutputdirinfo', 'analytics'), $defaultmodeloutputdir));
144 // Disable web interface evaluation and get predictions.
145 $settings->add(new admin_setting_configcheckbox('analytics/onlycli', new lang_string('onlycli', 'analytics'),
146 new lang_string('onlycliinfo', 'analytics'), 1));
148 // Training and prediction time limit per model.
149 $settings->add(new admin_setting_configduration('analytics/modeltimelimit', new lang_string('modeltimelimit', 'analytics'),
150 new lang_string('modeltimelimitinfo', 'analytics'), 20 * MINSECS
));