MDL-59840 analytics: Enable single range instead of no splitting
[moodle.git] / admin / settings / analytics.php
CommitLineData
369389c9
DM
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 * Adds settings links to admin tree.
19 *
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
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27if ($hassiteconfig) {
28 $settings = new admin_settingpage('analyticssettings', new lang_string('analyticssettings', 'analytics'));
29 $ADMIN->add('appearance', $settings);
30
31 if ($ADMIN->fulltree) {
32 // Select the site prediction's processor.
33 $predictionprocessors = \core_analytics\manager::get_all_prediction_processors();
34 $predictors = array();
35 foreach ($predictionprocessors as $fullclassname => $predictor) {
36 $pluginname = substr($fullclassname, 1, strpos($fullclassname, '\\', 1) - 1);
37 $predictors[$fullclassname] = new lang_string('pluginname', $pluginname);
38 }
39 $settings->add(new \core_analytics\admin_setting_predictor('analytics/predictionsprocessor',
40 new lang_string('predictionsprocessor', 'analytics'), new lang_string('predictionsprocessor_help', 'analytics'),
41 '\mlbackend_php\processor', $predictors)
42 );
43
f67f35f3
DM
44 // Log store.
45 $logmanager = get_log_manager();
46 $readers = $logmanager->get_readers('core\log\sql_reader');
47 $options = array();
1611308b 48 $defaultreader = null;
f67f35f3
DM
49 foreach ($readers as $plugin => $reader) {
50 if (!$reader->is_logging()) {
51 continue;
52 }
53 if (!isset($defaultreader)) {
54 // The top one as default reader.
55 $defaultreader = $plugin;
56 }
57 $options[$plugin] = $reader->get_name();
58 }
85e50ba4
DM
59
60 if (empty($defaultreader)) {
61 // We fall here during initial site installation because log stores are not
62 // enabled until admin/tool/log/db/install.php is executed and get_readers
63 // return nothing.
64
65 if ($enabledlogstores = get_config('tool_log', 'enabled_stores')) {
66 $enabledlogstores = explode(',', $enabledlogstores);
67 $defaultreader = reset($enabledlogstores);
68
69 // No need to set the correct name, just the value, this will not be displayed.
70 $options[$defaultreader] = $defaultreader;
71 }
72 }
f67f35f3
DM
73 $settings->add(new admin_setting_configselect('analytics/logstore',
74 new lang_string('analyticslogstore', 'analytics'), new lang_string('analyticslogstore_help', 'analytics'),
75 $defaultreader, $options));
76
369389c9
DM
77 // Enable/disable time splitting methods.
78 $alltimesplittings = \core_analytics\manager::get_all_time_splittings();
79
80 $timesplittingoptions = array();
206d7aa9 81 $timesplittingdefaults = array('\core\analytics\time_splitting\quarters_accum',
37dec84d 82 '\core\analytics\time_splitting\quarters', '\core\analytics\time_splitting\single_range');
369389c9
DM
83 foreach ($alltimesplittings as $key => $timesplitting) {
84 $timesplittingoptions[$key] = $timesplitting->get_name();
85 }
86 $settings->add(new admin_setting_configmultiselect('analytics/timesplittings',
805b667c 87 new lang_string('enabledtimesplittings', 'analytics'), new lang_string('timesplittingmethod_help', 'analytics'),
369389c9
DM
88 $timesplittingdefaults, $timesplittingoptions)
89 );
90
91 // Predictions processor output dir.
92 $defaultmodeloutputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models';
1cc2b4ba
DM
93 if (empty(get_config('analytics', 'modeloutputdir')) && !file_exists($defaultmodeloutputdir) &&
94 is_writable($defaultmodeloutputdir)) {
95 // Automatically create the dir for them so users don't see the invalid value red cross.
96 mkdir($defaultmodeloutputdir, $CFG->directorypermissions, true);
97 }
369389c9
DM
98 $settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'),
99 new lang_string('modeloutputdirinfo', 'analytics'), $defaultmodeloutputdir));
369389c9
DM
100 }
101}