admin/tool/usertours/amd/src/tour.js
admin/tool/usertours/amd/src/popper.js
auth/cas/CAS/
-auth/fc/fcFPP.php
enrol/lti/ims-blti/
filter/algebra/AlgParser.pm
filter/tex/mimetex.*
lib/editor/tinymce/plugins/pdw/tinymce/
lib/editor/tinymce/plugins/spellchecker/rpc.php
lib/editor/tinymce/tiny_mce/
+lib/mlbackend/php/phpml/
lib/adodb/
lib/bennu/
lib/evalmath/
lib/ltiprovider/
lib/amd/src/truncate.js
lib/fonts/
+lib/validateurlsyntax.php
media/player/videojs/amd/src/video-lazy.js
media/player/videojs/amd/src/Youtube-lazy.js
media/player/videojs/videojs/
admin/tool/usertours/amd/src/tour.js
admin/tool/usertours/amd/src/popper.js
auth/cas/CAS/
-auth/fc/fcFPP.php
enrol/lti/ims-blti/
filter/algebra/AlgParser.pm
filter/tex/mimetex.*
lib/editor/tinymce/plugins/pdw/tinymce/
lib/editor/tinymce/plugins/spellchecker/rpc.php
lib/editor/tinymce/tiny_mce/
+lib/mlbackend/php/phpml/
lib/adodb/
lib/bennu/
lib/evalmath/
lib/ltiprovider/
lib/amd/src/truncate.js
lib/fonts/
+lib/validateurlsyntax.php
media/player/videojs/amd/src/video-lazy.js
media/player/videojs/amd/src/Youtube-lazy.js
media/player/videojs/videojs/
php:
# We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
- 7.1
- - 5.6
+ - 7.0
addons:
postgresql: "9.3"
# Exclude it on all versions except for 7.1
- env: DB=mysqli TASK=PHPUNIT
- php: 5.6
-
- # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
- - env: DB=pgsql TASK=UPGRADE
- php: 7.1
+ php: 7.0
cache:
directories:
- $HOME/.npm
install:
- - sudo apt-get -y install haveged
- - sudo service haveged start
- >
if [ "$DB" = 'mysqli' ];
then
# We need the official upstream.
git remote add upstream https://github.com/moodle/moodle.git;
- # Checkout 27 STABLE branch.
- git fetch upstream MOODLE_27_STABLE;
- git checkout MOODLE_27_STABLE;
+ # Checkout 30 STABLE branch (the first version compatible with PHP 7.x)
+ git fetch upstream MOODLE_30_STABLE;
+ git checkout MOODLE_30_STABLE;
# Perform the upgrade
php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
$savebutton = false;
$outputhtml = '';
foreach ($settingspage->children as $childpage) {
- if ($childpage->is_hidden()) {
+ if ($childpage->is_hidden() || !$childpage->check_access()) {
continue;
}
if ($childpage instanceof admin_externalpage) {
define('IGNORE_COMPONENT_CACHE', true);
-// Check that PHP is of a sufficient version
-if (version_compare(phpversion(), "5.6.5") < 0) {
- $phpversion = phpversion();
- // do NOT localise - lang strings would not work here and we CAN NOT move it after installib
- fwrite(STDERR, "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).\n");
- fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n");
- exit(1);
-}
+// Check that PHP is of a sufficient version as soon as possible.
+require_once(__DIR__.'/../../lib/phpminimumversionlib.php');
+moodle_require_minimum_php_version();
// set up configuration
global $CFG;
if (!$options['skip-database']) {
install_cli_database($options, $interactive);
+ // This needs to happen at the end to ensure it occurs after all caches
+ // have been purged for the last time.
+ // This will build a cached version of the current theme for the user
+ // to immediately start browsing the site.
+ require_once($CFG->libdir.'/upgradelib.php');
+ upgrade_themes();
} else {
echo get_string('cliskipdatabase', 'install')."\n";
}
\$sudo -u www-data /usr/bin/php admin/cli/install_database.php --lang=cs --adminpass=soMePass123 --agree-license
";
-// Check that PHP is of a sufficient version
-if (version_compare(phpversion(), "5.6.5") < 0) {
- $phpversion = phpversion();
- // do NOT localise - lang strings would not work here and we CAN NOT move it after installib
- fwrite(STDERR, "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).\n");
- fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n");
- exit(1);
-}
+// Check that PHP is of a sufficient version as soon as possible.
+require_once(__DIR__.'/../../lib/phpminimumversionlib.php');
+moodle_require_minimum_php_version();
// Nothing to do if config.php does not exist
$configfile = __DIR__.'/../../config.php';
install_cli_database($options, true);
+// This needs to happen at the end to ensure it occurs after all caches
+// have been purged for the last time.
+// This will build a cached version of the current theme for the user
+// to immediately start browsing the site.
+require_once($CFG->libdir.'/upgradelib.php');
+upgrade_themes();
+
echo get_string('cliinstallfinished', 'install')."\n";
exit(0); // 0 means success
admin_apply_default_settings(NULL, false);
admin_apply_default_settings(NULL, false);
+// This needs to happen at the end to ensure it occurs after all caches
+// have been purged for the last time.
+// This will build a cached version of the current theme for the user
+// to immediately start browsing the site.
+upgrade_themes();
+
echo get_string('cliupgradefinished', 'admin')."\n";
exit(0); // 0 means success
</CUSTOM_CHECK>
</CUSTOM_CHECKS>
</MOODLE>
+ <MOODLE version="3.4" requires="3.0">
+ <UNICODE level="required">
+ <FEEDBACK>
+ <ON_ERROR message="unicoderequired" />
+ </FEEDBACK>
+ </UNICODE>
+ <DATABASE level="required">
+ <VENDOR name="mariadb" version="5.5.31" />
+ <VENDOR name="mysql" version="5.5.31" />
+ <VENDOR name="postgres" version="9.3" />
+ <VENDOR name="mssql" version="10.0" />
+ <VENDOR name="oracle" version="10.2" />
+ </DATABASE>
+ <PHP version="7.0.0" level="required">
+ </PHP>
+ <PCREUNICODE level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="pcreunicodewarning" />
+ </FEEDBACK>
+ </PCREUNICODE>
+ <PHP_EXTENSIONS>
+ <PHP_EXTENSION name="iconv" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="iconvrequired" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="mbstring" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="mbstringrecommended" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="curl" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="curlrequired" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="openssl" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="opensslrequired" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="tokenizer" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="tokenizerrecommended" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="xmlrpc" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="xmlrpcrecommended" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="soap" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="soaprecommended" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="ctype" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="ctyperequired" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="zip" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="ziprequired" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="zlib" level="required">
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="gd" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="gdrequired" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="simplexml" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="simplexmlrequired" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="spl" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="splrequired" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="pcre" level="required">
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="dom" level="required">
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="xml" level="required">
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="xmlreader" level="required">
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="intl" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="intlrequired" />
+ </FEEDBACK>
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="json" level="required">
+ </PHP_EXTENSION>
+ <PHP_EXTENSION name="hash" level="required"/>
+ <PHP_EXTENSION name="fileinfo" level="required"/>
+ </PHP_EXTENSIONS>
+ <PHP_SETTINGS>
+ <PHP_SETTING name="memory_limit" value="96M" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="settingmemorylimit" />
+ </FEEDBACK>
+ </PHP_SETTING>
+ <PHP_SETTING name="file_uploads" value="1" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="settingfileuploads" />
+ </FEEDBACK>
+ </PHP_SETTING>
+ <PHP_SETTING name="opcache.enable" value="1" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="opcacherecommended" />
+ </FEEDBACK>
+ </PHP_SETTING>
+ </PHP_SETTINGS>
+ <CUSTOM_CHECKS>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_database_storage_engine" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="unsupporteddbstorageengine" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="question/engine/upgrade/upgradelib.php" function="quiz_attempts_upgraded" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="quizattemptsupgradedmessage" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_slasharguments" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="slashargumentswarning" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_database_tables_row_format" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="unsupporteddbtablerowformat" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_unoconv_version" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="unoconvwarning" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_libcurl_version" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="libcurlwarning" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_mysql_file_format" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="unsupporteddbfileformat" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_mysql_file_per_table" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="unsupporteddbfilepertable" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_mysql_large_prefix" level="required">
+ <FEEDBACK>
+ <ON_ERROR message="unsupporteddblargeprefix" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_is_https" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="ishttpswarning" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ <CUSTOM_CHECK file="lib/upgradelib.php" function="check_mysql_incomplete_unicode_support" level="optional">
+ <FEEDBACK>
+ <ON_CHECK message="incompleteunicodesupport" />
+ </FEEDBACK>
+ </CUSTOM_CHECK>
+ </CUSTOM_CHECKS>
+ </MOODLE>
</COMPATIBILITY_MATRIX>
die();
}
-// Check that PHP is of a sufficient version as soon as possible
-if (version_compare(phpversion(), '5.6.5') < 0) {
- $phpversion = phpversion();
- // do NOT localise - lang strings would not work here and we CAN NOT move it to later place
- echo "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).<br />";
- echo "Please upgrade your server software or install older Moodle version.";
- die();
-}
+// Check that PHP is of a sufficient version as soon as possible.
+require_once(__DIR__.'/../lib/phpminimumversionlib.php');
+moodle_require_minimum_php_version();
// make sure iconv is available and actually works
if (!function_exists('iconv')) {
$imageurl = get_config('hub', 'site_imageurl_' . $cleanhuburl);
$privacy = get_config('hub', 'site_privacy_' . $cleanhuburl);
$address = get_config('hub', 'site_address_' . $cleanhuburl);
+ if ($address === false) {
+ $address = '';
+ }
$region = get_config('hub', 'site_region_' . $cleanhuburl);
$country = get_config('hub', 'site_country_' . $cleanhuburl);
- if ($country === false) {
- $country = $admin->country;
+ if (empty($country)) {
+ $country = $admin->country ?: $CFG->country;
}
$language = get_config('hub', 'site_language_' . $cleanhuburl);
if ($language === false) {
$language = explode('_', current_language())[0];
}
$geolocation = get_config('hub', 'site_geolocation_' . $cleanhuburl);
+ if ($geolocation === false) {
+ $geolocation = '';
+ }
$contactable = get_config('hub', 'site_contactable_' . $cleanhuburl);
$emailalert = get_config('hub', 'site_emailalert_' . $cleanhuburl);
- $emailalert = ($emailalert === 0) ? 0 : 1;
+ $emailalert = ($emailalert === false || $emailalert) ? 1 : 0;
$coursesnumber = get_config('hub', 'site_coursesnumber_' . $cleanhuburl);
$usersnumber = get_config('hub', 'site_usersnumber_' . $cleanhuburl);
$roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_' . $cleanhuburl);
$mform->addElement('hidden', 'regioncode', '-');
$mform->setType('regioncode', PARAM_ALPHANUMEXT);
- $countries = get_string_manager()->get_list_of_countries();
+ $countries = ['' => ''] + get_string_manager()->get_list_of_countries();
$mform->addElement('select', 'countrycode', get_string('sitecountry', 'hub'), $countries);
$mform->setDefault('countrycode', $country);
$mform->setType('countrycode', PARAM_ALPHANUMEXT);
$mform->addHelpButton('countrycode', 'sitecountry', 'hub');
+ $mform->addRule('countrycode', $strrequired, 'required', null, 'client');
$mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'),
array('class' => 'registration_textfield'));
$mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'),
array('class' => 'registration_textfield'));
$mform->setType('contactphone', PARAM_TEXT);
+ $mform->setDefault('contactphone', $contactphone);
$mform->addHelpButton('contactphone', 'sitephone', 'hub');
$mform->setForceLtr('contactphone');
$areasconfig[$areaid]->docsprocessed . ' , ' .
$areasconfig[$areaid]->recordsprocessed . ' , ' .
$areasconfig[$areaid]->docsignored;
+ if ($areasconfig[$areaid]->partial) {
+ $laststatus .= ' ' . get_string('searchpartial', 'admin');
+ }
} else {
$laststatus = '';
}
--- /dev/null
+<?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/>.
+
+/**
+ * Adds settings links to admin tree.
+ *
+ * @package core_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+if ($hassiteconfig) {
+ $settings = new admin_settingpage('analyticssettings', new lang_string('analyticssettings', 'analytics'));
+ $ADMIN->add('appearance', $settings);
+
+ if ($ADMIN->fulltree) {
+ // Select the site prediction's processor.
+ $predictionprocessors = \core_analytics\manager::get_all_prediction_processors();
+ $predictors = array();
+ foreach ($predictionprocessors as $fullclassname => $predictor) {
+ $pluginname = substr($fullclassname, 1, strpos($fullclassname, '\\', 1) - 1);
+ $predictors[$fullclassname] = new lang_string('pluginname', $pluginname);
+ }
+ $settings->add(new \core_analytics\admin_setting_predictor('analytics/predictionsprocessor',
+ new lang_string('predictionsprocessor', 'analytics'), new lang_string('predictionsprocessor_help', 'analytics'),
+ '\mlbackend_php\processor', $predictors)
+ );
+
+ // Log store.
+ $logmanager = get_log_manager();
+ $readers = $logmanager->get_readers('core\log\sql_reader');
+ $options = array();
+ $defaultreader = null;
+ foreach ($readers as $plugin => $reader) {
+ if (!$reader->is_logging()) {
+ continue;
+ }
+ if (!isset($defaultreader)) {
+ // The top one as default reader.
+ $defaultreader = $plugin;
+ }
+ $options[$plugin] = $reader->get_name();
+ }
+ $settings->add(new admin_setting_configselect('analytics/logstore',
+ new lang_string('analyticslogstore', 'analytics'), new lang_string('analyticslogstore_help', 'analytics'),
+ $defaultreader, $options));
+
+ // Enable/disable time splitting methods.
+ $alltimesplittings = \core_analytics\manager::get_all_time_splittings();
+
+ $timesplittingoptions = array();
+ $timesplittingdefaults = array('\core\analytics\time_splitting\quarters_accum',
+ '\core\analytics\time_splitting\quarters', '\core\analytics\time_splitting\no_splitting');
+ foreach ($alltimesplittings as $key => $timesplitting) {
+ $timesplittingoptions[$key] = $timesplitting->get_name();
+ }
+ $settings->add(new admin_setting_configmultiselect('analytics/timesplittings',
+ new lang_string('enabledtimesplittings', 'analytics'), new lang_string('enabledtimesplittings_help', 'analytics'),
+ $timesplittingdefaults, $timesplittingoptions)
+ );
+
+ // Predictions processor output dir.
+ $defaultmodeloutputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models';
+ if (empty(get_config('analytics', 'modeloutputdir')) && !file_exists($defaultmodeloutputdir) &&
+ is_writable($defaultmodeloutputdir)) {
+ // Automatically create the dir for them so users don't see the invalid value red cross.
+ mkdir($defaultmodeloutputdir, $CFG->directorypermissions, true);
+ }
+ $settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'),
+ new lang_string('modeloutputdirinfo', 'analytics'), $defaultmodeloutputdir));
+ }
+}
$temp->add(new admin_setting_heading('searchengineheading', new lang_string('searchengine', 'admin'), ''));
$temp->add(new admin_setting_configselect('searchengine',
new lang_string('selectsearchengine', 'admin'), '', 'solr', $engines));
+ $temp->add(new admin_setting_heading('searchindexingheading', new lang_string('searchoptions', 'admin'), ''));
+ $temp->add(new admin_setting_configcheckbox('searchindexwhendisabled',
+ new lang_string('searchindexwhendisabled', 'admin'), new lang_string('searchindexwhendisabled_desc', 'admin'),
+ 0));
+ $temp->add(new admin_setting_configduration('searchindextime',
+ new lang_string('searchindextime', 'admin'), new lang_string('searchindextime_desc', 'admin'),
+ 600));
$ADMIN->add('searchplugins', $temp);
$ADMIN->add('searchplugins', new admin_externalpage('searchareas', new lang_string('searchareas', 'admin'),
--- /dev/null
+// 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/>.
+
+/**
+ * Shows a dialogue with info about this logs.
+ *
+ * @module tool_analytics/log_info
+ * @class log_info
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+define(['jquery', 'core/str', 'core/modal_factory', 'core/notification'], function($, str, ModalFactory, Notification) {
+
+ return /** @alias module:tool_analytics/log_info */ {
+
+ /**
+ * Prepares a modal info for a log's results.
+ *
+ * @method loadInfo
+ * @param {int} id
+ * @param {string[]} info
+ */
+ loadInfo: function(id, info) {
+
+ var link = $('[data-model-log-id="' + id + '"]');
+ str.get_string('loginfo', 'tool_analytics').then(function(langString) {
+
+ var bodyInfo = $("<ul>");
+ info.forEach(function(item) {
+ bodyInfo.append('<li>' + item + '</li>');
+ });
+ bodyInfo.append("</ul>");
+
+ return ModalFactory.create({
+ title: langString,
+ body: bodyInfo.html(),
+ large: true,
+ }, link);
+
+ }).catch(Notification.exception);
+ }
+ };
+});
--- /dev/null
+<?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/>.
+
+/**
+ * Model edit form.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_analytics\output\form;
+
+defined('MOODLE_INTERNAL') || die();
+
+require_once($CFG->dirroot.'/lib/formslib.php');
+
+/**
+ * Model edit form.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class edit_model extends \moodleform {
+
+ /**
+ * Form definition
+ */
+ public function definition() {
+ global $OUTPUT;
+
+ $mform = $this->_form;
+
+ if ($this->_customdata['model']->get_model_obj()->trained == 1) {
+ $message = get_string('edittrainedwarning', 'tool_analytics');
+ $mform->addElement('html', $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING));
+ }
+
+ $mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'tool_analytics'));
+
+ $indicators = array();
+ foreach ($this->_customdata['indicators'] as $classname => $indicator) {
+ $optionname = \tool_analytics\output\helper::class_to_option($classname);
+ $indicators[$optionname] = $indicator->get_name();
+ }
+ $options = array(
+ 'multiple' => true
+ );
+ $mform->addElement('autocomplete', 'indicators', get_string('indicators', 'tool_analytics'), $indicators, $options);
+ $mform->setType('indicators', PARAM_ALPHANUMEXT);
+
+ $timesplittings = array('' => '');
+ foreach ($this->_customdata['timesplittings'] as $classname => $timesplitting) {
+ $optionname = \tool_analytics\output\helper::class_to_option($classname);
+ $timesplittings[$optionname] = $timesplitting->get_name();
+ }
+
+ $mform->addElement('select', 'timesplitting', get_string('timesplittingmethod', 'analytics'), $timesplittings);
+ $mform->addHelpButton('timesplitting', 'timesplittingmethod', 'analytics');
+
+ $mform->addElement('hidden', 'id', $this->_customdata['id']);
+ $mform->setType('id', PARAM_INT);
+
+ $mform->addElement('hidden', 'action', 'edit');
+ $mform->setType('action', PARAM_ALPHANUMEXT);
+
+ $this->add_action_buttons();
+ }
+
+ /**
+ * Form validation
+ *
+ * @param array $data data from the form.
+ * @param array $files files uploaded.
+ *
+ * @return array of errors.
+ */
+ public function validation($data, $files) {
+ $errors = parent::validation($data, $files);
+
+ if (!empty($data['timesplitting'])) {
+ $realtimesplitting = \tool_analytics\output\helper::option_to_class($data['timesplitting']);
+ if (\core_analytics\manager::is_valid($realtimesplitting, '\core_analytics\local\time_splitting\base') === false) {
+ $errors['timesplitting'] = get_string('errorinvalidtimesplitting', 'analytics');
+ }
+ }
+
+ if (empty($data['indicators'])) {
+ $errors['indicators'] = get_string('errornoindicators', 'analytics');
+ } else {
+ foreach ($data['indicators'] as $indicator) {
+ $realindicatorname = \tool_analytics\output\helper::option_to_class($indicator);
+ if (\core_analytics\manager::is_valid($realindicatorname, '\core_analytics\local\indicator\base') === false) {
+ $errors['indicators'] = get_string('errorinvalidindicator', 'analytics', $realindicatorname);
+ }
+ }
+ }
+
+ if (!empty($data['enabled']) && empty($data['timesplitting'])) {
+ $errors['enabled'] = get_string('errorcantenablenotimesplitting', 'tool_analytics');
+ }
+
+ return $errors;
+ }
+}
--- /dev/null
+<?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/>.
+
+/**
+ * Typical crappy helper class with tiny functions.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_analytics\output;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Helper class with general purpose tiny functions.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class helper {
+
+ /**
+ * Converts a class full name to a select option key
+ *
+ * @param string $class
+ * @return string
+ */
+ public static function class_to_option($class) {
+ // Form field is PARAM_ALPHANUMEXT and we are sending fully qualified class names
+ // as option names, but replacing the backslash for a string that is really unlikely
+ // to ever be part of a class name.
+ return str_replace('\\', '2015102400ouuu', $class);
+ }
+
+ /**
+ * option_to_class
+ *
+ * @param string $option
+ * @return string
+ */
+ public static function option_to_class($option) {
+ // Really unlikely but yeah, I'm a bad booyyy.
+ return str_replace('2015102400ouuu', '\\', $option);
+ }
+}
--- /dev/null
+<?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/>.
+
+/**
+ * Model logs table class.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_analytics\output;
+
+defined('MOODLE_INTERNAL') || die;
+require_once($CFG->libdir . '/tablelib.php');
+
+/**
+ * Model logs table class.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class model_logs extends \table_sql {
+
+ /**
+ * @var \core_analytics\model
+ */
+ protected $model = null;
+
+ /**
+ * Sets up the table_log parameters.
+ *
+ * @param string $uniqueid unique id of form.
+ * @param \core_analytics\model $model
+ */
+ public function __construct($uniqueid, $model) {
+ global $PAGE;
+
+ parent::__construct($uniqueid);
+
+ $this->model = $model;
+
+ $this->set_attribute('class', 'modellog generaltable generalbox');
+ $this->set_attribute('aria-live', 'polite');
+
+ $this->define_columns(array('time', 'version', 'indicators', 'timesplitting', 'accuracy', 'info', 'usermodified'));
+ $this->define_headers(array(
+ get_string('time'),
+ get_string('version'),
+ get_string('indicators', 'tool_analytics'),
+ get_string('timesplittingmethod', 'analytics'),
+ get_string('accuracy', 'tool_analytics'),
+ get_string('info', 'tool_analytics'),
+ get_string('fullnameuser'),
+ ));
+ $this->pageable(true);
+ $this->collapsible(false);
+ $this->sortable(false);
+ $this->is_downloadable(false);
+
+ $this->define_baseurl($PAGE->url);
+ }
+
+ /**
+ * Generate the version column.
+ *
+ * @param \stdClass $log log data.
+ * @return string HTML for the version column
+ */
+ public function col_version($log) {
+ $recenttimestr = get_string('strftimerecent', 'core_langconfig');
+ return userdate($log->version, $recenttimestr);
+ }
+
+ /**
+ * Generate the time column.
+ *
+ * @param \stdClass $log log data.
+ * @return string HTML for the time column
+ */
+ public function col_time($log) {
+ $recenttimestr = get_string('strftimerecent', 'core_langconfig');
+ return userdate($log->timecreated, $recenttimestr);
+ }
+
+ /**
+ * Generate the indicators column.
+ *
+ * @param \stdClass $log log data.
+ * @return string HTML for the indicators column
+ */
+ public function col_indicators($log) {
+ $indicatorclasses = json_decode($log->indicators);
+ $indicators = array();
+ foreach ($indicatorclasses as $indicatorclass) {
+ $indicator = \core_analytics\manager::get_indicator($indicatorclass);
+ if ($indicator) {
+ $indicators[] = $indicator->get_name();
+ } else {
+ debugging('Can\'t load ' . $indicatorclass . ' indicator', DEBUG_DEVELOPER);
+ }
+ }
+ return '<ul><li>' . implode('</li><li>', $indicators) . '</li></ul>';
+ }
+
+ /**
+ * Generate the context column.
+ *
+ * @param \stdClass $log log data.
+ * @return string HTML for the context column
+ */
+ public function col_timesplitting($log) {
+ $timesplitting = \core_analytics\manager::get_time_splitting($log->timesplitting);
+ return $timesplitting->get_name();
+ }
+
+ /**
+ * Generate the accuracy column.
+ *
+ * @param \stdClass $log log data.
+ * @return string HTML for the accuracy column
+ */
+ public function col_accuracy($log) {
+ return strval(round($log->score * 100, 2)) . '%';
+ }
+
+ /**
+ * Generate the info column.
+ *
+ * @param \stdClass $log log data.
+ * @return string HTML for the score column
+ */
+ public function col_info($log) {
+ global $PAGE;
+
+ if (empty($log->info) && empty($log->dir)) {
+ return '';
+ }
+
+ $info = array();
+ if (!empty($log->info)) {
+ $info = json_decode($log->info);
+ }
+ if (!empty($log->dir)) {
+ $info[] = get_string('predictorresultsin', 'tool_analytics', $log->dir);
+ }
+ $PAGE->requires->js_call_amd('tool_analytics/log_info', 'loadInfo', array($log->id, $info));
+ return \html_writer::link('#', get_string('view'), array('data-model-log-id' => $log->id));
+ }
+
+ /**
+ * Generate the usermodified column.
+ *
+ * @param \stdClass $log log data.
+ * @return string HTML for the usermodified column
+ */
+ public function col_usermodified($log) {
+ $user = \core_user::get_user($log->usermodified);
+ return fullname($user);
+ }
+
+ /**
+ * Query the logs table. Store results in the object for use by build_table.
+ *
+ * @param int $pagesize size of page for paginated displayed table.
+ * @param bool $useinitialsbar do you want to use the initials bar.
+ */
+ public function query_db($pagesize, $useinitialsbar = true) {
+ $total = count($this->model->get_logs());
+ $this->pagesize($pagesize, $total);
+ $this->rawdata = $this->model->get_logs($this->get_page_start(), $this->get_page_size());
+
+ // Set initial bars.
+ if ($useinitialsbar) {
+ $this->initialbars($total > $pagesize);
+ }
+ }
+}
--- /dev/null
+<?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/>.
+
+/**
+ * Prediction models list page.
+ *
+ * @package tool_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_analytics\output;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Shows tool_analytics models list.
+ *
+ * @package tool_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class models_list implements \renderable, \templatable {
+
+ /**
+ * models
+ *
+ * @var \core_analytics\model[]
+ */
+ protected $models = array();
+
+ /**
+ * __construct
+ *
+ * @param \core_analytics\model[] $models
+ * @return void
+ */
+ public function __construct($models) {
+ $this->models = $models;
+ }
+
+ /**
+ * Exports the data.
+ *
+ * @param \renderer_base $output
+ * @return \stdClass
+ */
+ public function export_for_template(\renderer_base $output) {
+
+ $data = new \stdClass();
+
+ $data->models = array();
+ foreach ($this->models as $model) {
+ $modeldata = $model->export();
+
+ // Model predictions list.
+ if ($model->uses_insights()) {
+ $predictioncontexts = $model->get_predictions_contexts();
+ if ($predictioncontexts) {
+
+ foreach ($predictioncontexts as $contextid => $unused) {
+ // We prepare this to be used as single_select template options.
+ $context = \context::instance_by_id($contextid);
+ if (empty($context)) {
+ // The context may have been deleted.
+ unset($predictioncontexts[$contextid]);
+ continue;
+ }
+
+ // Special name for system level predictions as showing "System is not visually nice".
+ if ($contextid == SYSCONTEXTID) {
+ $contextname = get_string('allpredictions', 'tool_analytics');
+ } else {
+ $contextname = shorten_text($context->get_context_name(true, true), 90);
+ }
+ $predictioncontexts[$contextid] = $contextname;
+ }
+ \core_collator::asort($predictioncontexts);
+
+ if (!empty($predictioncontexts)) {
+ $url = new \moodle_url('/report/insights/insights.php', array('modelid' => $model->get_id()));
+ $singleselect = new \single_select($url, 'contextid', $predictioncontexts);
+ $modeldata->insights = $singleselect->export_for_template($output);
+ }
+ }
+
+ if (empty($modeldata->insights)) {
+ if ($model->any_prediction_obtained()) {
+ $modeldata->noinsights = get_string('noinsights', 'analytics');
+ } else {
+ $modeldata->noinsights = get_string('nopredictionsyet', 'analytics');
+ }
+ }
+
+ } else {
+ $modeldata->noinsights = get_string('noinsightsmodel', 'analytics');
+ }
+
+ // Actions.
+ $actionsmenu = new \action_menu();
+ $actionsmenu->set_menu_trigger(get_string('actions'));
+ $actionsmenu->set_owner_selector('model-actions-' . $model->get_id());
+ $actionsmenu->set_alignment(\action_menu::TL, \action_menu::BL);
+
+ // Edit model.
+ if (!$model->is_static()) {
+ $url = new \moodle_url('model.php', array('action' => 'edit', 'id' => $model->get_id()));
+ $icon = new \action_menu_link_secondary($url, new \pix_icon('t/edit', get_string('edit')), get_string('edit'));
+ $actionsmenu->add($icon);
+ }
+
+ // Evaluate machine-learning-based models.
+ if ($model->get_indicators() && !$model->is_static()) {
+ $url = new \moodle_url('model.php', array('action' => 'evaluate', 'id' => $model->get_id()));
+ $icon = new \action_menu_link_secondary($url, new \pix_icon('i/calc', get_string('evaluate', 'tool_analytics')),
+ get_string('evaluate', 'tool_analytics'));
+ $actionsmenu->add($icon);
+ }
+
+ if ($modeldata->enabled && !empty($modeldata->timesplitting)) {
+ $url = new \moodle_url('model.php', array('action' => 'getpredictions', 'id' => $model->get_id()));
+ $icon = new \action_menu_link_secondary($url, new \pix_icon('i/notifications',
+ get_string('getpredictions', 'tool_analytics')), get_string('getpredictions', 'tool_analytics'));
+ $actionsmenu->add($icon);
+ }
+
+ // Machine-learning-based models evaluation log.
+ if (!$model->is_static()) {
+ $url = new \moodle_url('model.php', array('action' => 'log', 'id' => $model->get_id()));
+ $icon = new \action_menu_link_secondary($url, new \pix_icon('i/report', get_string('viewlog', 'tool_analytics')),
+ get_string('viewlog', 'tool_analytics'));
+ $actionsmenu->add($icon);
+ }
+
+ $modeldata->actions = $actionsmenu->export_for_template($output);
+
+ $data->models[] = $modeldata;
+ }
+
+ $data->warnings = array(
+ (object)array('message' => get_string('bettercli', 'tool_analytics'), 'closebutton' => true)
+ );
+
+ return $data;
+ }
+}
--- /dev/null
+<?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/>.
+
+/**
+ * Renderer.
+ *
+ * @package tool_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_analytics\output;
+
+defined('MOODLE_INTERNAL') || die();
+
+use plugin_renderer_base;
+use templatable;
+use renderable;
+
+/**
+ * Renderer class.
+ *
+ * @package tool_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class renderer extends plugin_renderer_base {
+
+ /**
+ * Defer to template.
+ *
+ * @param \tool_analytics\output\models_list $modelslist
+ * @return string HTML
+ */
+ protected function render_models_list(\tool_analytics\output\models_list $modelslist) {
+ $data = $modelslist->export_for_template($this);
+ return parent::render_from_template('tool_analytics/models_list', $data);
+ }
+
+ /**
+ * Renders a table.
+ *
+ * @param \table_sql $table
+ * @return string HTML
+ */
+ public function render_table(\table_sql $table) {
+
+ ob_start();
+ $table->out(10, true);
+ $output = ob_get_contents();
+ ob_end_clean();
+
+ return $output;
+ }
+
+ /**
+ * Web interface evaluate results.
+ *
+ * @param \stdClass[] $results
+ * @param string[] $logs
+ * @return string HTML
+ */
+ public function render_evaluate_results($results, $logs = array()) {
+ global $OUTPUT;
+
+ $output = '';
+
+ foreach ($results as $timesplittingid => $result) {
+
+ if (!CLI_SCRIPT) {
+ $output .= $OUTPUT->box_start('generalbox m-b-3');
+ }
+
+ // Check that the array key is a string, not all results depend on time splitting methods (e.g. general errors).
+ if (!is_numeric($timesplittingid)) {
+ $timesplitting = \core_analytics\manager::get_time_splitting($timesplittingid);
+ $langstrdata = (object)array('name' => $timesplitting->get_name(), 'id' => $timesplittingid);
+
+ if (CLI_SCRIPT) {
+ $output .= $OUTPUT->heading(get_string('getpredictionsresultscli', 'tool_analytics', $langstrdata), 3);
+ } else {
+ $output .= $OUTPUT->heading(get_string('getpredictionsresults', 'tool_analytics', $langstrdata), 3);
+ }
+ }
+
+ if ($result->status == 0) {
+ $output .= $OUTPUT->notification(get_string('goodmodel', 'tool_analytics'),
+ \core\output\notification::NOTIFY_SUCCESS);
+ } else if ($result->status === \core_analytics\model::NO_DATASET) {
+ $output .= $OUTPUT->notification(get_string('nodatatoevaluate', 'tool_analytics'),
+ \core\output\notification::NOTIFY_WARNING);
+ }
+
+ if (isset($result->score)) {
+ // Score.
+ $output .= $OUTPUT->heading(get_string('accuracy', 'tool_analytics') . ': ' .
+ round(floatval($result->score), 4) * 100 . '%', 4);
+ }
+
+ if (!empty($result->info)) {
+ foreach ($result->info as $message) {
+ $output .= $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
+ }
+ }
+
+ if (!CLI_SCRIPT) {
+ $output .= $OUTPUT->box_end();
+ }
+ }
+
+ // Info logged during evaluation.
+ if (!empty($logs) && debugging()) {
+ $output .= $OUTPUT->heading(get_string('extrainfo', 'tool_analytics'), 3);
+ foreach ($logs as $log) {
+ $output .= $OUTPUT->notification($log, \core\output\notification::NOTIFY_WARNING);
+ }
+ }
+
+ if (!CLI_SCRIPT) {
+ $output .= $OUTPUT->single_button(new \moodle_url('/admin/tool/analytics/index.php'), get_string('continue'));
+ }
+
+ return $output;
+ }
+
+
+ /**
+ * Web interface training & prediction results.
+ *
+ * @param \stdClass|false $trainresults
+ * @param string[] $trainlogs
+ * @param \stdClass|false $predictresults
+ * @param string[] $predictlogs
+ * @return string HTML
+ */
+ public function render_get_predictions_results($trainresults = false, $trainlogs = array(), $predictresults = false, $predictlogs = array()) {
+ global $OUTPUT;
+
+ $output = '';
+
+ if ($trainresults || (!empty($trainlogs) && debugging())) {
+ $output .= $OUTPUT->heading(get_string('trainingresults', 'tool_analytics'), 3);
+ }
+
+ if ($trainresults) {
+ if ($trainresults->status == 0) {
+ $output .= $OUTPUT->notification(get_string('trainingprocessfinished', 'tool_analytics'),
+ \core\output\notification::NOTIFY_SUCCESS);
+ } else if ($trainresults->status === \core_analytics\model::NO_DATASET) {
+ $output .= $OUTPUT->notification(get_string('nodatatotrain', 'tool_analytics'),
+ \core\output\notification::NOTIFY_WARNING);
+ } else {
+ $output .= $OUTPUT->notification(get_string('generalerror', 'analytics', $trainresults->status),
+ \core\output\notification::NOTIFY_ERROR);
+ }
+ }
+
+ if (!empty($trainlogs) && debugging()) {
+ $output .= $OUTPUT->heading(get_string('extrainfo', 'tool_analytics'), 4);
+ foreach ($trainlogs as $log) {
+ $output .= $OUTPUT->notification($log, \core\output\notification::NOTIFY_WARNING);
+ }
+ }
+
+ if ($predictresults || (!empty($predictlogs) && debugging())) {
+ $output .= $OUTPUT->heading(get_string('predictionresults', 'tool_analytics'), 3, 'main m-t-3');
+ }
+
+ if ($predictresults) {
+ if ($predictresults->status == 0) {
+ $output .= $OUTPUT->notification(get_string('predictionprocessfinished', 'tool_analytics'),
+ \core\output\notification::NOTIFY_SUCCESS);
+ } else if ($predictresults->status === \core_analytics\model::NO_DATASET) {
+ $output .= $OUTPUT->notification(get_string('nodatatopredict', 'tool_analytics'),
+ \core\output\notification::NOTIFY_WARNING);
+ } else {
+ $output .= $OUTPUT->notification(get_string('generalerror', 'analytics', $predictresults->status),
+ \core\output\notification::NOTIFY_ERROR);
+ }
+ }
+
+ if (!empty($predictlogs) && debugging()) {
+ $output .= $OUTPUT->heading(get_string('extrainfo', 'tool_analytics'), 4);
+ foreach ($predictlogs as $log) {
+ $output .= $OUTPUT->notification($log, \core\output\notification::NOTIFY_WARNING);
+ }
+ }
+
+ if (!CLI_SCRIPT) {
+ $output .= $OUTPUT->single_button(new \moodle_url('/admin/tool/analytics/index.php'), get_string('continue'));
+ }
+
+ return $output;
+ }
+}
--- /dev/null
+<?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/>.
+
+/**
+ * Predict system models with new data available.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_analytics\task;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Predict system models with new data available.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class predict_models extends \core\task\scheduled_task {
+
+ /**
+ * get_name
+ *
+ * @return string
+ */
+ public function get_name() {
+ return get_string('predictmodels', 'tool_analytics');
+ }
+
+ /**
+ * Executes the prediction task.
+ *
+ * @return void
+ */
+ public function execute() {
+ global $OUTPUT, $PAGE;
+
+ $models = \core_analytics\manager::get_all_models(true, true);
+ if (!$models) {
+ mtrace(get_string('errornoenabledandtrainedmodels', 'tool_analytics'));
+ return;
+ }
+
+ foreach ($models as $model) {
+ $result = $model->predict();
+ if ($result) {
+ echo $OUTPUT->heading(get_string('modelresults', 'tool_analytics', $model->get_target()->get_name()));
+ $renderer = $PAGE->get_renderer('tool_analytics');
+ echo $renderer->render_get_predictions_results(false, array(), $result, $model->get_analyser()->get_logs());
+ }
+ }
+
+ }
+}
--- /dev/null
+<?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/>.
+
+/**
+ * Train system models with new data available.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_analytics\task;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Train system models with new data available.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class train_models extends \core\task\scheduled_task {
+
+ /**
+ * get_name
+ *
+ * @return string
+ */
+ public function get_name() {
+ return get_string('trainmodels', 'tool_analytics');
+ }
+
+ /**
+ * Executes the prediction task.
+ *
+ * @return void
+ */
+ public function execute() {
+ global $OUTPUT, $PAGE;
+
+ $models = \core_analytics\manager::get_all_models(true);
+ if (!$models) {
+ mtrace(get_string('errornoenabledmodels', 'tool_analytics'));
+ return;
+ }
+
+ foreach ($models as $model) {
+
+ if ($model->is_static()) {
+ // Skip models based on assumptions.
+ continue;
+ }
+
+ if (!$model->get_time_splitting()) {
+ // Can not train if there is no time splitting method selected.
+ continue;
+ }
+
+ $result = $model->train();
+ if ($result) {
+ echo $OUTPUT->heading(get_string('modelresults', 'tool_analytics', $model->get_target()->get_name()));
+
+ $renderer = $PAGE->get_renderer('tool_analytics');
+ echo $renderer->render_get_predictions_results($result, $model->get_analyser()->get_logs());
+ }
+ }
+ }
+}
--- /dev/null
+<?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/>.
+
+/**
+ * Enables the provided model.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('CLI_SCRIPT', true);
+
+require_once(__DIR__ . '/../../../../config.php');
+require_once($CFG->libdir.'/clilib.php');
+
+$help = "Enables the provided model.
+
+Options:
+--modelid Model id
+--timesplitting Time splitting method full class name
+-h, --help Print out this help
+
+Example:
+\$ php admin/tool/analytics/cli/enable_model.php --modelid=1 --timesplitting=\"\\core\\analytics\\time_splitting\\quarters\"
+";
+
+// Now get cli options.
+list($options, $unrecognized) = cli_get_params(
+ array(
+ 'help' => false,
+ 'modelid' => false,
+ 'timesplitting' => false
+ ),
+ array(
+ 'h' => 'help',
+ )
+);
+
+if ($options['help']) {
+ echo $help;
+ exit(0);
+}
+
+if ($options['modelid'] === false || $options['timesplitting'] === false) {
+ echo $help;
+ exit(0);
+}
+
+// We need admin permissions.
+\core\session\manager::set_user(get_admin());
+
+$model = new \core_analytics\model($options['modelid']);
+
+// Evaluate its suitability to predict accurately.
+$model->enable($options['timesplitting']);
+
+cli_heading(get_string('success'));
+exit(0);
--- /dev/null
+<?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/>.
+
+/**
+ * Evaluates the provided model.
+ *
+ * @package tool_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('CLI_SCRIPT', true);
+
+require_once(__DIR__ . '/../../../../config.php');
+require_once($CFG->libdir.'/clilib.php');
+
+$help = "Evaluates the provided model.
+
+Options:
+--modelid Model id
+--non-interactive Not interactive questions
+--timesplitting Restrict the evaluation to 1 single time splitting method (Optional)
+--filter Analyser dependant. e.g. A courseid would evaluate the model using a single course (Optional)
+--reuse-prev-analysed Reuse recently analysed courses instead of analysing the whole site. Set it to false while" .
+ " coding indicators. Defaults to true (Optional)" . "
+-h, --help Print out this help
+
+Example:
+\$ php admin/tool/analytics/cli/evaluate_model.php --modelid=1 --timesplitting='\\core\\analytics\\time_splitting\\quarters' --filter=123,321
+";
+
+// Now get cli options.
+list($options, $unrecognized) = cli_get_params(
+ array(
+ 'help' => false,
+ 'modelid' => false,
+ 'timesplitting' => false,
+ 'reuse-prev-analysed' => true,
+ 'non-interactive' => false,
+ 'filter' => false
+ ),
+ array(
+ 'h' => 'help',
+ )
+);
+
+if ($options['help']) {
+ echo $help;
+ exit(0);
+}
+
+if ($options['modelid'] === false) {
+ echo $help;
+ exit(0);
+}
+
+// Reformat them as an array.
+if ($options['filter'] !== false) {
+ $options['filter'] = explode(',', $options['filter']);
+}
+
+// We need admin permissions.
+\core\session\manager::set_user(get_admin());
+
+$model = new \core_analytics\model($options['modelid']);
+
+mtrace(get_string('analysingsitedata', 'tool_analytics'));
+
+if ($options['reuse-prev-analysed']) {
+ mtrace(get_string('evaluationinbatches', 'tool_analytics'));
+}
+
+$analyseroptions = array(
+ 'filter' => $options['filter'],
+ 'timesplitting' => $options['timesplitting'],
+ 'reuseprevanalysed' => $options['reuse-prev-analysed'],
+);
+// Evaluate its suitability to predict accurately.
+$results = $model->evaluate($analyseroptions);
+
+$renderer = $PAGE->get_renderer('tool_analytics');
+echo $renderer->render_evaluate_results($results, $model->get_analyser()->get_logs());
+
+// Check that we have, at leasa,t 1 valid dataset (not necessarily good) to use.
+foreach ($results as $result) {
+ if ($result->status !== \core_analytics\model::NO_DATASET &&
+ $result->status !== \core_analytics\model::GENERAL_ERROR) {
+ $validdatasets = true;
+ }
+}
+
+if (!empty($validdatasets) && !$model->is_enabled() && $options['non-interactive'] === false) {
+
+ // Select a dataset, train and enable the model.
+ $input = cli_input(get_string('clienablemodel', 'tool_analytics'));
+ while (!\core_analytics\manager::is_valid($input, '\core_analytics\local\time_splitting\base') && $input !== 'none') {
+ mtrace(get_string('errorunexistingtimesplitting', 'analytics'));
+ $input = cli_input(get_string('clienablemodel', 'tool_analytics'));
+ }
+
+ if ($input === 'none') {
+ exit(0);
+ }
+
+ // Refresh the instance to prevent unexpected issues.
+ $model = new \core_analytics\model($modelobj);
+
+ // Set the time splitting method file and enable it.
+ $model->enable($input);
+
+ mtrace(get_string('trainandpredictmodel', 'tool_analytics'));
+
+ // Train the model with the selected time splitting method and start predicting.
+ $model->train();
+ $model->predict();
+}
+
+exit(0);
--- /dev/null
+<?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/>.
+
+/**
+ * Guesses course start and end dates based on activity logs.
+ *
+ * @package tool_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('CLI_SCRIPT', true);
+
+require_once(__DIR__ . '/../../../../config.php');
+require_once($CFG->libdir.'/clilib.php');
+
+require_once($CFG->dirroot . '/course/lib.php');
+require_once($CFG->dirroot . '/course/format/weeks/lib.php');
+
+$help = "Guesses course start and end dates based on activity logs.
+
+Options:
+--guessstart Guess the course start date (default to true)
+--guessend Guess the course end date (default to true)
+--guessall Guess all start and end dates, even if they are already set (default to false)
+--update Update the db or just notify the guess (default to false)
+--filter Analyser dependant. e.g. A courseid would evaluate the model using a single course (Optional)
+-h, --help Print out this help
+
+Example:
+\$ php admin/tool/analytics/cli/guess_course_start_and_end_dates.php --update=1 --filter=123,321
+";
+
+// Now get cli options.
+list($options, $unrecognized) = cli_get_params(
+ array(
+ 'help' => false,
+ 'guessstart' => true,
+ 'guessend' => true,
+ 'guessall' => false,
+ 'update' => false,
+ 'filter' => false
+ ),
+ array(
+ 'h' => 'help',
+ )
+);
+
+if ($options['help']) {
+ echo $help;
+ exit(0);
+}
+
+if ($options['guessstart'] === false && $options['guessend'] === false && $options['guessall'] === false) {
+ echo $help;
+ exit(0);
+}
+
+// Reformat them as an array.
+if ($options['filter'] !== false) {
+ $options['filter'] = explode(',', clean_param($options['filter'], PARAM_SEQUENCE));
+}
+
+// We need admin permissions.
+\core\session\manager::set_user(get_admin());
+
+$conditions = array('id != 1');
+if (!$options['guessall']) {
+ if ($options['guessstart']) {
+ $conditions[] = '(startdate is null or startdate = 0)';
+ }
+ if ($options['guessend']) {
+ $conditions[] = '(enddate is null or enddate = 0)';
+ }
+}
+
+$coursessql = '';
+$params = null;
+if ($options['filter']) {
+ list($coursessql, $params) = $DB->get_in_or_equal($options['filter'], SQL_PARAMS_NAMED);
+ $conditions[] = 'id ' . $coursessql;
+}
+
+$courses = $DB->get_recordset_select('course', implode(' AND ', $conditions), $params, 'sortorder ASC');
+foreach ($courses as $course) {
+ tool_analytics_calculate_course_dates($course, $options);
+}
+$courses->close();
+
+
+/**
+ * tool_analytics_calculate_course_dates
+ *
+ * @param stdClass $course
+ * @param array $options CLI options
+ * @return void
+ */
+function tool_analytics_calculate_course_dates($course, $options) {
+ global $DB, $OUTPUT;
+
+ $courseman = new \core_analytics\course($course);
+
+ $notification = $course->shortname . ' (id = ' . $course->id . '): ';
+
+ if ($options['guessstart'] || $options['guessall']) {
+
+ $originalstartdate = $course->startdate;
+
+ $guessedstartdate = $courseman->guess_start();
+ if ($guessedstartdate == $originalstartdate) {
+ if (!$guessedstartdate) {
+ $notification .= PHP_EOL . ' ' . get_string('cantguessstartdate', 'tool_analytics');
+ } else {
+ // No need to update.
+ $notification .= PHP_EOL . ' ' . get_string('samestartdate', 'tool_analytics') . ': ' . userdate($guessedstartdate);
+ }
+ } else if (!$guessedstartdate) {
+ $notification .= PHP_EOL . ' ' . get_string('cantguessstartdate', 'tool_analytics');
+ } else {
+ // Update it to something we guess.
+
+ // We set it to $course even if we don't update because may be needed to guess the end one.
+ $course->startdate = $guessedstartdate;
+ $notification .= PHP_EOL . ' ' . get_string('startdate') . ': ' . userdate($guessedstartdate);
+
+ // Two different course updates because week's end date may be recalculated after setting the start date.
+ if ($options['update']) {
+ update_course($course);
+
+ // Refresh course data as end date may have been updated.
+ $course = $DB->get_record('course', array('id' => $course->id));
+ $courseman = new \core_analytics\course($course);
+ }
+ }
+ }
+
+ if ($options['guessend'] || $options['guessall']) {
+
+ $originalenddate = $course->enddate;
+
+ $format = course_get_format($course);
+ $formatoptions = $format->get_format_options();
+
+ if ($course->format === 'weeks' && $formatoptions['automaticenddate']) {
+ // Special treatment for weeks with automatic end date.
+
+ if ($options['update']) {
+ format_weeks::update_end_date($course->id);
+ $course->enddate = $DB->get_field('course', 'enddate', array('id' => $course->id));
+ $notification .= PHP_EOL . ' ' . get_string('weeksenddateautomaticallyset', 'tool_analytics') . ': ' .
+ userdate($course->enddate);
+ } else {
+ // We can't provide more info without actually updating it in db.
+ $notification .= PHP_EOL . ' ' . get_string('weeksenddatedefault', 'tool_analytics');
+ }
+ } else {
+ $guessedenddate = $courseman->guess_end();
+
+ if ($guessedenddate == $originalenddate) {
+ if (!$guessedenddate) {
+ $notification .= PHP_EOL . ' ' . get_string('cantguessenddate', 'tool_analytics');
+ } else {
+ // No need to update.
+ $notification .= PHP_EOL . ' ' . get_string('sameenddate', 'tool_analytics') . ': ' . userdate($guessedenddate);
+ }
+ } else if (!$guessedenddate) {
+ $notification .= PHP_EOL . ' ' . get_string('cantguessenddate', 'tool_analytics');
+ } else {
+ // Update it to something we guess.
+
+ $course->enddate = $guessedenddate;
+
+ if ($course->enddate > $course->startdate) {
+ $notification .= PHP_EOL . ' ' . get_string('enddate') . ': ' . userdate($course->enddate);
+ } else {
+ $notification .= PHP_EOL . ' ' . get_string('errorendbeforestart', 'analytics', userdate($course->enddate));
+ }
+
+ if ($options['update']) {
+ if ($course->enddate > $course->startdate) {
+ update_course($course);
+ }
+ }
+ }
+ }
+
+ }
+
+ mtrace($notification);
+}
+
+mtrace(get_string('success'));
+
+exit(0);
--- /dev/null
+<?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/>.
+
+/**
+ * This file defines tasks performed by the tool.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// List of tasks.
+$tasks = array(
+ array(
+ 'classname' => 'tool_analytics\task\train_models',
+ 'blocking' => 0,
+ 'minute' => '0',
+ 'hour' => 'R',
+ 'day' => '*',
+ 'dayofweek' => '*',
+ 'month' => '*'
+ ),
+ array(
+ 'classname' => 'tool_analytics\task\predict_models',
+ 'blocking' => 0,
+ 'minute' => '0',
+ 'hour' => 'R',
+ 'day' => '*',
+ 'dayofweek' => '*',
+ 'month' => '*'
+ ),
+);
--- /dev/null
+<?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/>.
+
+/**
+ * Prediction models tool frontend.
+ *
+ * @package tool_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(__DIR__ . '/../../../config.php');
+require_once($CFG->libdir . '/adminlib.php');
+
+admin_externalpage_setup('analyticmodels', '', null, '', array('pagelayout' => 'report'));
+
+$models = \core_analytics\manager::get_all_models();
+
+echo $OUTPUT->header();
+
+$templatable = new \tool_analytics\output\models_list($models);
+echo $PAGE->get_renderer('tool_analytics')->render($templatable);
+
+echo $OUTPUT->footer();
--- /dev/null
+<?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/>.
+
+/**
+ * Strings for tool_analytics.
+ *
+ * @package tool_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['accuracy'] = 'Accuracy';
+$string['allpredictions'] = 'All predictions';
+$string['analysingsitedata'] = 'Analysing the site';
+$string['analyticmodels'] = 'Analytic models';
+$string['bettercli'] = 'Evaluating models and generating predictions may involve heavy processing. It is advised that you run these actions via the command line interface';
+$string['cantguessstartdate'] = 'Can\'t guess the start date';
+$string['cantguessenddate'] = 'Can\'t guess the end date';
+$string['clienablemodel'] = 'You can enable the model by selecting a time splitting method by its id. Note that you can also enable it later using the web interface (\'none\' to exit)';
+$string['editmodel'] = 'Edit "{$a}" model';
+$string['edittrainedwarning'] = 'This model has already been trained, note that changing its indicators or its time splitting method will delete its previous predictions and start generating the new ones';
+$string['enabled'] = 'Enabled';
+$string['errorcantenablenotimesplitting'] = 'You need to select a time splitting method before enabling the model';
+$string['errornoenabledandtrainedmodels'] = 'There are not enabled and trained models to predict';
+$string['errornoenabledmodels'] = 'There are not enabled models to train';
+$string['errornostaticedit'] = 'Models based on assumptions can not be edited';
+$string['errornostaticevaluated'] = 'Models based on assumptions can not be evaluated, they are always 100% correct according to how they were defined';
+$string['errornostaticlog'] = 'Models based on assumptions can not be evaluated, there is no preformance log';
+$string['evaluate'] = 'Evaluate';
+$string['evaluatemodel'] = 'Evaluate model';
+$string['evaluationinbatches'] = 'The site contents are calculated and stored in batches, during evaluation you can stop the process at any moment, the next time you run it it will continue from the point you stopped it.';
+$string['trainandpredictmodel'] = 'Training model and calculating predictions';
+$string['getpredictionsresultscli'] = 'Results using {$a->name} (id: {$a->id}) course duration splitting';
+$string['getpredictionsresults'] = 'Results using {$a->name} course duration splitting';
+$string['extrainfo'] = 'Info';
+$string['generalerror'] = 'Evaluation error. Status code {$a}';
+$string['getpredictions'] = 'Get predictions';
+$string['goodmodel'] = 'This is a good model and it can be used to predict, enable it to start getting predictions.';
+$string['indicators'] = 'Indicators';
+$string['info'] = 'Info';
+$string['insights'] = 'Insights';
+$string['loginfo'] = 'Log extra info';
+$string['modelresults'] = '{$a} results';
+$string['modelslist'] = 'Models list';
+$string['modeltimesplitting'] = 'Time splitting';
+$string['nodatatoevaluate'] = 'There is no data to evaluate the model';
+$string['nodatatopredict'] = 'No new elements to get predictions for';
+$string['nodatatotrain'] = 'There is no new data that can be used for training';
+$string['notdefined'] = 'Not yet defined';
+$string['pluginname'] = 'Analytic models';
+$string['predictionresults'] = 'Prediction results';
+$string['predictmodels'] = 'Predict models';
+$string['predictorresultsin'] = 'Predictor logged information in {$a} directory';
+$string['predictionprocessfinished'] = 'Prediction process finished';
+$string['samestartdate'] = 'Current start date is good';
+$string['sameenddate'] = 'Current end date is good';
+$string['target'] = 'Target';
+$string['trainingprocessfinished'] = 'Training process finished';
+$string['trainingresults'] = 'Training results';
+$string['trainmodels'] = 'Train models';
+$string['viewlog'] = 'Log';
+$string['weeksenddateautomaticallyset'] = 'End date automatically set based on start date and the number of sections';
+$string['weeksenddatedefault'] = 'End date would be automatically calculated from the course start date';
--- /dev/null
+<?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/>.
+
+/**
+ * Model-related actions.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(__DIR__ . '/../../../config.php');
+
+$id = required_param('id', PARAM_INT);
+$action = required_param('action', PARAM_ALPHANUMEXT);
+
+$context = context_system::instance();
+
+require_login();
+
+$model = new \core_analytics\model($id);
+\core_analytics\manager::check_can_manage_models();
+
+$params = array('id' => $id, 'action' => $action);
+$url = new \moodle_url('/admin/tool/analytics/model.php', $params);
+
+switch ($action) {
+
+ case 'edit':
+ $title = get_string('editmodel', 'tool_analytics', $model->get_target()->get_name());
+ break;
+ case 'evaluate':
+ $title = get_string('evaluatemodel', 'tool_analytics');
+ break;
+ case 'getpredictions':
+ $title = get_string('getpredictions', 'tool_analytics');
+ break;
+ case 'log':
+ $title = get_string('viewlog', 'tool_analytics');
+ break;
+ default:
+ throw new moodle_exception('errorunknownaction', 'analytics');
+}
+
+$PAGE->set_context($context);
+$PAGE->set_url($url);
+$PAGE->set_pagelayout('report');
+$PAGE->set_title($title);
+$PAGE->set_heading($title);
+
+switch ($action) {
+
+ case 'edit':
+
+ if ($model->is_static()) {
+ echo $OUTPUT->header();
+ throw new moodle_exception('errornostaticedit', 'tool_analytics');
+ }
+
+ $customdata = array(
+ 'id' => $model->get_id(),
+ 'model' => $model,
+ 'indicators' => $model->get_potential_indicators(),
+ 'timesplittings' => \core_analytics\manager::get_enabled_time_splitting_methods()
+ );
+ $mform = new \tool_analytics\output\form\edit_model(null, $customdata);
+
+ if ($mform->is_cancelled()) {
+ redirect(new \moodle_url('/admin/tool/analytics/index.php'));
+
+ } else if ($data = $mform->get_data()) {
+ confirm_sesskey();
+
+ // Converting option names to class names.
+ $indicators = array();
+ foreach ($data->indicators as $indicator) {
+ $indicatorclass = \tool_analytics\output\helper::option_to_class($indicator);
+ $indicators[] = \core_analytics\manager::get_indicator($indicatorclass);
+ }
+ $timesplitting = \tool_analytics\output\helper::option_to_class($data->timesplitting);
+ $model->update($data->enabled, $indicators, $timesplitting);
+ redirect(new \moodle_url('/admin/tool/analytics/index.php'));
+ }
+
+ echo $OUTPUT->header();
+
+ $modelobj = $model->get_model_obj();
+
+ $callable = array('\tool_analytics\output\helper', 'class_to_option');
+ $modelobj->indicators = array_map($callable, json_decode($modelobj->indicators));
+ $modelobj->timesplitting = \tool_analytics\output\helper::class_to_option($modelobj->timesplitting);
+ $mform->set_data($modelobj);
+ $mform->display();
+ break;
+
+ case 'evaluate':
+ echo $OUTPUT->header();
+
+ if ($model->is_static()) {
+ throw new moodle_exception('errornostaticevaluate', 'tool_analytics');
+ }
+
+ // Web interface is used by people who can not use CLI nor code stuff, always use
+ // cached stuff as they will change the model through the web interface as well
+ // which invalidates the previously analysed stuff.
+ $results = $model->evaluate(array('reuseprevanalysed' => true));
+ $renderer = $PAGE->get_renderer('tool_analytics');
+ echo $renderer->render_evaluate_results($results, $model->get_analyser()->get_logs());
+ break;
+
+ case 'getpredictions':
+ echo $OUTPUT->header();
+
+ $trainresults = $model->train();
+ $trainlogs = $model->get_analyser()->get_logs();
+
+ // Looks dumb to get a new instance but better be conservative.
+ $model = new \core_analytics\model($model->get_model_obj());
+ $predictresults = $model->predict();
+ $predictlogs = $model->get_analyser()->get_logs();
+
+ $renderer = $PAGE->get_renderer('tool_analytics');
+ echo $renderer->render_get_predictions_results($trainresults, $trainlogs, $predictresults, $predictlogs);
+ break;
+
+ case 'log':
+ echo $OUTPUT->header();
+
+ if ($model->is_static()) {
+ throw new moodle_exception('errornostaticlog', 'tool_analytics');
+ }
+
+ $renderer = $PAGE->get_renderer('tool_analytics');
+ $modellogstable = new \tool_analytics\output\model_logs('model-' . $model->get_id(), $model);
+ echo $renderer->render_table($modellogstable);
+ break;
+}
+
+echo $OUTPUT->footer();
--- /dev/null
+<?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/>.
+
+/**
+ * Adds settings links to admin tree.
+ *
+ * @package tool_analytics
+ * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$ADMIN->add('reports', new admin_externalpage('analyticmodels', get_string('analyticmodels', 'tool_analytics'),
+ "$CFG->wwwroot/$CFG->admin/tool/analytics/index.php", 'moodle/analytics:managemodels'));
--- /dev/null
+{{!
+ 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/>.
+}}
+{{!
+ @template tool_analytics/models_list
+
+ Template for models list.
+
+ Classes required for JS:
+ * none
+
+ Data attributes required for JS:
+ * none
+
+ Context variables required for this template:
+ * none
+
+ Example context (json):
+ {
+ "models": [
+ {
+ "target": "Prevent devs at risk",
+ "enabled": 1,
+ "indicators": [
+ "Indicator 1",
+ "Indicator 2",
+ "Indicator 3",
+ "Indicator 4"
+ ],
+ "timesplitting": "Quarters",
+ "noinsights": "No insights available yet"
+ }
+ ],
+ "warnings": {
+ "message": "Hey, this is a warning"
+ }
+ }
+}}
+
+{{#warnings}}
+ {{> core/notification_warning}}
+{{/warnings}}
+<div class="box">
+ <table class="generaltable fullwidth">
+ <caption>{{#str}}modelslist, tool_analytics{{/str}}</caption>
+ <thead>
+ <tr>
+ <th scope="col">{{#str}}target, tool_analytics{{/str}}</th>
+ <th scope="col">{{#str}}enabled, tool_analytics{{/str}}</th>
+ <th scope="col">{{#str}}indicators, tool_analytics{{/str}}</th>
+ <th scope="col">{{#str}}modeltimesplitting, tool_analytics{{/str}}</th>
+ <th scope="col">{{#str}}insights, tool_analytics{{/str}}</th>
+ <th scope="col">{{#str}}actions{{/str}}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{#models}}
+ <tr>
+ <td>{{target}}</td>
+ <td>
+ {{#enabled}}
+ {{#pix}}i/checked, core, {{#str}}yes{{/str}}{{/pix}}
+ {{/enabled}}
+ {{^enabled}}
+ {{#str}}no{{/str}}
+ {{/enabled}}
+ </td>
+ <td>
+ <ul>
+ {{#indicators}}
+ <li>{{.}}</li>
+ {{/indicators}}
+ </ul>
+ </td>
+ <td>
+ {{#timesplitting}}{{timesplitting}}{{/timesplitting}}{{^timesplitting}}{{#str}}notdefined, tool_analytics{{/str}}{{/timesplitting}}
+ </td>
+ <td>
+ {{! models_list renderer is responsible of sending one or the other}}
+ {{#insights}}
+ {{> core/single_select }}
+ {{/insights}}
+ {{#noinsights}}
+ {{.}}
+ {{/noinsights}}
+ </td>
+ <td>
+ {{#actions}}
+ {{> core/action_menu}}
+ {{/actions}}
+ </td>
+ </tr>
+ {{/models}}
+ </tbody>
+ </table>
+</div>
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * Version details
+ * Version details.
*
- * @package auth_fc
- * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2017051500; // The current plugin version (Date: YYYYMMDDXX)
-$plugin->requires = 2017050500; // Requires this Moodle version
-$plugin->component = 'auth_fc'; // Full name of the plugin (used for diagnostics)
+$plugin->version = 2017051500; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->requires = 2017050500; // Requires this Moodle version.
+$plugin->component = 'tool_analytics'; // Full name of the plugin (used for diagnostics).
function xmldb_tool_customlang_upgrade($oldversion) {
global $CFG;
- // Moodle v2.8.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v2.9.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v3.0.0 release upgrade line.
- // Put any upgrade step following this.
-
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
$string['deletea'] = 'Delete {$a}';
$string['deletefiletypes'] = 'Delete a file type';
$string['description'] = 'Custom description';
-$string['description_help'] = 'Simple file type description, e.g. ‘Kindle ebook’. If your site supports multiple languages and uses the multi-language filter, you can enter multi-language tags in this field to supply a description in different languages.';
+$string['description_help'] = 'Simple file type description, e.g. \'Kindle ebook\'. If your site supports multiple languages and uses the multi-language filter, you can enter multi-language tags in this field to supply a description in different languages.';
$string['descriptiontype'] = 'Description type';
$string['descriptiontype_help'] = 'There are three possible ways to specify a description.
$string['error_extension'] = 'The file type extension <strong>{$a}</strong> already exists or is invalid. File extensions must be unique and must not contain special characters.';
$string['error_notfound'] = 'The file type with extension {$a} cannot be found.';
$string['extension'] = 'Extension';
-$string['extension_help'] = 'File name extension without the dot, e.g. ‘mobi’';
+$string['extension_help'] = 'File name extension without the dot, e.g. \'mobi\'';
$string['groups'] = 'Type groups';
-$string['groups_help'] = 'Optional list of file type groups that this type belongs to. These are generic categories such as ‘document’ and ‘image’.';
+$string['groups_help'] = 'Optional list of file type groups that this type belongs to. These are generic categories such as \'document\' and \'image\'.';
$string['icon'] = 'File icon';
$string['icon_help'] = 'Icon filename.
The list of icons is taken from the /pix/f directory inside your Moodle installation. You can add custom icons to this folder if required.';
$string['mimetype'] = 'MIME type';
-$string['mimetype_help'] = 'MIME type associated with this file type, e.g. ‘application/x-mobipocket-ebook’';
+$string['mimetype_help'] = 'MIME type associated with this file type, e.g. \'application/x-mobipocket-ebook\'';
$string['pluginname'] = 'File types';
$string['revert'] = 'Restore {$a} to Moodle defaults';
$string['revert_confirmation'] = 'Are you sure you want to restore <strong>.{$a}</strong> to Moodle defaults, discarding your changes?';
function xmldb_tool_log_upgrade($oldversion) {
global $CFG;
- // Moodle v2.8.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v2.9.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v3.0.0 release upgrade line.
- // Put any upgrade step following this.
-
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
$dboptions['dbport'] = $this->get_config('dbport', '');
$dboptions['dbschema'] = $this->get_config('dbschema', '');
$dboptions['dbcollation'] = $this->get_config('dbcollation', '');
+ $dboptions['dbhandlesoptions'] = $this->get_config('dbhandlesoptions', false);
try {
$db->connect($this->get_config('dbhost'), $this->get_config('dbuser'), $this->get_config('dbpass'),
$this->get_config('dbname'), false, $dboptions);
function xmldb_logstore_database_upgrade($oldversion) {
global $CFG;
- // Moodle v2.8.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v2.9.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v3.0.0 release upgrade line.
- // Put any upgrade step following this.
-
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
$string['databasepersist'] = 'Persistent database connections';
$string['databaseschema'] = 'Database schema';
$string['databasecollation'] = 'Database collation';
+$string['databasehandlesoptions'] = 'Database handles options';
+$string['databasehandlesoptions_help'] = 'Does the remote database handle its own options.';
$string['databasetable'] = 'Database table';
$string['databasetable_help'] = 'Name of the table where logs will be stored. This table should have a structure identical to the one used by logstore_standard (mdl_logstore_standard_log).';
$string['includeactions'] = 'Include actions of these types';
'logstore_database'), '', ''));
$settings->add(new admin_setting_configtext('logstore_database/dbcollation', get_string('databasecollation',
'logstore_database'), '', ''));
+ $settings->add(new admin_setting_configcheckbox('logstore_database/dbhandlesoptions', get_string('databasehandlesoptions',
+ 'logstore_database'), get_string('databasehandlesoptions_help', 'logstore_database'), '0'));
$settings->add(new admin_setting_configtext('logstore_database/buffersize', get_string('buffersize',
'logstore_database'), get_string('buffersize_help', 'logstore_database'), 50));
$dboptions['dbport'] = get_config('logstore_database', 'dbport');
$dboptions['dbschema'] = get_config('logstore_database', 'dbschema');
$dboptions['dbcollation'] = get_config('logstore_database', 'dbcollation');
+$dboptions['dbhandlesoptions'] = get_config('logstore_database', 'dbhandlesoptions');
try {
$db->connect(get_config('logstore_database', 'dbhost'), get_config('logstore_database', 'dbuser'),
} else {
set_config('dbcollation', '', 'logstore_database');
}
+ if (!empty($CFG->dboptions['dbhandlesoptions'])) {
+ set_config('dbhandlesoptions', $CFG->dboptions['dbhandlesoptions'], 'logstore_database');
+ } else {
+ set_config('dbhandlesoptions', false, 'logstore_database');
+ }
// Enable logging plugin.
set_config('enabled_stores', 'logstore_database', 'tool_log');
--- /dev/null
+This files describes API changes in the logstore_database code.
+
+=== 3.4 ===
+* PostgreSQL connections now use advanced options to reduce connection overhead. These options are not compatible
+ with some connection poolers. The dbhandlesoptions parameter has been added to allow the database to configure the
+ required defaults. The parameters that are required in the database are;
+ ALTER DATABASE moodle SET client_encoding = UTF8;
+ ALTER DATABASE moodle SET standard_conforming_strings = on;
+ ALTER DATABASE moodle SET search_path = 'moodle,public'; -- Optional, if you wish to use a custom schema.
+ You can set these options against the database or the moodle user who connects.
+
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2017051500; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version = 2017062600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2017050500; // Requires this Moodle version.
$plugin->component = 'logstore_database'; // Full name of the plugin (used for diagnostics).
defined('MOODLE_INTERNAL') || die();
function xmldb_logstore_standard_upgrade($oldversion) {
- global $CFG, $DB;
-
- $dbman = $DB->get_manager();
-
- // Moodle v2.8.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v2.9.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v3.0.0 release upgrade line.
- // Put any upgrade step following this.
-
- if ($oldversion < 2016041200) {
- // This could take a long time. Unfortunately, no way to know how long, and no way to do progress, so setting for 1 hour.
- upgrade_set_timeout(3600);
-
- // Define key contextid (foreign) to be added to logstore_standard_log.
- $table = new xmldb_table('logstore_standard_log');
- $key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
-
- // Launch add key contextid.
- $dbman->add_key($table, $key);
-
- // Standard savepoint reached.
- upgrade_plugin_savepoint(true, 2016041200, 'logstore', 'standard');
- }
+ global $CFG;
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
));
}
- /**
- * Returns the description of external function parameters.
- *
- * @return external_function_parameters
- */
- public static function search_cohorts_parameters() {
- $query = new external_value(
- PARAM_RAW,
- 'Query string'
- );
- $includes = new external_value(
- PARAM_ALPHA,
- 'What other contexts to fetch the frameworks from. (all, parents, self)',
- VALUE_DEFAULT,
- 'parents'
- );
- $limitfrom = new external_value(
- PARAM_INT,
- 'limitfrom we are fetching the records from',
- VALUE_DEFAULT,
- 0
- );
- $limitnum = new external_value(
- PARAM_INT,
- 'Number of records to fetch',
- VALUE_DEFAULT,
- 25
- );
- return new external_function_parameters(array(
- 'query' => $query,
- 'context' => self::get_context_parameters(),
- 'includes' => $includes,
- 'limitfrom' => $limitfrom,
- 'limitnum' => $limitnum
- ));
- }
-
- /**
- * Search cohorts.
- * TODO: MDL-52243 Move this function to cohorts/externallib.php
- *
- * @param string $query
- * @param array $context
- * @param string $includes
- * @param int $limitfrom
- * @param int $limitnum
- * @return array
- */
- public static function search_cohorts($query, $context, $includes = 'parents', $limitfrom = 0, $limitnum = 25) {
- global $DB, $CFG, $PAGE;
- require_once($CFG->dirroot . '/cohort/lib.php');
-
- $params = self::validate_parameters(self::search_cohorts_parameters(), array(
- 'query' => $query,
- 'context' => $context,
- 'includes' => $includes,
- 'limitfrom' => $limitfrom,
- 'limitnum' => $limitnum,
- ));
- $query = $params['query'];
- $includes = $params['includes'];
- $context = self::get_context_from_params($params['context']);
- $limitfrom = $params['limitfrom'];
- $limitnum = $params['limitnum'];
-
- self::validate_context($context);
- $output = $PAGE->get_renderer('tool_lp');
-
- $manager = has_capability('moodle/cohort:manage', $context);
- if (!$manager) {
- require_capability('moodle/cohort:view', $context);
- }
-
- // TODO Make this more efficient.
- if ($includes == 'self') {
- $results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
- $results = $results['cohorts'];
- } else if ($includes == 'parents') {
- $results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
- $results = $results['cohorts'];
- if (!$context instanceof context_system) {
- $results = array_merge($results, cohort_get_available_cohorts($context, COHORT_ALL, $limitfrom, $limitnum, $query));
- }
- } else if ($includes == 'all') {
- $results = cohort_get_all_cohorts($limitfrom, $limitnum, $query);
- $results = $results['cohorts'];
- } else {
- throw new coding_exception('Invalid parameter value for \'includes\'.');
- }
-
- $cohorts = array();
- foreach ($results as $key => $cohort) {
- $cohortcontext = context::instance_by_id($cohort->contextid);
- $exporter = new cohort_summary_exporter($cohort, array('context' => $cohortcontext));
- $newcohort = $exporter->export($output);
-
- $cohorts[$key] = $newcohort;
- }
-
- return array('cohorts' => $cohorts);
- }
-
- /**
- * Returns description of external function result value.
- *
- * @return external_description
- */
- public static function search_cohorts_returns() {
- return new external_single_structure(array(
- 'cohorts' => new external_multiple_structure(cohort_summary_exporter::get_read_structure())
- ));
- }
-
/**
* Returns description of external function.
*
'capabilities' => '',
'ajax' => true,
),
+ // This function was originally in this plugin but has been moved to core.
'tool_lp_search_cohorts' => array(
- 'classname' => 'tool_lp\external',
+ 'classname' => 'core_cohort_external',
'methodname' => 'search_cohorts',
- 'classpath' => '',
+ 'classpath' => 'cohort/externallib.php',
'description' => 'Search for cohorts.',
'type' => 'read',
'capabilities' => 'moodle/cohort:view',
$this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']);
}
- /**
- * Select item from autocomplete list.
- *
- * @Given /^I click on "([^"]*)" item in the autocomplete list$/
- *
- * @param string $item
- */
- public function i_click_on_item_in_the_autocomplete_list($item) {
- $xpathtarget = "//ul[@class='form-autocomplete-suggestions']//li//span//span[contains(.,'" . $item . "')]";
-
- $this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']);
- }
}
And I follow "Home"
And I navigate to "Competencies > Learning plan templates" in site administration
And I click on ".template-userplans" "css_element" in the "Science template" "table_row"
- And I click on ".form-autocomplete-downarrow" "css_element"
+ And I open the autocomplete suggestions list
And I click on "Admin" item in the autocomplete list
+ And I press key "27" in the field "Select users to create learning plans for"
When I click on "Create learning plans" "button"
Then I should see "A learning plan was created"
And I should see "Admin User" in the "Science template" "table_row"
And I click on ".template-cohorts" "css_element" in the "Science template cohort" "table_row"
And I click on ".form-autocomplete-downarrow" "css_element"
And I click on "cohort plan" item in the autocomplete list
+ And I press key "27" in the field "Select cohorts to sync"
When I click on "Add cohorts" "button"
Then I should see "2 learning plans were created."
And I follow "Learning plan templates"
$this->assertEquals('A', $summary->evidence[1]->gradename);
}
- /**
- * Search cohorts.
- */
- public function test_search_cohorts() {
- $this->resetAfterTest(true);
-
- $syscontext = array('contextid' => context_system::instance()->id);
- $catcontext = array('contextid' => context_coursecat::instance($this->category->id)->id);
- $othercatcontext = array('contextid' => context_coursecat::instance($this->othercategory->id)->id);
-
- $cohort1 = $this->getDataGenerator()->create_cohort(array_merge($syscontext, array('name' => 'Cohortsearch 1')));
- $cohort2 = $this->getDataGenerator()->create_cohort(array_merge($catcontext, array('name' => 'Cohortsearch 2')));
- $cohort3 = $this->getDataGenerator()->create_cohort(array_merge($othercatcontext, array('name' => 'Cohortsearch 3')));
-
- // Check for parameter $includes = 'parents'.
-
- // A user without permission in the system.
- $this->setUser($this->user);
- try {
- $result = external::search_cohorts("Cohortsearch", $syscontext, 'parents');
- $this->fail('Invalid permissions in system');
- } catch (required_capability_exception $e) {
- // All good.
- }
-
- // A user without permission in a category.
- $this->setUser($this->catuser);
- try {
- $result = external::search_cohorts("Cohortsearch", $catcontext, 'parents');
- $this->fail('Invalid permissions in category');
- } catch (required_capability_exception $e) {
- // All good.
- }
-
- // A user with permissions in the system.
- $this->setUser($this->creator);
- $result = external::search_cohorts("Cohortsearch", $syscontext, 'parents');
- $this->assertEquals(1, count($result['cohorts']));
- $this->assertEquals('Cohortsearch 1', $result['cohorts'][$cohort1->id]->name);
-
- // A user with permissions in the category.
- $this->setUser($this->catcreator);
- $result = external::search_cohorts("Cohortsearch", $catcontext, 'parents');
- $this->assertEquals(2, count($result['cohorts']));
- $cohorts = array();
- foreach ($result['cohorts'] as $cohort) {
- $cohorts[] = $cohort->name;
- }
- $this->assertTrue(in_array('Cohortsearch 1', $cohorts));
- $this->assertTrue(in_array('Cohortsearch 2', $cohorts));
-
- // Check for parameter $includes = 'self'.
- $this->setUser($this->creator);
- $result = external::search_cohorts("Cohortsearch", $othercatcontext, 'self');
- $this->assertEquals(1, count($result['cohorts']));
- $this->assertEquals('Cohortsearch 3', $result['cohorts'][$cohort3->id]->name);
-
- // Check for parameter $includes = 'all'.
- $this->setUser($this->creator);
- $result = external::search_cohorts("Cohortsearch", $syscontext, 'all');
- $this->assertEquals(3, count($result['cohorts']));
-
- // Detect invalid parameter $includes.
- $this->setUser($this->creator);
- try {
- $result = external::search_cohorts("Cohortsearch", $syscontext, 'invalid');
- $this->fail('Invalid parameter includes');
- } catch (coding_exception $e) {
- // All good.
- }
- }
-
}
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2017051500; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version = 2017062700; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2017050500; // Requires this Moodle version.
$plugin->component = 'tool_lp'; // Full name of the plugin (used for diagnostics).
$string['mainmenu'] = 'Main menu';
$string['mobileapp'] = 'Mobile app';
$string['mobileappconnected'] = 'Mobile app connected';
-$string['mobileappenabled'] = 'This site has mobile app access enabled. You can use mobile app to access the content of your courses and much more. Click <a href="{$a}">here</a> for more information';
+$string['mobileappenabled'] = 'This site has mobile app access enabled.<br /><a href="{$a}">Download the mobile app</a>.';
$string['mobileappearance'] = 'Mobile appearance';
$string['mobileauthentication'] = 'Mobile authentication';
$string['mobilecssurl'] = 'CSS';
$string['mobilefeatures'] = 'Mobile features';
$string['mobilesettings'] = 'Mobile settings';
$string['pluginname'] = 'Moodle Mobile tools';
-$string['setuplink'] = 'Mobile setup link';
-$string['setuplink_desc'] = 'Link to documentation page to help users setup their mobile app.';
+$string['setuplink'] = 'App download page';
+$string['setuplink_desc'] = 'URL of page with links to download the mobile app from the App Store and Google Play.';
$string['smartappbanners'] = 'App Banners';
$string['pluginnotenabledorconfigured'] = 'Plugin not enabled or configured.';
$string['remoteaddons'] = 'Remote add-ons';
$string['typeoflogin'] = 'Type of login';
$string['typeoflogin_desc'] = 'If the site uses a SSO authentication method, then select via a browser window or via an embedded browser. An embedded browser provides a better user experience, though it doesn\'t work with all SSO plugins. If using SSO, autologinguests should be disabled.';
+$string['getmoodleonyourmobile'] = 'Get Moodle on your mobile';
$node = new core_user\output\myprofile\node('mobile', 'mobileappnode', $mobilestr, null);
$tree->add_node($node);
}
+
+/**
+ * Callback to add footer elements.
+ *
+ * @return str valid html footer content
+ * @since Moodle 3.4
+ */
+function tool_mobile_standard_footer_html() {
+ global $CFG;
+ $output = '';
+ if (!empty($CFG->enablemobilewebservice) && $url = tool_mobile_create_app_download_url()) {
+ $output .= html_writer::link($url, get_string('getmoodleonyourmobile', 'tool_mobile'));
+ }
+ return $output;
+}
* @return bool always true
*/
function xmldb_tool_monitor_upgrade($oldversion) {
- global $DB;
+ global $CFG, $DB;
$dbman = $DB->get_manager();
- if ($oldversion < 2014102000) {
-
- // Define field lastnotificationsent to be added to tool_monitor_subscriptions.
- $table = new xmldb_table('tool_monitor_subscriptions');
- $field = new xmldb_field('lastnotificationsent', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'timecreated');
-
- // Conditionally launch add field lastnotificationsent.
- if (!$dbman->field_exists($table, $field)) {
- $dbman->add_field($table, $field);
- }
-
- // Monitor savepoint reached.
- upgrade_plugin_savepoint(true, 2014102000, 'tool', 'monitor');
- }
-
- // Moodle v2.8.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v2.9.0 release upgrade line.
- // Put any upgrade step following this.
-
- // Moodle v3.0.0 release upgrade line.
- // Put any upgrade step following this.
-
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.