Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  if ($hassiteconfig && \core_analytics\manager::is_analytics_enabled()) {
  28  
  29      $settings = new admin_settingpage('analyticssite', new lang_string('analyticssiteinfo', 'analytics'));
  30      $ADMIN->add('analytics', $settings);
  31  
  32      if ($ADMIN->fulltree) {
  33          $modeinstructions = [
  34              'facetoface' => get_string('modeinstructionfacetoface', 'analytics'),
  35              'blendedhybrid' => get_string('modeinstructionblendedhybrid', 'analytics'),
  36              'fullyonline' => get_string('modeinstructionfullyonline', 'analytics'),
  37          ];
  38          $settings->add(new admin_setting_configmultiselect('analytics/modeinstruction', get_string('modeinstruction', 'analytics'),
  39              '', [], $modeinstructions));
  40  
  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));
  44  
  45          $typeinstitutions = [
  46              'typeinstitutionacademic' => get_string('typeinstitutionacademic', 'analytics'),
  47              'typeinstitutiontraining' => get_string('typeinstitutiontraining', 'analytics'),
  48              'typeinstitutionngo' => get_string('typeinstitutionngo', 'analytics'),
  49          ];
  50          $settings->add(new admin_setting_configmultiselect('analytics/typeinstitution', get_string('typeinstitution', 'analytics'),
  51              '', [], $typeinstitutions));
  52  
  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'),
  63          ];
  64          $settings->add(new admin_setting_configmultiselect('analytics/levelinstitution',
  65              get_string('levelinstitution', 'analytics'), '', [], $levelinstitutions));
  66      }
  67  
  68      $settings = new admin_settingpage('analyticssettings', new lang_string('analyticssettings', 'analytics'));
  69      $ADMIN->add('analytics', $settings);
  70  
  71      if ($ADMIN->fulltree) {
  72  
  73  
  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);
  80          }
  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)
  84          );
  85  
  86          // Log store.
  87          $logmanager = get_log_manager();
  88          $readers = $logmanager->get_readers('core\log\sql_reader');
  89          $options = array();
  90          $defaultreader = null;
  91          foreach ($readers as $plugin => $reader) {
  92              if (!$reader->is_logging()) {
  93                  continue;
  94              }
  95              if (!isset($defaultreader)) {
  96                  // The top one as default reader.
  97                  $defaultreader = $plugin;
  98              }
  99              $options[$plugin] = $reader->get_name();
 100          }
 101  
 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
 105              // return nothing.
 106  
 107              if ($enabledlogstores = get_config('tool_log', 'enabled_stores')) {
 108                  $enabledlogstores = explode(',', $enabledlogstores);
 109                  $defaultreader = reset($enabledlogstores);
 110  
 111                  // No need to set the correct name, just the value, this will not be displayed.
 112                  $options[$defaultreader] = $defaultreader;
 113              }
 114          }
 115          $settings->add(new admin_setting_configselect('analytics/logstore',
 116              new lang_string('analyticslogstore', 'analytics'), new lang_string('analyticslogstore_help', 'analytics'),
 117              $defaultreader, $options));
 118  
 119          // Enable/disable time splitting methods.
 120          $alltimesplittings = \core_analytics\manager::get_time_splitting_methods_for_evaluation(true);
 121  
 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();
 127          }
 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)
 132          );
 133  
 134          // Predictions processor output dir - specify default in setting description (used if left blank).
 135          $defaultmodeloutputdir = \core_analytics\model::default_output_dir();
 136          $settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'),
 137              new lang_string('modeloutputdirwithdefaultinfo', 'analytics', $defaultmodeloutputdir), ''));
 138  
 139          // Disable web interface evaluation and get predictions.
 140          $settings->add(new admin_setting_configcheckbox('analytics/onlycli', new lang_string('onlycli', 'analytics'),
 141              new lang_string('onlycliinfo', 'analytics'), 1));
 142  
 143          // Training and prediction time limit per model.
 144          $settings->add(new admin_setting_configduration('analytics/modeltimelimit', new lang_string('modeltimelimit', 'analytics'),
 145              new lang_string('modeltimelimitinfo', 'analytics'), 20 * MINSECS));
 146  
 147      }
 148  }