lib/google/
lib/htmlpurifier/
lib/jabber/
-lib/minify/
+lib/minify/matthiasmullie-minify/
+lib/minify/matthiasmullie-pathconverter/
lib/flowplayer/
lib/pear/Auth/RADIUS.php
lib/pear/Crypt/CHAP.php
'no-inner-declarations': 'error',
'no-invalid-regexp': 'error',
'no-irregular-whitespace': 'error',
- 'no-negated-in-lhs': 'error',
'no-obj-calls': 'error',
'no-prototype-builtins': 'off',
'no-regex-spaces': 'error',
'no-unexpected-multiline': 'error',
'no-unreachable': 'warn',
'no-unsafe-finally': 'error',
+ 'no-unsafe-negation': 'error',
'use-isnan': 'error',
'valid-jsdoc': ['warn', { 'requireReturn': false, 'requireParamDescription': false, 'requireReturnDescription': false }],
'valid-typeof': 'error',
'no-extra-bind': 'warn',
'no-fallthrough': 'error',
'no-floating-decimal': 'warn',
+ 'no-global-assign': 'warn',
// Enabled by grunt for AMD modules: 'no-implicit-globals': 'error',
'no-implied-eval': 'error',
'no-invalid-this': 'error',
'no-loop-func': 'error',
'no-multi-spaces': 'warn',
'no-multi-str': 'error',
- 'no-native-reassign': 'warn',
'no-new-func': 'error',
'no-new-wrappers': 'error',
'no-octal': 'error',
'no-delete-var': 'error',
'no-undef': 'error',
'no-undef-init': 'error',
- 'no-unused-vars': ['error', { 'caughtErrors': 'none', 'argsIgnorePattern': "(e|event)" }],
+ 'no-unused-vars': ['error', { 'caughtErrors': 'none' }],
// === Stylistic Issues ===
'array-bracket-spacing': 'warn',
'computed-property-spacing': 'error',
'consistent-this': 'off',
'eol-last': 'off',
+ 'func-call-spacing': ['warn', 'never'],
'func-names': 'off',
'func-style': 'off',
// indent currently not doing well with our wrapping style, so disabled.
'no-nested-ternary': 'warn',
'no-new-object': 'off',
'no-plusplus': 'off',
- 'no-spaced-func': 'warn',
+ 'no-tabs': 'error',
'no-ternary': 'off',
'no-trailing-spaces': 'error',
'no-underscore-dangle': 'off',
'spaced-comment': 'warn',
'unicode-bom': 'error',
'wrap-regex': 'off',
+
+ // === Deprecations ===
+ "no-restricted-properties": ['warn', {
+ 'object': 'M',
+ 'property': 'str',
+ 'message': 'Use AMD module "core/str" or M.util.get_string()'
+ }],
}
}
# Generated by "grunt ignorefiles"
theme/bootstrapbase/style/
+theme/clean/style/custom.css
+theme/more/style/custom.css
node_modules/
vendor/
auth/cas/CAS/
lib/google/
lib/htmlpurifier/
lib/jabber/
-lib/minify/
+lib/minify/matthiasmullie-minify/
+lib/minify/matthiasmullie-pathconverter/
lib/flowplayer/
lib/pear/Auth/RADIUS.php
lib/pear/Crypt/CHAP.php
- 7.0
- 5.6
+services:
+ - redis-server
+
env:
# Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
# start first so that the total run time is not too high.
echo 'auth.json' >> .git/info/exclude
fi
+ # Enable Redis.
+ echo 'extension="redis.so"' > /tmp/redis.ini
+ phpenv config-add /tmp/redis.ini
+
# Install composer dependencies.
# We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
# Typically it should be able to use the Composer cache if any other job has already completed before we started here.
sed -i \
-e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
-e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
+ -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
config.php ;
# Initialise PHPUnit for Moodle.
var eslintIgnores = ['# Generated by "grunt ignorefiles"', '*/**/yui/src/*/meta/', '*/**/build/'].concat(thirdPartyPaths);
grunt.file.write('.eslintignore', eslintIgnores.join('\n'));
// Generate .stylelintignore.
- var stylelintIgnores = ['# Generated by "grunt ignorefiles"', 'theme/bootstrapbase/style/'].concat(thirdPartyPaths);
+ var stylelintIgnores = [
+ '# Generated by "grunt ignorefiles"',
+ 'theme/bootstrapbase/style/',
+ 'theme/clean/style/custom.css',
+ 'theme/more/style/custom.css'
+ ].concat(thirdPartyPaths);
grunt.file.write('.stylelintignore', stylelintIgnores.join('\n'));
};
$cachewarnings = cache_helper::warnings();
// Check if there are events 1 API handlers.
$eventshandlers = $DB->get_records_sql('SELECT DISTINCT component FROM {events_handlers}');
+$themedesignermode = !empty($CFG->themedesignermode);
admin_externalpage_setup('adminnotifications');
echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems,
$maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb,
- $registered, $cachewarnings, $eventshandlers);
+ $registered, $cachewarnings, $eventshandlers, $themedesignermode);
*/
public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
$cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
- $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0) {
+ $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0, $themedesignermode = false) {
global $CFG;
$output = '';
$output .= $this->legacy_log_store_writing_error();
$output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
$output .= $this->insecure_dataroot_warning($insecuredataroot);
+ $output .= $this->themedesignermode_warning($themedesignermode);
$output .= $this->display_errors_warning($errorsdisplayed);
$output .= $this->buggy_iconv_warning($buggyiconvnomb);
$output .= $this->cron_overdue_warning($cronoverdue);
return $this->warning(get_string('displayerrorswarning', 'admin'));
}
+ /**
+ * Render an appropriate message if themdesignermode is enabled.
+ * @param bool $themedesignermode true if enabled
+ * @return string HTML to output.
+ */
+ protected function themedesignermode_warning($themedesignermode) {
+ if (!$themedesignermode) {
+ return '';
+ }
+
+ return $this->warning(get_string('themedesignermodewarning', 'admin'));
+ }
+
/**
* Render an appropriate message if iconv is buggy and mbstring missing.
* @param bool $buggyiconvnomb
$temp->add(new admin_setting_configcheckbox('passwordchangelogout',
new lang_string('passwordchangelogout', 'admin'),
new lang_string('passwordchangelogout_desc', 'admin'), 0));
+
+ $temp->add(new admin_setting_configcheckbox('passwordchangetokendeletion',
+ new lang_string('passwordchangetokendeletion', 'admin'),
+ new lang_string('passwordchangetokendeletion_desc', 'admin'), 0));
+
$temp->add(new admin_setting_configcheckbox('groupenrolmentkeypolicy', new lang_string('groupenrolmentkeypolicy', 'admin'), new lang_string('groupenrolmentkeypolicy_desc', 'admin'), 1));
$temp->add(new admin_setting_configcheckbox('disableuserimages', new lang_string('disableuserimages', 'admin'), new lang_string('configdisableuserimages', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('emailchangeconfirmation', new lang_string('emailchangeconfirmation', 'admin'), new lang_string('configemailchangeconfirmation', 'admin'), 1));
--- /dev/null
+@tool @tool_behat
+Feature: Transform date time string arguments
+ In order to write tests with relative date and time
+ As a user
+ I need to apply some transformations to the steps arguments
+
+ Scenario: Set date in table and check date with specific format
+ Given I am on site homepage
+ And the following "users" exist:
+ | username | firstname | lastname |
+ | teacher1 | Teacher | 1 |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "activities" exist:
+ | activity | course | idnumber | name | intro | duedate |
+ | assign | C1 | assign1 | Test assignment name | Test assignment description | ##yesterday## |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher1 | C1 | editingteacher |
+ And I log in as "teacher1"
+ And I follow "Course 1"
+ And I follow "Test assignment name"
+ And I should see "##yesterday##l, j F Y##"
+ And I log out
And I press "Update profile"
And I follow "Edit profile"
Then I should not see "NASTYSTRING"
- And the field "Surname" matches value "$NASTYSTRING1"
- And the field "City/town" matches value "$NASTYSTRING3"
+ # BEHAT Transformation regression - See MDL-56397
+ #And the field "Surname" matches value "$NASTYSTRING1"
+ #And the field "City/town" matches value "$NASTYSTRING3"
Scenario: Use double quotes
When I set the following fields to these values:
And I should see "My Firstname"
And I should see "My Surname"
And the field "First name" matches value "My Firstname $NASTYSTRING1"
- And the field "Surname" matches value "My Surname $NASTYSTRING2"
+ # BEHAT Transformation regression - See MDL-56397
+ #And the field "Surname" matches value "My Surname $NASTYSTRING2"
--- /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/>.
+
+/**
+ * Auto-login end-point, a user can be fully authenticated in the site providing a valid key.
+ *
+ * @package tool_mobile
+ * @copyright 2016 Juan Leyva
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(__DIR__ . '/../../../config.php');
+require_once($CFG->libdir . '/externallib.php');
+
+$userid = required_param('userid', PARAM_INT); // The user id the key belongs to (for double-checking).
+$key = required_param('key', PARAM_ALPHANUMEXT); // The key generated by the tool_mobile_external::get_autologin_key() external function.
+$urltogo = optional_param('urltogo', $CFG->wwwroot, PARAM_URL); // URL to redirect.
+
+$context = context_system::instance();
+$PAGE->set_context($context);
+// Force https.
+$PAGE->https_required();
+
+// Check if the user is already logged-in.
+if (isloggedin() and !isguestuser()) {
+ delete_user_key('tool_mobile', $userid);
+ if ($USER->id == $userid) {
+ redirect($urltogo);
+ } else {
+ throw new moodle_exception('alreadyloggedin', 'error', '', format_string(fullname($USER)));
+ }
+}
+
+tool_mobile\api::check_autologin_prerequisites($userid);
+
+// Validate and delete the key.
+$key = validate_user_key($key, 'tool_mobile', null);
+delete_user_key('tool_mobile', $userid);
+
+// Double check key belong to user.
+if ($key->userid != $userid) {
+ throw new moodle_exception('invalidkey');
+}
+
+// Key validated, now require an active user: not guest, not suspended.
+$user = core_user::get_user($key->userid, '*', MUST_EXIST);
+core_user::require_active_user($user, true, true);
+
+// Do the user log-in.
+if (!$user = get_complete_user_data('id', $user->id)) {
+ throw new moodle_exception('cannotfinduser', '', '', $user->id);
+}
+
+complete_user_login($user);
+\core\session\manager::apply_concurrent_login_limit($user->id, session_id());
+
+redirect($urltogo);
use core_plugin_manager;
use context_system;
use moodle_url;
+use moodle_exception;
/**
* API exposed by tool_mobile
const LOGIN_VIA_BROWSER = 2;
/** @var int to identify the login via an embedded browser. */
const LOGIN_VIA_EMBEDDED_BROWSER = 3;
+ /** @var int seconds an auto-login key will expire. */
+ const LOGIN_KEY_TTL = 60;
/**
* Returns a list of Moodle plugins supporting the mobile app.
return $settings;
}
+ /*
+ * Check if all the required conditions are met to allow the auto-login process continue.
+ *
+ * @param int $userid current user id
+ * @since Moodle 3.2
+ * @throws moodle_exception
+ */
+ public static function check_autologin_prerequisites($userid) {
+ global $CFG;
+
+ if (!$CFG->enablewebservices or !$CFG->enablemobilewebservice) {
+ throw new moodle_exception('enablewsdescription', 'webservice');
+ }
+
+ if (!is_https()) {
+ throw new moodle_exception('httpsrequired', 'tool_mobile');
+ }
+
+ if (has_capability('moodle/site:config', context_system::instance(), $userid) or is_siteadmin($userid)) {
+ throw new moodle_exception('autologinnotallowedtoadmins', 'tool_mobile');
+ }
+ }
+
+ /**
+ * Creates an auto-login key for the current user, this key is restricted by time and ip address.
+ *
+ * @return string the key
+ * @since Moodle 3.2
+ */
+ public static function get_autologin_key() {
+ global $USER;
+ // Delete previous keys.
+ delete_user_key('tool_mobile', $USER->id);
+
+ // Create a new key.
+ $iprestriction = getremoteaddr();
+ $validuntil = time() + self::LOGIN_KEY_TTL;
+ return create_user_key('tool_mobile', $USER->id, null, $iprestriction, $validuntil);
+ }
}
use external_single_structure;
use external_multiple_structure;
use external_warnings;
+use context_system;
+use moodle_exception;
+use moodle_url;
+use core_text;
/**
* This is the external API for this tool.
)
);
}
+
+ /**
+ * Returns description of get_autologin_key() parameters.
+ *
+ * @return external_function_parameters
+ * @since Moodle 3.2
+ */
+ public static function get_autologin_key_parameters() {
+ return new external_function_parameters (
+ array(
+ 'privatetoken' => new external_value(PARAM_ALPHANUM, 'Private token, usually generated by login/token.php'),
+ )
+ );
+ }
+
+ /**
+ * Creates an auto-login key for the current user. Is created only in https sites and is restricted by time and ip address.
+ *
+ * @param string $privatetoken the user private token for validating the request
+ * @return array with the settings and warnings
+ * @since Moodle 3.2
+ */
+ public static function get_autologin_key($privatetoken) {
+ global $CFG, $DB, $USER;
+
+ $params = self::validate_parameters(self::get_autologin_key_parameters(), array('privatetoken' => $privatetoken));
+ $privatetoken = $params['privatetoken'];
+
+ $context = context_system::instance();
+
+ // We must toletare these two exceptions: forcepasswordchangenotice and usernotfullysetup.
+ try {
+ self::validate_context($context);
+ } catch (Exception $e) {
+ if ($e instanceof moodle_exception) {
+ if (($e->errorcode != 'usernotfullysetup') and
+ ($e->errorcode != 'forcepasswordchangenotice')) {
+
+ // In case we receive a different exception, throw it.
+ throw $e;
+ }
+ } else {
+ throw $e;
+ }
+ }
+
+ api::check_autologin_prerequisites($USER->id);
+
+ if (isset($_GET['privatetoken']) or empty($privatetoken)) {
+ throw new moodle_exception('invalidprivatetoken', 'tool_mobile');
+ }
+
+ // Check the request counter, we must limit the number of times the privatetoken is sent.
+ // Between each request 6 minutes are required.
+ $last = get_user_preferences('tool_mobile_autologin_request_last', 0, $USER);
+ // Check if we must reset the count.
+ $timenow = time();
+ if ($timenow - $last < 6 * MINSECS) {
+ throw new moodle_exception('autologinkeygenerationlockout', 'tool_mobile');
+ }
+ set_user_preference('tool_mobile_autologin_request_last', $timenow, $USER);
+
+ // We are expecting a privatetoken linked to the current token being used.
+ // This WS is only valid when using mobile services via REST (this is intended).
+ $currenttoken = required_param('wstoken', PARAM_ALPHANUM);
+ $conditions = array(
+ 'userid' => $USER->id,
+ 'token' => $currenttoken,
+ 'privatetoken' => $privatetoken,
+ );
+ if (!$token = $DB->get_record('external_tokens', $conditions)) {
+ throw new moodle_exception('invalidprivatetoken', 'tool_mobile');
+ }
+
+ $result = array();
+ $result['key'] = api::get_autologin_key();
+ $autologinurl = new moodle_url("/$CFG->admin/tool/mobile/autologin.php");
+ $result['autologinurl'] = $autologinurl->out(false);
+ $result['warnings'] = array();
+ return $result;
+ }
+
+ /**
+ * Returns description of get_autologin_key() result value.
+ *
+ * @return external_description
+ * @since Moodle 3.2
+ */
+ public static function get_autologin_key_returns() {
+ return new external_single_structure(
+ array(
+ 'key' => new external_value(PARAM_ALPHANUMEXT, 'Auto-login key for a single usage with time expiration.'),
+ 'autologinurl' => new external_value(PARAM_URL, 'Auto-login URL.'),
+ 'warnings' => new external_warnings(),
+ )
+ );
+ }
}
'description' => 'Returns a list of the site configurations, filtering by section.',
'type' => 'read',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
- )
+ ),
+ 'tool_mobile_get_autologin_key' => array(
+ 'classname' => 'tool_mobile\external',
+ 'methodname' => 'get_autologin_key',
+ 'description' => 'Creates an auto-login key for the current user.
+ Is created only in https sites and is restricted by time and ip address.',
+ 'type' => 'write',
+ 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
+ )
);
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+$string['autologinkeygenerationlockout'] = 'Auto-login key generation is locked out, too much requests in an hour.';
+$string['autologinnotallowedtoadmins'] = 'Auto-login is not allowed to site admins';
$string['clickheretolaunchtheapp'] = 'Click here if the app does not open automatically.';
$string['enablesmartappbanners'] = 'Enable Smart App Banners';
$string['enablesmartappbanners_desc'] = 'This will display a banner promoting the Moodle Mobile app when visiting the site in Mobile Safari.';
$string['forcedurlscheme'] = 'The URL scheme allows to open the mobile app from other apps like the browser. Use this setting if you want to allow only your custom branded app to be opened by the browser.';
$string['forcedurlscheme_key'] = 'URL scheme';
+$string['httpsrequired'] = 'HTTPS required';
+$string['invalidprivatetoken'] = 'Invalid private token. Token should not be empty or passed via GET parameter.';
$string['iosappid'] = 'App\'s unique identifier';
$string['iosappid_desc'] = 'You only need to change this value if you have a custom iOS app';
$string['loginintheapp'] = 'Via the app';
--- /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/>.
+
+/**
+ * Moodle Mobile admin tool api tests.
+ *
+ * @package tool_mobile
+ * @category external
+ * @copyright 2016 Juan Leyva
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 3.1
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+
+require_once($CFG->dirroot . '/webservice/tests/helpers.php');
+
+use tool_mobile\api;
+
+/**
+ * Moodle Mobile admin tool api tests.
+ *
+ * @package tool_mobile
+ * @copyright 2016 Juan Leyva
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 3.1
+ */
+class tool_mobile_api_testcase extends externallib_advanced_testcase {
+
+ /**
+ * Test get_autologin_key.
+ */
+ public function test_get_autologin_key() {
+ global $USER, $DB;
+
+ $this->resetAfterTest(true);
+ $this->setAdminUser();
+
+ // Set server timezone for test.
+ $this->setTimezone('UTC');
+ // SEt user to GMT+5.
+ $USER->timezone = 5;
+
+ $timenow = time();
+ $key = api::get_autologin_key();
+
+ $key = $DB->get_record('user_private_key', array('value' => $key), '*', MUST_EXIST);
+ $this->assertEquals($timenow + api::LOGIN_KEY_TTL, $key->validuntil);
+ $this->assertEquals('0.0.0.0', $key->iprestriction);
+ }
+}
use tool_mobile\api;
/**
- * External learning plans webservice API tests.
+ * Moodle Mobile admin tool external functions tests.
*
* @package tool_mobile
* @copyright 2016 Juan Leyva
$this->assertEquals($expected, $result['settings']);
}
+ /*
+ * Test get_autologin_key.
+ */
+ public function test_get_autologin_key() {
+ global $DB, $CFG, $USER;
+
+ $this->resetAfterTest(true);
+
+ $user = $this->getDataGenerator()->create_user();
+ $this->setUser($user);
+ $service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
+
+ $token = external_generate_token_for_current_user($service);
+ $this->assertDebuggingCalled(); // MDL-55992.
+
+ // Check we got the private token.
+ $this->assertTrue(isset($token->privatetoken));
+
+ // Enable requeriments.
+ $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->httpswwwroot); // Mock https.
+ $CFG->enablewebservices = 1;
+ $CFG->enablemobilewebservice = 1;
+ $_GET['wstoken'] = $token->token; // Mock parameters.
+
+ $this->setCurrentTimeStart();
+ $result = external::get_autologin_key($token->privatetoken);
+ $result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
+ // Validate the key.
+ $this->assertEquals(32, core_text::strlen($result['key']));
+ $key = $DB->get_record('user_private_key', array('value' => $result['key']));
+ $this->assertEquals($USER->id, $key->userid);
+ $this->assertTimeCurrent($key->validuntil - api::LOGIN_KEY_TTL);
+
+ // Now, try with an invalid private token.
+ set_user_preference('tool_mobile_autologin_request_last', time() - HOURSECS, $USER);
+
+ $this->expectException('moodle_exception');
+ $this->expectExceptionMessage(get_string('invalidprivatetoken', 'tool_mobile'));
+ $result = external::get_autologin_key(random_string('64'));
+ }
+
+ /**
+ * Test get_autologin_key missing ws.
+ */
+ public function test_get_autologin_key_missing_ws() {
+ $this->resetAfterTest(true);
+
+ $this->setAdminUser();
+ $this->expectException('moodle_exception');
+ $this->expectExceptionMessage(get_string('enablewsdescription', 'webservice'));
+ $result = external::get_autologin_key('');
+ }
+
+ /**
+ * Test get_autologin_key missing https.
+ */
+ public function test_get_autologin_key_missing_https() {
+ global $CFG;
+
+ $this->resetAfterTest(true);
+ $this->setAdminUser();
+ $CFG->enablewebservices = 1;
+ $CFG->enablemobilewebservice = 1;
+
+ $this->expectException('moodle_exception');
+ $this->expectExceptionMessage(get_string('httpsrequired', 'tool_mobile'));
+ $result = external::get_autologin_key('');
+ }
+
+ /**
+ * Test get_autologin_key missing admin.
+ */
+ public function test_get_autologin_key_missing_admin() {
+ global $CFG;
+
+ $this->resetAfterTest(true);
+ $this->setAdminUser();
+ $CFG->enablewebservices = 1;
+ $CFG->enablemobilewebservice = 1;
+ $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->httpswwwroot);
+
+ $this->expectException('moodle_exception');
+ $this->expectExceptionMessage(get_string('autologinnotallowedtoadmins', 'tool_mobile'));
+ $result = external::get_autologin_key('');
+ }
+
+ /**
+ * Test get_autologin_key locked.
+ */
+ public function test_get_autologin_key_missing_locked() {
+ global $CFG, $DB, $USER;
+
+ $this->resetAfterTest(true);
+ $user = $this->getDataGenerator()->create_user();
+ $this->setUser($user);
+ $CFG->enablewebservices = 1;
+ $CFG->enablemobilewebservice = 1;
+ $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->httpswwwroot);
+
+ $service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
+
+ $token = external_generate_token_for_current_user($service);
+ $this->assertDebuggingCalled(); // MDL-55992.
+ $_GET['wstoken'] = $token->token; // Mock parameters.
+
+ $result = external::get_autologin_key($token->privatetoken);
+ $result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
+
+ // Mock last time request.
+ $mocktime = time() - 7 * MINSECS;
+ set_user_preference('tool_mobile_autologin_request_last', $mocktime, $USER);
+ $result = external::get_autologin_key($token->privatetoken);
+ $result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
+
+ // We just requested one token, we must wait.
+ $this->expectException('moodle_exception');
+ $this->expectExceptionMessage(get_string('autologinkeygenerationlockout', 'tool_mobile'));
+ $result = external::get_autologin_key($token->privatetoken);
+ }
}
*/
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2016052304; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version = 2016052305; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2016051900; // Requires this Moodle version.
$plugin->component = 'tool_mobile'; // Full name of the plugin (used for diagnostics).
Then I should see "Subscription successfully removed"
And "#toolmonitorsubs_r0" "css_element" should not exist
+ @_bug_phantomjs
Scenario: Receiving notification on site level
Given I log in as "admin"
And I follow "Preferences" in the user menu
- And I follow "Messaging"
- And I click on "input[name^=tool_monitor_notification_loggedin]" "css_element"
- And I press "Save changes"
+ And I click on "Notification preferences" "link" in the "#page-content" "css_element"
+ And I click on ".preference-state" "css_element" in the "Notifications of rule subscriptions" "table_row"
+ And I wait until the page is ready
And I follow "Preferences" in the user menu
And I follow "Event monitoring"
And I set the field "Select a course" to "Acceptance test site"
And I am on site homepage
And I trigger cron
And I am on site homepage
- When I follow "Messages" in the user menu
- And I follow "Do not reply to this email (1)"
- Then I should see "The course was viewed."
+ When I click on ".popover-region-notifications" "css_element"
+ And I click on "View more" "link" in the ".popover-region-notifications" "css_element"
+ Then I should see "New rule site level"
+ And I should see "The course was viewed"
+ @_bug_phantomjs
Scenario: Receiving notification on course level
Given I log in as "teacher1"
And I follow "Preferences" in the user menu
- And I follow "Messaging"
- And I click on "input[name^=tool_monitor_notification_loggedin]" "css_element"
- And I press "Save changes"
+ And I click on "Notification preferences" "link" in the "#page-content" "css_element"
+ And I click on ".preference-state" "css_element" in the "Notifications of rule subscriptions" "table_row"
+ And I wait until the page is ready
And I follow "Preferences" in the user menu
And I follow "Event monitoring"
And I set the field "Select a course" to "Course 1"
And I follow "Course 1"
And I trigger cron
And I am on site homepage
- When I follow "Messages" in the user menu
- And I follow "Do not reply to this email (1)"
- Then I should see "The course was viewed."
+ When I click on ".popover-region-notifications" "css_element"
+ And I click on "View more" "link" in the ".popover-region-notifications" "css_element"
+ Then I should see "New rule course level"
+ And I should see "The course was viewed"
Scenario: Navigating via quick link to rules
Given I log in as "admin"
// Get the list of possible template directories.
$dirs = mustache_template_finder::get_template_directories_for_component($component);
$filename = false;
+ $themedir = core_component::get_plugin_types()['theme'];
foreach ($dirs as $dir) {
// Skip theme dirs - we only want the original plugin/core template.
- if (strpos($dir, "/theme/") === false) {
- $candidate = $dir . $template . '.mustache';
- if (file_exists($candidate)) {
- $filename = $candidate;
- break;
- }
+ if (strpos($dir, $themedir) === 0) {
+ continue;
+ }
+
+ $candidate = $dir . $template . '.mustache';
+ if (file_exists($candidate)) {
+ $filename = $candidate;
+ break;
}
}
+
if ($filename === false) {
throw new moodle_exception('filenotfound', 'error');
}
if (!empty($format['defaultblocks'])) {
$blocknames = $format['defaultblocks'];
} else {
- if (!empty($CFG->defaultblocks)) {
+ if (isset($CFG->defaultblocks)) {
$blocknames = $CFG->defaultblocks;
} else {
$blocknames = 'participants,activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';
Then I should see "Welcome Student" in the "Course overview" "block"
And I should see "You have no unread messages" in the "Course overview" "block"
And I follow "messages"
- And I should see "Contact list empty"
+ And I should see "No messages"
+ @javascript
Scenario: View the block by a user with the welcome area and the user having messages.
Given the following config values are set as admin:
| showwelcomearea | 1 | block_course_overview |
And I follow "Course 1"
When I turn editing mode on
And I add the "Messages" block
- Then I should see "No messages waiting" in the "Messages" "block"
+ Then I should see "No messages" in the "Messages" "block"
+ @javascript
Scenario: View the block by a user who has messages.
Given I log in as "student1"
And I follow "Messages" in the user menu
And I add the "Messages" block
Then I should see "Student 1" in the "Messages" "block"
+ @javascript
Scenario: Use the block to send a message to a user.
Given I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add the "Messages" block
- And I follow "Messages"
+ And I click on "//a[normalize-space(.) = 'Messages']" "xpath_element" in the "Messages" "block"
And I send "This is message 1" message to "Student 1" user
And I log out
When I log in as "student1"
Given I log in as "teacher1"
And I press "Customise this page"
When I add the "Messages" block
- Then I should see "No messages waiting" in the "Messages" "block"
+ Then I should see "No messages" in the "Messages" "block"
+ @javascript
Scenario: View the block by a user who has messages.
Given I log in as "student1"
And I follow "Messages" in the user menu
And I add the "Messages" block
Then I should see "Student 1" in the "Messages" "block"
+ @javascript
Scenario: Use the block to send a message to a user.
Given I log in as "teacher1"
And I press "Customise this page"
And I add the "Messages" block
- And I follow "Messages"
+ And I click on "//a[normalize-space(.) = 'Messages']" "xpath_element" in the "Messages" "block"
And I send "This is message 1" message to "Student 1" user
And I log out
When I log in as "student1"
Scenario: View the block by a user who does not have any messages.
Given I log in as "teacher1"
When I am on site homepage
- Then I should see "No messages waiting" in the "Messages" "block"
+ Then I should see "No messages" in the "Messages" "block"
Scenario: Try to view the block as a guest user.
Given I log in as "guest"
When I am on site homepage
Then I should not see "Messages"
+ @javascript
Scenario: View the block by a user who has messages.
Given I log in as "student1"
And I follow "Messages" in the user menu
And I am on site homepage
Then I should see "Student 1" in the "Messages" "block"
+ @javascript
Scenario: Use the block to send a message to a user.
Given I log in as "teacher1"
And I am on site homepage
- And I follow "Messages"
+ And I click on "//a[normalize-space(.) = 'Messages']" "xpath_element" in the "Messages" "block"
And I send "This is message 1" message to "Student 1" user
And I log out
When I log in as "student1"
}
function get_content() {
- global $USER, $CFG, $DB, $OUTPUT, $PAGE;
+ global $USER, $CFG, $DB, $OUTPUT;
if ($this->content !== NULL) {
return $this->content;
if (isloggedin() && has_capability('moodle/site:sendmessage', $this->page->context)
&& !empty($CFG->messaging) && !isguestuser()) {
$canshowicon = true;
- message_messenger_requirejs();
} else {
$canshowicon = false;
}
if ($canshowicon and ($USER->id != $user->id) and !isguestuser($user)) { // Only when logged in and messaging active etc
$anchortagcontents = '<img class="iconsmall" src="'.$OUTPUT->pix_url('t/message') . '" alt="'. get_string('messageselectadd') .'" />';
$anchorurl = new moodle_url('/message/index.php', array('id' => $user->id));
- $anchortag = html_writer::link($anchorurl, $anchortagcontents, array_merge(
- message_messenger_sendmessage_link_params($user),
- array('title' => get_string('messageselectadd'))
- ));
+ $anchortag = html_writer::link($anchorurl, $anchortagcontents,
+ array('title' => get_string('messageselectadd')));
$this->content->text .= '<div class="message">'.$anchortag.'</div>';
}
When I log in as "student1"
And I follow "Course 1"
And I click on "Participants" "link" in the "People" "block"
- Then I should see "All participants" in the "h3" "css_element"
+ Then I should see "All participants" in the "#page-content" "css_element"
And the "My courses" select box should contain "C101"
Scenario: Student without permission can not view participants link
};
adminTree.collapseGroup = function(item) {
Tree.prototype.collapseGroup.call(this, item);
- Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {
- instanceid: instanceid
- });
Y.use('moodle-core-event', function() {
Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {
instanceid: instanceid
$mform =& $this->_form;
- $mform->addElement('url', 'url', get_string('url', 'blog'), array('size' => 50));
+ $mform->addElement('url', 'url', get_string('url', 'blog'), array('size' => 50), array('usefilepicker' => false));
$mform->setType('url', PARAM_URL);
$mform->addRule('url', get_string('emptyurl', 'blog'), 'required', null, 'client');
$mform->addHelpButton('url', 'url', 'blog');
}
$definition = $this->create_definition($component, $area);
$definition->set_identifiers($identifiers);
- $cache = $this->create_cache($definition, $identifiers);
+ $cache = $this->create_cache($definition);
// Loaders are always held onto to speed up subsequent requests.
$this->cachesfromdefinitions[$definitionname] = $cache;
return $cache;
}
$definition = cache_definition::load_adhoc($mode, $component, $area, $options);
$definition->set_identifiers($identifiers);
- $cache = $this->create_cache($definition, $identifiers);
+ $cache = $this->create_cache($definition);
$this->cachesfromparams[$key] = $cache;
return $cache;
}
*/
public function create_cache_from_definition($component, $area, array $identifiers = array(), $unused = null) {
$definition = $this->create_definition($component, $area);
- $cache = $this->create_cache($definition, $identifiers);
+ $definition->set_identifiers($identifiers);
+ $cache = $this->create_cache($definition);
return $cache;
}
*/
public function create_cache_from_params($mode, $component, $area, array $identifiers = array(), array $options = array()) {
$definition = cache_definition::load_adhoc($mode, $component, $area);
- $cache = $this->create_cache($definition, $identifiers);
+ $definition->set_identifiers($identifiers);
+ $cache = $this->create_cache($definition);
return $cache;
}
'plugin' => $details['plugin'],
'default' => $details['default'],
'isready' => $store->is_ready(),
- 'requirementsmet' => $store->are_requirements_met(),
+ 'requirementsmet' => $class::are_requirements_met(),
'mappings' => 0,
'lock' => $lock,
'modes' => array(
* @return bool True if the stores software/hardware requirements have been met and it can be used. False otherwise.
*/
public static function are_requirements_met() {
- if (!extension_loaded('apcu') || !ini_get('apc.enabled')) {
+ $enabled = ini_get('apc.enabled') && (php_sapi_name() != "cli" || ini_get('apc.enable_cli'));
+ if (!extension_loaded('apcu') || !$enabled) {
return false;
}
*/
public static function reorder_template_competency($templateid, $competencyidfrom, $competencyidto) {
static::require_enabled();
- // First we do a permissions check.
- $context = context_system::instance();
+ $template = new template($templateid);
- require_capability('moodle/competency:templatemanage', $context);
+ // First we do a permissions check.
+ if (!$template->can_manage()) {
+ throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
+ 'nopermissions', '');
+ }
$down = true;
$matches = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyidfrom));
$this->assertInstanceOf('core_competency\\template_cohort', $result);
}
+ public function test_reorder_template_competencies_permissions() {
+ $this->resetAfterTest(true);
+
+ $dg = $this->getDataGenerator();
+ $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
+ $cat = $dg->create_category();
+ $catcontext = context_coursecat::instance($cat->id);
+ $syscontext = context_system::instance();
+
+ $user = $dg->create_user();
+ $role = $dg->create_role();
+ assign_capability('moodle/competency:templatemanage', CAP_ALLOW, $role, $syscontext->id, true);
+ $dg->role_assign($role, $user->id, $syscontext->id);
+
+ // Create a template.
+ $template = $lpg->create_template(array('contextid' => $catcontext->id));
+
+ // Create a competency framework.
+ $framework = $lpg->create_framework(array('contextid' => $catcontext->id));
+
+ // Create competencies.
+ $competency1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
+ $competency2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
+
+ // Add the competencies.
+ $lpg->create_template_competency(array(
+ 'templateid' => $template->get_id(),
+ 'competencyid' => $competency1->get_id()
+ ));
+ $lpg->create_template_competency(array(
+ 'templateid' => $template->get_id(),
+ 'competencyid' => $competency2->get_id()
+ ));
+ $this->setUser($user);
+ // Can reorder competencies with system context permissions in category context.
+ $result = api::reorder_template_competency($template->get_id(), $competency2->get_id(), $competency1->get_id());
+ $this->assertTrue($result);
+ unassign_capability('moodle/competency:templatemanage', $role, $syscontext->id);
+ accesslib_clear_all_caches_for_unit_testing();
+
+ try {
+ api::reorder_template_competency($template->get_id(), $competency2->get_id(), $competency1->get_id());
+ $this->fail('Exception expected due to not permissions to manage template competencies');
+ } catch (required_capability_exception $e) {
+ $this->assertEquals('nopermissions', $e->errorcode);
+ }
+
+ // Giving permissions in category context.
+ assign_capability('moodle/competency:templatemanage', CAP_ALLOW, $role, $catcontext->id, true);
+ $dg->role_assign($role, $user->id, $catcontext->id);
+ // User with templatemanage capability in category context can reorder competencies in temple.
+ $result = api::reorder_template_competency($template->get_id(), $competency1->get_id(), $competency2->get_id());
+ $this->assertTrue($result);
+ // Removing templatemanage capability in category context.
+ unassign_capability('moodle/competency:templatemanage', $role, $catcontext->id);
+ accesslib_clear_all_caches_for_unit_testing();
+
+ try {
+ api::reorder_template_competency($template->get_id(), $competency2->get_id(), $competency1->get_id());
+ $this->fail('Exception expected due to not permissions to manage template competencies');
+ } catch (required_capability_exception $e) {
+ $this->assertEquals('nopermissions', $e->errorcode);
+ }
+ }
+
public function test_delete_template() {
$this->resetAfterTest(true);
$this->setAdminUser();
"type": "project",
"homepage": "https://moodle.org",
"require-dev": {
- "phpunit/phpunit": "5.4.*",
+ "phpunit/phpunit": "5.5.*",
"phpunit/dbUnit": "1.4.*",
"moodlehq/behat-extension": "3.32.3"
}
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "c3da2812d8753f3fb2429366b373afa8",
- "content-hash": "a4e8fa2277e59a3c14afb3ae729bf4e7",
+ "hash": "ec5f1e9d8b8134cf6a4490ba5dfe0082",
+ "content-hash": "583f9a915721de799118a396dc81f177",
"packages": [],
"packages-dev": [
{
},
{
"name": "phpunit/phpunit",
- "version": "5.4.8",
+ "version": "5.5.7",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "3132365e1430c091f208e120b8845d39c25f20e6"
+ "reference": "3f67cee782c9abfaee5e32fd2f57cdd54bc257ba"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3132365e1430c091f208e120b8845d39c25f20e6",
- "reference": "3132365e1430c091f208e120b8845d39c25f20e6",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3f67cee782c9abfaee5e32fd2f57cdd54bc257ba",
+ "reference": "3f67cee782c9abfaee5e32fd2f57cdd54bc257ba",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-json": "*",
- "ext-pcre": "*",
- "ext-reflection": "*",
- "ext-spl": "*",
+ "ext-libxml": "*",
+ "ext-mbstring": "*",
+ "ext-xml": "*",
"myclabs/deep-copy": "~1.3",
"php": "^5.6 || ^7.0",
"phpspec/prophecy": "^1.3.1",
"conflict": {
"phpdocumentor/reflection-docblock": "3.0.2"
},
+ "require-dev": {
+ "ext-pdo": "*"
+ },
"suggest": {
+ "ext-tidy": "*",
+ "ext-xdebug": "*",
"phpunit/php-invoker": "~1.1"
},
"bin": [
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "5.4.x-dev"
+ "dev-master": "5.5.x-dev"
}
},
"autoload": {
"testing",
"xunit"
],
- "time": "2016-07-26 14:48:00"
+ "time": "2016-10-03 13:04:15"
},
{
"name": "phpunit/phpunit-mock-objects",
- "version": "3.2.7",
+ "version": "3.3.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
- "reference": "546898a2c0c356ef2891b39dd7d07f5d82c8ed0a"
+ "reference": "03500345483e1e17b52e2e4d34a89c9408ab2902"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/546898a2c0c356ef2891b39dd7d07f5d82c8ed0a",
- "reference": "546898a2c0c356ef2891b39dd7d07f5d82c8ed0a",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/03500345483e1e17b52e2e4d34a89c9408ab2902",
+ "reference": "03500345483e1e17b52e2e4d34a89c9408ab2902",
"shasum": ""
},
"require": {
"mock",
"xunit"
],
- "time": "2016-09-06 16:07:45"
+ "time": "2016-10-04 11:03:26"
},
{
"name": "psr/http-message",
],
"time": "2016-08-06 14:39:51"
},
+ {
+ "name": "psr/log",
+ "version": "1.0.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-fig/log.git",
+ "reference": "5277094ed527a1c4477177d102fe4c53551953e0"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-fig/log/zipball/5277094ed527a1c4477177d102fe4c53551953e0",
+ "reference": "5277094ed527a1c4477177d102fe4c53551953e0",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Psr\\Log\\": "Psr/Log/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
+ }
+ ],
+ "description": "Common interface for logging libraries",
+ "homepage": "https://github.com/php-fig/log",
+ "keywords": [
+ "log",
+ "psr",
+ "psr-3"
+ ],
+ "time": "2016-09-19 16:02:08"
+ },
{
"name": "sebastian/code-unit-reverse-lookup",
"version": "1.0.0",
},
{
"name": "symfony/browser-kit",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/browser-kit.git",
- "reference": "d2a07cc11c5fa94820240b1e67592ffb18e347b9"
+ "reference": "901319a31c9b3cee7857b4aeeb81b5d64dfa34fc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/browser-kit/zipball/d2a07cc11c5fa94820240b1e67592ffb18e347b9",
- "reference": "d2a07cc11c5fa94820240b1e67592ffb18e347b9",
+ "url": "https://api.github.com/repos/symfony/browser-kit/zipball/901319a31c9b3cee7857b4aeeb81b5d64dfa34fc",
+ "reference": "901319a31c9b3cee7857b4aeeb81b5d64dfa34fc",
"shasum": ""
},
"require": {
],
"description": "Symfony BrowserKit Component",
"homepage": "https://symfony.com",
- "time": "2016-07-26 08:04:17"
+ "time": "2016-09-06 11:02:40"
},
{
"name": "symfony/class-loader",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/class-loader.git",
- "reference": "2d0ba77c46ecc96a6641009a98f72632216811ba"
+ "reference": "bcb072aba46ddf3b1a496438c63be6be647739aa"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/class-loader/zipball/2d0ba77c46ecc96a6641009a98f72632216811ba",
- "reference": "2d0ba77c46ecc96a6641009a98f72632216811ba",
+ "url": "https://api.github.com/repos/symfony/class-loader/zipball/bcb072aba46ddf3b1a496438c63be6be647739aa",
+ "reference": "bcb072aba46ddf3b1a496438c63be6be647739aa",
"shasum": ""
},
"require": {
],
"description": "Symfony ClassLoader Component",
"homepage": "https://symfony.com",
- "time": "2016-08-23 13:39:15"
+ "time": "2016-09-06 23:30:54"
},
{
"name": "symfony/config",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/config.git",
- "reference": "431d28df9c7bb6e77f8f6289d8670b044fabb9e8"
+ "reference": "949e7e846743a7f9e46dc50eb639d5fde1f53341"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/config/zipball/431d28df9c7bb6e77f8f6289d8670b044fabb9e8",
- "reference": "431d28df9c7bb6e77f8f6289d8670b044fabb9e8",
+ "url": "https://api.github.com/repos/symfony/config/zipball/949e7e846743a7f9e46dc50eb639d5fde1f53341",
+ "reference": "949e7e846743a7f9e46dc50eb639d5fde1f53341",
"shasum": ""
},
"require": {
],
"description": "Symfony Config Component",
"homepage": "https://symfony.com",
- "time": "2016-08-27 18:50:07"
+ "time": "2016-09-25 08:27:07"
},
{
"name": "symfony/console",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "8ea494c34f0f772c3954b5fbe00bffc5a435e563"
+ "reference": "6cb0872fb57b38b3b09ff213c21ed693956b9eb0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/8ea494c34f0f772c3954b5fbe00bffc5a435e563",
- "reference": "8ea494c34f0f772c3954b5fbe00bffc5a435e563",
+ "url": "https://api.github.com/repos/symfony/console/zipball/6cb0872fb57b38b3b09ff213c21ed693956b9eb0",
+ "reference": "6cb0872fb57b38b3b09ff213c21ed693956b9eb0",
"shasum": ""
},
"require": {
"php": ">=5.5.9",
+ "symfony/debug": "~2.8|~3.0",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
- "time": "2016-08-19 06:48:39"
+ "time": "2016-09-28 00:11:12"
},
{
"name": "symfony/css-selector",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
- "reference": "2851e1932d77ce727776154d659b232d061e816a"
+ "reference": "ca809c64072e0fe61c1c7fb3c76cdc32265042ac"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/css-selector/zipball/2851e1932d77ce727776154d659b232d061e816a",
- "reference": "2851e1932d77ce727776154d659b232d061e816a",
+ "url": "https://api.github.com/repos/symfony/css-selector/zipball/ca809c64072e0fe61c1c7fb3c76cdc32265042ac",
+ "reference": "ca809c64072e0fe61c1c7fb3c76cdc32265042ac",
"shasum": ""
},
"require": {
],
"description": "Symfony CssSelector Component",
"homepage": "https://symfony.com",
- "time": "2016-06-29 05:41:56"
+ "time": "2016-09-06 11:02:40"
+ },
+ {
+ "name": "symfony/debug",
+ "version": "v3.1.5",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/debug.git",
+ "reference": "e2b3f74a67fc928adc3c1b9027f73e1bc01190a8"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/debug/zipball/e2b3f74a67fc928adc3c1b9027f73e1bc01190a8",
+ "reference": "e2b3f74a67fc928adc3c1b9027f73e1bc01190a8",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.9",
+ "psr/log": "~1.0"
+ },
+ "conflict": {
+ "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
+ },
+ "require-dev": {
+ "symfony/class-loader": "~2.8|~3.0",
+ "symfony/http-kernel": "~2.8|~3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.1-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Debug\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Debug Component",
+ "homepage": "https://symfony.com",
+ "time": "2016-09-06 11:02:40"
},
{
"name": "symfony/dependency-injection",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/dependency-injection.git",
- "reference": "6e4f3316afdc9783d7b48a136db89bd791b55698"
+ "reference": "8fa4be9a36f41e49b0c3969678c41c81ed463816"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/6e4f3316afdc9783d7b48a136db89bd791b55698",
- "reference": "6e4f3316afdc9783d7b48a136db89bd791b55698",
+ "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/8fa4be9a36f41e49b0c3969678c41c81ed463816",
+ "reference": "8fa4be9a36f41e49b0c3969678c41c81ed463816",
"shasum": ""
},
"require": {
],
"description": "Symfony DependencyInjection Component",
"homepage": "https://symfony.com",
- "time": "2016-08-23 13:39:15"
+ "time": "2016-09-24 15:56:48"
},
{
"name": "symfony/dom-crawler",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
},
{
"name": "symfony/event-dispatcher",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
},
{
"name": "symfony/filesystem",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
- "reference": "bb29adceb552d202b6416ede373529338136e84f"
+ "reference": "682fd8fdb3135fdf05fc496a01579ccf6c85c0e5"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/filesystem/zipball/bb29adceb552d202b6416ede373529338136e84f",
- "reference": "bb29adceb552d202b6416ede373529338136e84f",
+ "url": "https://api.github.com/repos/symfony/filesystem/zipball/682fd8fdb3135fdf05fc496a01579ccf6c85c0e5",
+ "reference": "682fd8fdb3135fdf05fc496a01579ccf6c85c0e5",
"shasum": ""
},
"require": {
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
- "time": "2016-07-20 05:44:26"
+ "time": "2016-09-14 00:18:46"
},
{
"name": "symfony/polyfill-mbstring",
},
{
"name": "symfony/process",
- "version": "v2.8.11",
+ "version": "v2.8.12",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
- "reference": "05a03ed27073638658cab9405d99a67dd1014987"
+ "reference": "024de37f8a6b9e5e8244d9eb3fcf3e467dd2a93f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/process/zipball/05a03ed27073638658cab9405d99a67dd1014987",
- "reference": "05a03ed27073638658cab9405d99a67dd1014987",
+ "url": "https://api.github.com/repos/symfony/process/zipball/024de37f8a6b9e5e8244d9eb3fcf3e467dd2a93f",
+ "reference": "024de37f8a6b9e5e8244d9eb3fcf3e467dd2a93f",
"shasum": ""
},
"require": {
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
- "time": "2016-09-06 10:55:00"
+ "time": "2016-09-29 14:03:54"
},
{
"name": "symfony/translation",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/translation.git",
- "reference": "a35edc277513c9bc0f063ca174c36b346f974528"
+ "reference": "93013a18d272e59dab8e67f583155b78c68947eb"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/translation/zipball/a35edc277513c9bc0f063ca174c36b346f974528",
- "reference": "a35edc277513c9bc0f063ca174c36b346f974528",
+ "url": "https://api.github.com/repos/symfony/translation/zipball/93013a18d272e59dab8e67f583155b78c68947eb",
+ "reference": "93013a18d272e59dab8e67f583155b78c68947eb",
"shasum": ""
},
"require": {
],
"description": "Symfony Translation Component",
"homepage": "https://symfony.com",
- "time": "2016-08-05 08:37:39"
+ "time": "2016-09-06 11:02:40"
},
{
"name": "symfony/yaml",
- "version": "v3.1.4",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
- "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d"
+ "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/yaml/zipball/f291ed25eb1435bddbe8a96caaef16469c2a092d",
- "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d",
+ "url": "https://api.github.com/repos/symfony/yaml/zipball/368b9738d4033c8b93454cb0dbd45d305135a6d3",
+ "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3",
"shasum": ""
},
"require": {
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
- "time": "2016-09-02 02:12:52"
+ "time": "2016-09-25 08:27:07"
},
{
"name": "webmozart/assert",
*/
public function get_default_blocks() {
global $CFG;
- if (!empty($CFG->defaultblocks)){
+ if (isset($CFG->defaultblocks)) {
return blocks_parse_default_blocks_list($CFG->defaultblocks);
}
$blocknames = array(
return $result;
}
-function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='',
- $modname="", $modid=0, $modaction="", $groupid=0) {
- global $DB, $SESSION, $USER;
- // It is assumed that $date is the GMT time of midnight for that day,
- // and so the next 86400 seconds worth of logs are printed.
-
- /// Setup for group handling.
-
- /// If the group mode is separate, and this user does not have editing privileges,
- /// then only the user's group can be viewed.
- if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', context_course::instance($course->id))) {
- if (isset($SESSION->currentgroup[$course->id])) {
- $groupid = $SESSION->currentgroup[$course->id];
- } else {
- $groupid = groups_get_all_groups($course->id, $USER->id);
- if (is_array($groupid)) {
- $groupid = array_shift(array_keys($groupid));
- $SESSION->currentgroup[$course->id] = $groupid;
- } else {
- $groupid = 0;
- }
- }
- }
- /// If this course doesn't have groups, no groupid can be specified.
- else if (!$course->groupmode) {
- $groupid = 0;
- }
-
- $joins = array();
- $params = array();
-
- if ($course->id != SITEID || $modid != 0) {
- $joins[] = "l.course = :courseid";
- $params['courseid'] = $course->id;
- }
-
- if ($modname) {
- $joins[] = "l.module = :modname";
- $params['modname'] = $modname;
- }
-
- if ('site_errors' === $modid) {
- $joins[] = "( l.action='error' OR l.action='infected' )";
- } else if ($modid) {
- $joins[] = "l.cmid = :modid";
- $params['modid'] = $modid;
- }
-
- if ($modaction) {
- $firstletter = substr($modaction, 0, 1);
- if ($firstletter == '-') {
- $joins[] = $DB->sql_like('l.action', ':modaction', false, true, true);
- $params['modaction'] = '%'.substr($modaction, 1).'%';
- } else {
- $joins[] = $DB->sql_like('l.action', ':modaction', false);
- $params['modaction'] = '%'.$modaction.'%';
- }
- }
-
-
- /// Getting all members of a group.
- if ($groupid and !$user) {
- if ($gusers = groups_get_members($groupid)) {
- $gusers = array_keys($gusers);
- $joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
- } else {
- $joins[] = 'l.userid = 0'; // No users in groups, so we want something that will always be false.
- }
- }
- else if ($user) {
- $joins[] = "l.userid = :userid";
- $params['userid'] = $user;
- }
-
- if ($date) {
- $enddate = $date + 86400;
- $joins[] = "l.time > :date AND l.time < :enddate";
- $params['date'] = $date;
- $params['enddate'] = $enddate;
- }
-
- $selector = implode(' AND ', $joins);
-
- $totalcount = 0; // Initialise
- $result = array();
- $result['logs'] = get_logs($selector, $params, $order, $limitfrom, $limitnum, $totalcount);
- $result['totalcount'] = $totalcount;
- return $result;
-}
-
-
-function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
- $url="", $modname="", $modid=0, $modaction="", $groupid=0) {
-
- global $CFG, $DB, $OUTPUT;
-
- if (!$logs = build_logs_array($course, $user, $date, $order, $page*$perpage, $perpage,
- $modname, $modid, $modaction, $groupid)) {
- echo $OUTPUT->notification("No logs found!");
- echo $OUTPUT->footer();
- exit;
- }
-
- $courses = array();
-
- if ($course->id == SITEID) {
- $courses[0] = '';
- if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
- foreach ($ccc as $cc) {
- $courses[$cc->id] = $cc->shortname;
- }
- }
- } else {
- $courses[$course->id] = $course->shortname;
- }
-
- $totalcount = $logs['totalcount'];
- $count=0;
- $ldcache = array();
- $tt = getdate(time());
- $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
-
- $strftimedatetime = get_string("strftimedatetime");
-
- echo "<div class=\"info\">\n";
- print_string("displayingrecords", "", $totalcount);
- echo "</div>\n";
-
- echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
-
- $table = new html_table();
- $table->classes = array('logtable','generaltable');
- $table->align = array('right', 'left', 'left');
- $table->head = array(
- get_string('time'),
- get_string('ip_address'),
- get_string('fullnameuser'),
- get_string('action'),
- get_string('info')
- );
- $table->data = array();
-
- if ($course->id == SITEID) {
- array_unshift($table->align, 'left');
- array_unshift($table->head, get_string('course'));
- }
-
- // Make sure that the logs array is an array, even it is empty, to avoid warnings from the foreach.
- if (empty($logs['logs'])) {
- $logs['logs'] = array();
- }
-
- foreach ($logs['logs'] as $log) {
-
- if (isset($ldcache[$log->module][$log->action])) {
- $ld = $ldcache[$log->module][$log->action];
- } else {
- $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
- $ldcache[$log->module][$log->action] = $ld;
- }
- if ($ld && is_numeric($log->info)) {
- // ugly hack to make sure fullname is shown correctly
- if ($ld->mtable == 'user' && $ld->field == $DB->sql_concat('firstname', "' '" , 'lastname')) {
- $log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
- } else {
- $log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
- }
- }
-
- //Filter log->info
- $log->info = format_string($log->info);
-
- // If $log->url has been trimmed short by the db size restriction
- // code in add_to_log, keep a note so we don't add a link to a broken url
- $brokenurl=(core_text::strlen($log->url)==100 && core_text::substr($log->url,97)=='...');
-
- $row = array();
- if ($course->id == SITEID) {
- if (empty($log->course)) {
- $row[] = get_string('site');
- } else {
- $row[] = "<a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">". format_string($courses[$log->course])."</a>";
- }
- }
-
- $row[] = userdate($log->time, '%a').' '.userdate($log->time, $strftimedatetime);
-
- $link = new moodle_url("/iplookup/index.php?ip=$log->ip&user=$log->userid");
- $row[] = $OUTPUT->action_link($link, $log->ip, new popup_action('click', $link, 'iplookup', array('height' => 440, 'width' => 700)));
-
- $row[] = html_writer::link(new moodle_url("/user/view.php?id={$log->userid}&course={$log->course}"), fullname($log, has_capability('moodle/site:viewfullnames', context_course::instance($course->id))));
-
- $displayaction="$log->module $log->action";
- if ($brokenurl) {
- $row[] = $displayaction;
- } else {
- $link = make_log_url($log->module,$log->url);
- $row[] = $OUTPUT->action_link($link, $displayaction, new popup_action('click', $link, 'fromloglive'), array('height' => 440, 'width' => 700));
- }
- $row[] = $log->info;
- $table->data[] = $row;
- }
-
- echo html_writer::table($table);
- echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
-}
-
-
-function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
- $url="", $modname="", $modid=0, $modaction="", $groupid=0) {
-
- global $CFG, $DB, $OUTPUT;
-
- if (!$logs = build_mnet_logs_array($hostid, $course, $user, $date, $order, $page*$perpage, $perpage,
- $modname, $modid, $modaction, $groupid)) {
- echo $OUTPUT->notification("No logs found!");
- echo $OUTPUT->footer();
- exit;
- }
-
- if ($course->id == SITEID) {
- $courses[0] = '';
- if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname,c.visible')) {
- foreach ($ccc as $cc) {
- $courses[$cc->id] = $cc->shortname;
- }
- }
- }
-
- $totalcount = $logs['totalcount'];
- $count=0;
- $ldcache = array();
- $tt = getdate(time());
- $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
-
- $strftimedatetime = get_string("strftimedatetime");
-
- echo "<div class=\"info\">\n";
- print_string("displayingrecords", "", $totalcount);
- echo "</div>\n";
-
- echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
-
- echo "<table class=\"logtable\" cellpadding=\"3\" cellspacing=\"0\">\n";
- echo "<tr>";
- if ($course->id == SITEID) {
- echo "<th class=\"c0 header\">".get_string('course')."</th>\n";
- }
- echo "<th class=\"c1 header\">".get_string('time')."</th>\n";
- echo "<th class=\"c2 header\">".get_string('ip_address')."</th>\n";
- echo "<th class=\"c3 header\">".get_string('fullnameuser')."</th>\n";
- echo "<th class=\"c4 header\">".get_string('action')."</th>\n";
- echo "<th class=\"c5 header\">".get_string('info')."</th>\n";
- echo "</tr>\n";
-
- if (empty($logs['logs'])) {
- echo "</table>\n";
- return;
- }
-
- $row = 1;
- foreach ($logs['logs'] as $log) {
-
- $log->info = $log->coursename;
- $row = ($row + 1) % 2;
-
- if (isset($ldcache[$log->module][$log->action])) {
- $ld = $ldcache[$log->module][$log->action];
- } else {
- $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
- $ldcache[$log->module][$log->action] = $ld;
- }
- if (0 && $ld && !empty($log->info)) {
- // ugly hack to make sure fullname is shown correctly
- if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
- $log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
- } else {
- $log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
- }
- }
-
- //Filter log->info
- $log->info = format_string($log->info);
-
- echo '<tr class="r'.$row.'">';
- if ($course->id == SITEID) {
- $courseshortname = format_string($courses[$log->course], true, array('context' => context_course::instance(SITEID)));
- echo "<td class=\"r$row c0\" >\n";
- echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">".$courseshortname."</a>\n";
- echo "</td>\n";
- }
- echo "<td class=\"r$row c1\" align=\"right\">".userdate($log->time, '%a').
- ' '.userdate($log->time, $strftimedatetime)."</td>\n";
- echo "<td class=\"r$row c2\" >\n";
- $link = new moodle_url("/iplookup/index.php?ip=$log->ip&user=$log->userid");
- echo $OUTPUT->action_link($link, $log->ip, new popup_action('click', $link, 'iplookup', array('height' => 400, 'width' => 700)));
- echo "</td>\n";
- $fullname = fullname($log, has_capability('moodle/site:viewfullnames', context_course::instance($course->id)));
- echo "<td class=\"r$row c3\" >\n";
- echo " <a href=\"$CFG->wwwroot/user/view.php?id={$log->userid}\">$fullname</a>\n";
- echo "</td>\n";
- echo "<td class=\"r$row c4\">\n";
- echo $log->action .': '.$log->module;
- echo "</td>\n";
- echo "<td class=\"r$row c5\">{$log->info}</td>\n";
- echo "</tr>\n";
- }
- echo "</table>\n";
-
- echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
-}
-
-
-function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
- $modid, $modaction, $groupid) {
- global $DB, $CFG;
-
- require_once($CFG->libdir . '/csvlib.class.php');
-
- $csvexporter = new csv_export_writer('tab');
-
- $header = array();
- $header[] = get_string('course');
- $header[] = get_string('time');
- $header[] = get_string('ip_address');
- $header[] = get_string('fullnameuser');
- $header[] = get_string('action');
- $header[] = get_string('info');
-
- if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
- $modname, $modid, $modaction, $groupid)) {
- return false;
- }
-
- $courses = array();
-
- if ($course->id == SITEID) {
- $courses[0] = '';
- if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
- foreach ($ccc as $cc) {
- $courses[$cc->id] = $cc->shortname;
- }
- }
- } else {
- $courses[$course->id] = $course->shortname;
- }
-
- $count=0;
- $ldcache = array();
- $tt = getdate(time());
- $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
-
- $strftimedatetime = get_string("strftimedatetime");
-
- $csvexporter->set_filename('logs', '.txt');
- $title = array(get_string('savedat').userdate(time(), $strftimedatetime));
- $csvexporter->add_data($title);
- $csvexporter->add_data($header);
-
- if (empty($logs['logs'])) {
- return true;
- }
-
- foreach ($logs['logs'] as $log) {
- if (isset($ldcache[$log->module][$log->action])) {
- $ld = $ldcache[$log->module][$log->action];
- } else {
- $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
- $ldcache[$log->module][$log->action] = $ld;
- }
- if ($ld && is_numeric($log->info)) {
- // ugly hack to make sure fullname is shown correctly
- if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
- $log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
- } else {
- $log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
- }
- }
-
- //Filter log->info
- $log->info = format_string($log->info);
- $log->info = strip_tags(urldecode($log->info)); // Some XSS protection
-
- $coursecontext = context_course::instance($course->id);
- $firstField = format_string($courses[$log->course], true, array('context' => $coursecontext));
- $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
- $actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);
- $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action.' ('.$actionurl.')', $log->info);
- $csvexporter->add_data($row);
- }
- $csvexporter->download_file();
- return true;
-}
-
-
-function print_log_xls($course, $user, $date, $order='l.time DESC', $modname,
- $modid, $modaction, $groupid) {
-
- global $CFG, $DB;
-
- require_once("$CFG->libdir/excellib.class.php");
-
- if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
- $modname, $modid, $modaction, $groupid)) {
- return false;
- }
-
- $courses = array();
-
- if ($course->id == SITEID) {
- $courses[0] = '';
- if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
- foreach ($ccc as $cc) {
- $courses[$cc->id] = $cc->shortname;
- }
- }
- } else {
- $courses[$course->id] = $course->shortname;
- }
-
- $count=0;
- $ldcache = array();
- $tt = getdate(time());
- $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
-
- $strftimedatetime = get_string("strftimedatetime");
-
- $nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1));
- $filename = 'logs_'.userdate(time(),get_string('backupnameformat', 'langconfig'),99,false);
- $filename .= '.xls';
-
- $workbook = new MoodleExcelWorkbook('-');
- $workbook->send($filename);
-
- $worksheet = array();
- $headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
- get_string('fullnameuser'), get_string('action'), get_string('info'));
-
- // Creating worksheets
- for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
- $sheettitle = get_string('logs').' '.$wsnumber.'-'.$nroPages;
- $worksheet[$wsnumber] = $workbook->add_worksheet($sheettitle);
- $worksheet[$wsnumber]->set_column(1, 1, 30);
- $worksheet[$wsnumber]->write_string(0, 0, get_string('savedat').
- userdate(time(), $strftimedatetime));
- $col = 0;
- foreach ($headers as $item) {
- $worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW-1,$col,$item,'');
- $col++;
- }
- }
-
- if (empty($logs['logs'])) {
- $workbook->close();
- return true;
- }
-
- $formatDate =& $workbook->add_format();
- $formatDate->set_num_format(get_string('log_excel_date_format'));
-
- $row = FIRSTUSEDEXCELROW;
- $wsnumber = 1;
- $myxls =& $worksheet[$wsnumber];
- foreach ($logs['logs'] as $log) {
- if (isset($ldcache[$log->module][$log->action])) {
- $ld = $ldcache[$log->module][$log->action];
- } else {
- $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
- $ldcache[$log->module][$log->action] = $ld;
- }
- if ($ld && is_numeric($log->info)) {
- // ugly hack to make sure fullname is shown correctly
- if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
- $log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
- } else {
- $log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
- }
- }
-
- // Filter log->info
- $log->info = format_string($log->info);
- $log->info = strip_tags(urldecode($log->info)); // Some XSS protection
-
- if ($nroPages>1) {
- if ($row > EXCELROWS) {
- $wsnumber++;
- $myxls =& $worksheet[$wsnumber];
- $row = FIRSTUSEDEXCELROW;
- }
- }
-
- $coursecontext = context_course::instance($course->id);
-
- $myxls->write($row, 0, format_string($courses[$log->course], true, array('context' => $coursecontext)), '');
- $myxls->write_date($row, 1, $log->time, $formatDate); // write_date() does conversion/timezone support. MDL-14934
- $myxls->write($row, 2, $log->ip, '');
- $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
- $myxls->write($row, 3, $fullname, '');
- $actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);
- $myxls->write($row, 4, $log->module.' '.$log->action.' ('.$actionurl.')', '');
- $myxls->write($row, 5, $log->info, '');
-
- $row++;
- }
-
- $workbook->close();
- return true;
-}
-
-function print_log_ods($course, $user, $date, $order='l.time DESC', $modname,
- $modid, $modaction, $groupid) {
-
- global $CFG, $DB;
-
- require_once("$CFG->libdir/odslib.class.php");
-
- if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
- $modname, $modid, $modaction, $groupid)) {
- return false;
- }
-
- $courses = array();
-
- if ($course->id == SITEID) {
- $courses[0] = '';
- if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
- foreach ($ccc as $cc) {
- $courses[$cc->id] = $cc->shortname;
- }
- }
- } else {
- $courses[$course->id] = $course->shortname;
- }
-
- $count=0;
- $ldcache = array();
- $tt = getdate(time());
- $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
-
- $strftimedatetime = get_string("strftimedatetime");
-
- $nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1));
- $filename = 'logs_'.userdate(time(),get_string('backupnameformat', 'langconfig'),99,false);
- $filename .= '.ods';
-
- $workbook = new MoodleODSWorkbook('-');
- $workbook->send($filename);
-
- $worksheet = array();
- $headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
- get_string('fullnameuser'), get_string('action'), get_string('info'));
-
- // Creating worksheets
- for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
- $sheettitle = get_string('logs').' '.$wsnumber.'-'.$nroPages;
- $worksheet[$wsnumber] = $workbook->add_worksheet($sheettitle);
- $worksheet[$wsnumber]->set_column(1, 1, 30);
- $worksheet[$wsnumber]->write_string(0, 0, get_string('savedat').
- userdate(time(), $strftimedatetime));
- $col = 0;
- foreach ($headers as $item) {
- $worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW-1,$col,$item,'');
- $col++;
- }
- }
-
- if (empty($logs['logs'])) {
- $workbook->close();
- return true;
- }
-
- $formatDate =& $workbook->add_format();
- $formatDate->set_num_format(get_string('log_excel_date_format'));
-
- $row = FIRSTUSEDEXCELROW;
- $wsnumber = 1;
- $myxls =& $worksheet[$wsnumber];
- foreach ($logs['logs'] as $log) {
- if (isset($ldcache[$log->module][$log->action])) {
- $ld = $ldcache[$log->module][$log->action];
- } else {
- $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
- $ldcache[$log->module][$log->action] = $ld;
- }
- if ($ld && is_numeric($log->info)) {
- // ugly hack to make sure fullname is shown correctly
- if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
- $log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
- } else {
- $log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
- }
- }
-
- // Filter log->info
- $log->info = format_string($log->info);
- $log->info = strip_tags(urldecode($log->info)); // Some XSS protection
-
- if ($nroPages>1) {
- if ($row > EXCELROWS) {
- $wsnumber++;
- $myxls =& $worksheet[$wsnumber];
- $row = FIRSTUSEDEXCELROW;
- }
- }
-
- $coursecontext = context_course::instance($course->id);
-
- $myxls->write_string($row, 0, format_string($courses[$log->course], true, array('context' => $coursecontext)));
- $myxls->write_date($row, 1, $log->time);
- $myxls->write_string($row, 2, $log->ip);
- $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
- $myxls->write_string($row, 3, $fullname);
- $actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);
- $myxls->write_string($row, 4, $log->module.' '.$log->action.' ('.$actionurl.')');
- $myxls->write_string($row, 5, $log->info);
-
- $row++;
- }
-
- $workbook->close();
- return true;
-}
-
/**
* Checks the integrity of the course data.
*
And I go to the courses management page
And I should see "Course and category management" in the "h2" "css_element"
And I should see "Course categories" in the ".view-mode-selector" "css_element"
- And I should see "Course categories" in the "h3" "css_element"
+ And I should see "Course categories" in the "#page-content" "css_element"
And I should see the "Course categories and courses" management page
@javascript
break;
case 'getassignable':
$otheruserroles = optional_param('otherusers', false, PARAM_BOOL);
- $outcome->response = array_reverse($manager->get_assignable_roles($otheruserroles), true);
+ $outcome->response = $manager->get_assignable_roles_for_json($otheruserroles);
break;
case 'searchotherusers':
$search = optional_param('search', '', PARAM_RAW);
}
}
+ /**
+ * Gets all of the assignable roles for this course, wrapped in an array to ensure
+ * role sort order is not lost during json deserialisation.
+ *
+ * @param boolean $otherusers whether to include the assignable roles for other users
+ * @return array
+ */
+ public function get_assignable_roles_for_json($otherusers = false) {
+ $rolesarray = array();
+ $assignable = $this->get_assignable_roles($otherusers);
+ foreach ($assignable as $id => $role) {
+ $rolesarray[] = array('id' => $id, 'name' => $role);
+ }
+ return $rolesarray;
+ }
+
/**
* Gets all of the groups for this course.
*
var index = 0, count = 0;
for (var i in roles) {
count++;
- var option = create('<option value="'+i+'">'+roles[i]+'</option>');
- if (i == v) {
+ var option = create('<option value="' + roles[i].id + '">' + roles[i].name + '</option>');
+ if (roles[i].id == v) {
index = count;
}
s.append(option);
)
.append(Y.Node.create('<div class="'+CSS.OPTIONS+'"><span class="label">'+M.util.get_string('assignrole', 'role')+': </span></div>'))
);
- var id = 0, roles = this._manager.get(ASSIGNABLEROLES);
- for (id in roles) {
- var role = Y.Node.create('<a href="#" class="'+CSS.ROLEOPTION+'">'+roles[id]+'</a>');
- role.on('click', this.assignRoleToUser, this, id, role);
+ var roles = this._manager.get(ASSIGNABLEROLES);
+ for (var i in roles) {
+ var role = Y.Node.create('<a href="#" class="' + CSS.ROLEOPTION + '">' + roles[i].name + '</a>');
+ role.on('click', this.assignRoleToUser, this, roles[i].id, role);
this._node.one('.'+CSS.OPTIONS).append(role);
}
return this._node;
if (o.error) {
new M.core.ajaxException(o);
} else {
- this.users[userid].addRoleToDisplay(args.roleid, this.get(ASSIGNABLEROLES)[args.roleid]);
+ this.users[userid].addRoleToDisplay(args.roleid, this._getAssignableRole(args.roleid));
}
} catch (e) {
new M.core.exception(e);
}
});
},
+ _getAssignableRole: function(roleid) {
+ var roles = this.get(ASSIGNABLEROLES);
+ for (var i in roles) {
+ if (roles[i].id == roleid) {
+ return roles[i].name;
+ }
+ }
+ return null;
+ },
_loadAssignableRoles : function() {
var c = this.get(COURSEID), params = {
id : this.get(COURSEID),
var current = this.get(CURRENTROLES);
var allroles = true, i = 0;
for (i in roles) {
- if (!current[i]) {
+ if (!current[roles[i].id]) {
allroles = false;
break;
}
var content = element.one('.content');
var roles = m.get(ASSIGNABLEROLES);
for (i in roles) {
- var button = Y.Node.create('<input type="button" value="'+roles[i]+'" id="add_assignable_role_'+i+'" />');
- button.on('click', this.submit, this, i);
+ var buttonid = 'add_assignable_role_' + roles[i].id;
+ var buttonhtml = '<input type="button" value="' + roles[i].name + '" id="' + buttonid + '" />';
+ var button = Y.Node.create(buttonhtml);
+ button.on('click', this.submit, this, roles[i].id);
content.append(button);
}
Y.one(document.body).append(element);
$outcome_rec->courseid = $courseid;
require_login();
require_capability('moodle/grade:manage', $systemcontext);
+ $PAGE->set_context($systemcontext);
}
} else if ($courseid){
} else {
require_login();
require_capability('moodle/grade:manage', $systemcontext);
+ $PAGE->set_context($systemcontext);
/// adding new outcome from admin section
$outcome_rec = new stdClass();
--- /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/>.
+
+/**
+ * External grade report overview API
+ *
+ * @package gradereport_overview
+ * @copyright 2016 Juan Leyva <juan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+require_once($CFG->libdir . '/externallib.php');
+require_once($CFG->libdir . '/gradelib.php');
+require_once($CFG->dirroot . '/grade/lib.php');
+require_once($CFG->dirroot . '/grade/report/overview/lib.php');
+
+/**
+ * External grade overview report API implementation
+ *
+ * @package gradereport_overview
+ * @copyright 2016 Juan Leyva <juan@moodle.com>
+ * @category external
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class gradereport_overview_external extends external_api {
+
+ /**
+ * Describes the parameters for get_course_grades.
+ *
+ * @return external_external_function_parameters
+ * @since Moodle 3.2
+ */
+ public static function get_course_grades_parameters() {
+ return new external_function_parameters (
+ array(
+ 'userid' => new external_value(PARAM_INT, 'Get grades for this user (optional, default current)', VALUE_DEFAULT, 0)
+ )
+ );
+ }
+
+ /**
+ * Get the given user courses final grades
+ *
+ * @param int $userid get grades for this user (optional, default current)
+ *
+ * @return array the grades tables
+ * @since Moodle 3.2
+ */
+ public static function get_course_grades($userid = 0) {
+ global $USER;
+
+ $warnings = array();
+
+ // Validate the parameter.
+ $params = self::validate_parameters(self::get_course_grades_parameters(),
+ array(
+ 'userid' => $userid
+ )
+ );
+
+ $userid = $params['userid'];
+ if (empty($userid)) {
+ $userid = $USER->id;
+ }
+
+ $systemcontext = context_system::instance();
+ self::validate_context($systemcontext);
+
+ if ($USER->id != $userid) {
+ // We must check if the current user can view other users grades.
+ $user = core_user::get_user($userid, '*', MUST_EXIST);
+ core_user::require_active_user($user);
+ require_capability('moodle/grade:viewall', $systemcontext);
+ }
+
+ // We need the site course, and course context.
+ $course = get_course(SITEID);
+ $context = context_course::instance($course->id);
+
+ // Force a regrade if required.
+ grade_regrade_final_grades_if_required($course);
+ // Get the course final grades now.
+ $gpr = new grade_plugin_return(array('type' => 'report', 'plugin' => 'overview', 'courseid' => $course->id,
+ 'userid' => $userid));
+ $report = new grade_report_overview($userid, $gpr, $context);
+ $coursesgrades = $report->setup_courses_data(true);
+
+ $grades = array();
+ foreach ($coursesgrades as $coursegrade) {
+ $gradeinfo = array(
+ 'courseid' => $coursegrade['course']->id,
+ 'grade' => grade_format_gradevalue($coursegrade['finalgrade'], $coursegrade['courseitem'], true),
+ 'rawgrade' => $coursegrade['finalgrade'],
+ );
+ if (isset($coursegrade['rank'])) {
+ $gradeinfo['rank'] = $coursegrade['rank'];
+ }
+ $grades[] = $gradeinfo;
+ }
+
+ $result = array();
+ $result['grades'] = $grades;
+ $result['warnings'] = $warnings;
+ return $result;
+ }
+
+ /**
+ * Describes the get_course_grades return value.
+ *
+ * @return external_single_structure
+ * @since Moodle 3.2
+ */
+ public static function get_course_grades_returns() {
+ return new external_single_structure(
+ array(
+ 'grades' => new external_multiple_structure(
+ new external_single_structure(
+ array(
+ 'courseid' => new external_value(PARAM_INT, 'Course id'),
+ 'grade' => new external_value(PARAM_RAW, 'Grade formatted'),
+ 'rawgrade' => new external_value(PARAM_RAW, 'Raw grade, not formatted'),
+ 'rank' => new external_value(PARAM_INT, 'Your rank in the course', VALUE_OPTIONAL),
+ )
+ )
+ ),
+ 'warnings' => new external_warnings()
+ )
+ );
+ }
+
+ /**
+ * Returns description of method parameters
+ *
+ * @return external_function_parameters
+ * @since Moodle 3.2
+ */
+ public static function view_grade_report_parameters() {
+ return new external_function_parameters(
+ array(
+ 'courseid' => new external_value(PARAM_INT, 'id of the course'),
+ 'userid' => new external_value(PARAM_INT, 'id of the user, 0 means current user', VALUE_DEFAULT, 0)
+ )
+ );
+ }
+
+ /**
+ * Trigger the user report events, do the same that the web interface view of the report
+ *
+ * @param int $courseid id of course
+ * @param int $userid id of the user the report belongs to
+ * @return array of warnings and status result
+ * @since Moodle 3.2
+ * @throws moodle_exception
+ */
+ public static function view_grade_report($courseid, $userid = 0) {
+ global $USER;
+
+ $params = self::validate_parameters(self::view_grade_report_parameters(),
+ array(
+ 'courseid' => $courseid,
+ 'userid' => $userid
+ )
+ );
+
+ $warnings = array();
+ $course = get_course($params['courseid']);
+
+ $context = context_course::instance($course->id);
+ self::validate_context($context);
+
+ $userid = $params['userid'];
+ if (empty($userid)) {
+ $userid = $USER->id;
+ } else {
+ $user = core_user::get_user($userid, '*', MUST_EXIST);
+ core_user::require_active_user($user);
+ }
+ $systemcontext = context_system::instance();
+ $personalcontext = context_user::instance($userid);
+
+ $access = grade_report_overview::check_access($systemcontext, $context, $personalcontext, $course, $userid);
+
+ if (!$access) {
+ throw new moodle_exception('nopermissiontoviewgrades', 'error');
+ }
+
+ grade_report_overview::viewed($context, $course->id, $userid);
+
+ $result = array();
+ $result['status'] = true;
+ $result['warnings'] = $warnings;
+ return $result;
+ }
+
+ /**
+ * Returns description of method result value
+ *
+ * @return external_description
+ * @since Moodle 3.2
+ */
+ public static function view_grade_report_returns() {
+ return new external_single_structure(
+ array(
+ 'status' => new external_value(PARAM_BOOL, 'status: true if success'),
+ 'warnings' => new external_warnings()
+ )
+ );
+ }
+}
--- /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/>.
+
+/**
+ * Overview grade report external functions and service definitions.
+ *
+ * @package gradereport_overview
+ * @copyright 2016 Juan Leyva <juan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$functions = array(
+
+ 'gradereport_overview_get_course_grades' => array(
+ 'classname' => 'gradereport_overview_external',
+ 'methodname' => 'get_course_grades',
+ 'description' => 'Get the given user courses final grades',
+ 'type' => 'read',
+ 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
+ ),
+ 'gradereport_overview_view_grade_report' => array(
+ 'classname' => 'gradereport_overview_external',
+ 'methodname' => 'view_grade_report',
+ 'description' => 'Trigger the report view event',
+ 'type' => 'write',
+ 'capabilities' => 'gradereport/overview:view',
+ 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
+ )
+);
$PAGE->navigation->extend_for_user($user);
}
-$access = false;
-if (has_capability('moodle/grade:viewall', $systemcontext)) {
- // Ok - can view all course grades.
- $access = true;
-
-} else if (has_capability('moodle/grade:viewall', $context)) {
- // Ok - can view any grades in context.
- $access = true;
-
-} else if ($userid == $USER->id and ((has_capability('moodle/grade:view', $context) and $course->showgrades)
- || $courseid == SITEID)) {
- // Ok - can view own course grades.
- $access = true;
-
-} else if (has_capability('moodle/grade:viewall', $personalcontext) and $course->showgrades) {
- // Ok - can view grades of this user - parent most probably.
- $access = true;
-} else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and $course->showgrades) {
- // Ok - can view grades of this user - parent most probably.
- $access = true;
-}
+$access = grade_report_overview::check_access($systemcontext, $context, $personalcontext, $course, $userid);
if (!$access) {
// no access to grades!
}
}
-$event = \gradereport_overview\event\grade_report_viewed::create(
- array(
- 'context' => $context,
- 'courseid' => $courseid,
- 'relateduserid' => $userid,
- )
-);
-$event->trigger();
+grade_report_overview::viewed($context, $courseid, $userid);
echo $OUTPUT->footer();
-
-
$this->table->setup();
}
+ /**
+ * Set up the courses grades data for the report.
+ *
+ * @param bool $studentcoursesonly Only show courses that the user is a student of.
+ * @return array of course grades information
+ */
+ public function setup_courses_data($studentcoursesonly) {
+ global $USER, $DB;
+
+ $coursesdata = array();
+ $numusers = $this->get_numusers(false);
+
+ foreach ($this->courses as $course) {
+ if (!$course->showgrades) {
+ continue;
+ }
+
+ // If we are only showing student courses and this course isn't part of the group, then move on.
+ if ($studentcoursesonly && !isset($this->studentcourseids[$course->id])) {
+ continue;
+ }
+
+ $coursecontext = context_course::instance($course->id);
+
+ if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
+ // The course is hidden and the user isn't allowed to see it.
+ continue;
+ }
+
+ if (!has_capability('moodle/user:viewuseractivitiesreport', context_user::instance($this->user->id)) &&
+ ((!has_capability('moodle/grade:view', $coursecontext) || $this->user->id != $USER->id) &&
+ !has_capability('moodle/grade:viewall', $coursecontext))) {
+ continue;
+ }
+
+ $coursesdata[$course->id]['course'] = $course;
+ $coursesdata[$course->id]['context'] = $coursecontext;
+
+ $canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext);
+
+ // Get course grade_item.
+ $courseitem = grade_item::fetch_course_item($course->id);
+
+ // Get the stored grade.
+ $coursegrade = new grade_grade(array('itemid' => $courseitem->id, 'userid' => $this->user->id));
+ $coursegrade->grade_item =& $courseitem;
+ $finalgrade = $coursegrade->finalgrade;
+
+ if (!$canviewhidden and !is_null($finalgrade)) {
+ if ($coursegrade->is_hidden()) {
+ $finalgrade = null;
+ } else {
+ $adjustedgrade = $this->blank_hidden_total_and_adjust_bounds($course->id,
+ $courseitem,
+ $finalgrade);
+
+ // We temporarily adjust the view of this grade item - because the min and
+ // max are affected by the hidden values in the aggregation.
+ $finalgrade = $adjustedgrade['grade'];
+ $courseitem->grademax = $adjustedgrade['grademax'];
+ $courseitem->grademin = $adjustedgrade['grademin'];
+ }
+ } else {
+ // We must use the specific max/min because it can be different for
+ // each grade_grade when items are excluded from sum of grades.
+ if (!is_null($finalgrade)) {
+ $courseitem->grademin = $coursegrade->get_grade_min();
+ $courseitem->grademax = $coursegrade->get_grade_max();
+ }
+ }
+
+ $coursesdata[$course->id]['finalgrade'] = $finalgrade;
+ $coursesdata[$course->id]['courseitem'] = $courseitem;
+
+ if ($this->showrank['any'] && $this->showrank[$course->id] && !is_null($finalgrade)) {
+ // Find the number of users with a higher grade.
+ // Please note this can not work if hidden grades involved :-( to be fixed in 2.0.
+ $params = array($finalgrade, $courseitem->id);
+ $sql = "SELECT COUNT(DISTINCT(userid))
+ FROM {grade_grades}
+ WHERE finalgrade IS NOT NULL AND finalgrade > ?
+ AND itemid = ?";
+ $rank = $DB->count_records_sql($sql, $params) + 1;
+
+ $coursesdata[$course->id]['rank'] = $rank;
+ $coursesdata[$course->id]['numusers'] = $numusers;
+ }
+ }
+ return $coursesdata;
+ }
+
/**
* Fill the table for displaying.
*
// Only show user's courses instead of all courses.
if ($this->courses) {
- $numusers = $this->get_numusers(false);
-
- foreach ($this->courses as $course) {
- if (!$course->showgrades) {
- continue;
- }
-
- // If we are only showing student courses and this course isn't part of the group, then move on.
- if ($studentcoursesonly && !isset($this->studentcourseids[$course->id])) {
- continue;
- }
-
- $coursecontext = context_course::instance($course->id);
+ $coursesdata = $this->setup_courses_data($studentcoursesonly);
- if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
- // The course is hidden and the user isn't allowed to see it
- continue;
- }
+ foreach ($coursesdata as $coursedata) {
- if (!has_capability('moodle/user:viewuseractivitiesreport', context_user::instance($this->user->id)) &&
- ((!has_capability('moodle/grade:view', $coursecontext) || $this->user->id != $USER->id) &&
- !has_capability('moodle/grade:viewall', $coursecontext))) {
- continue;
- }
+ $course = $coursedata['course'];
+ $coursecontext = $coursedata['context'];
+ $finalgrade = $coursedata['finalgrade'];
+ $courseitem = $coursedata['courseitem'];
$coursename = format_string(get_course_display_name_for_list($course), true, array('context' => $coursecontext));
// Link to the activity report version of the user grade report.
$courselink = html_writer::link(new moodle_url('/grade/report/user/index.php', array('id' => $course->id,
'userid' => $this->user->id)), $coursename);
}
- $canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext);
-
- // Get course grade_item
- $course_item = grade_item::fetch_course_item($course->id);
- // Get the stored grade
- $course_grade = new grade_grade(array('itemid'=>$course_item->id, 'userid'=>$this->user->id));
- $course_grade->grade_item =& $course_item;
- $finalgrade = $course_grade->finalgrade;
+ $data = array($courselink, grade_format_gradevalue($finalgrade, $courseitem, true));
- if (!$canviewhidden and !is_null($finalgrade)) {
- if ($course_grade->is_hidden()) {
- $finalgrade = null;
+ if ($this->showrank['any']) {
+ if ($this->showrank[$course->id] && !is_null($finalgrade)) {
+ $rank = $coursedata['rank'];
+ $numusers = $coursedata['numusers'];
+ $data[] = "$rank/$numusers";
} else {
- $adjustedgrade = $this->blank_hidden_total_and_adjust_bounds($course->id,
- $course_item,
- $finalgrade);
-
- // We temporarily adjust the view of this grade item - because the min and
- // max are affected by the hidden values in the aggregation.
- $finalgrade = $adjustedgrade['grade'];
- $course_item->grademax = $adjustedgrade['grademax'];
- $course_item->grademin = $adjustedgrade['grademin'];
+ // No grade, no rank.
+ // Or this course wants rank hidden.
+ $data[] = '-';
}
- } else {
- // We must use the specific max/min because it can be different for
- // each grade_grade when items are excluded from sum of grades.
- if (!is_null($finalgrade)) {
- $course_item->grademin = $course_grade->get_grade_min();
- $course_item->grademax = $course_grade->get_grade_max();
- }
- }
-
- $data = array($courselink, grade_format_gradevalue($finalgrade, $course_item, true));
-
- if (!$this->showrank['any']) {
- //nothing to do
-
- } else if ($this->showrank[$course->id] && !is_null($finalgrade)) {
- /// find the number of users with a higher grade
- /// please note this can not work if hidden grades involved :-( to be fixed in 2.0
- $params = array($finalgrade, $course_item->id);
- $sql = "SELECT COUNT(DISTINCT(userid))
- FROM {grade_grades}
- WHERE finalgrade IS NOT NULL AND finalgrade > ?
- AND itemid = ?";
- $rank = $DB->count_records_sql($sql, $params) + 1;
-
- $data[] = "$rank/$numusers";
-
- } else {
- // No grade, no rank.
- // Or this course wants rank hidden.
- $data[] = '-';
}
$this->table->add_data($data);
}
- return true;
+ return true;
} else {
echo $OUTPUT->notification(get_string('notenrolled', 'grades'), 'notifymessage');
return false;
public static function supports_mygrades() {
return true;
}
+
+ /**
+ * Check if the user can access the report.
+ *
+ * @param stdClass $systemcontext system context
+ * @param stdClass $context course context
+ * @param stdClass $personalcontext personal context
+ * @param stdClass $course course object
+ * @param int $userid userid
+ * @return bool true if the user can access the report
+ * @since Moodle 3.2
+ */
+ public static function check_access($systemcontext, $context, $personalcontext, $course, $userid) {
+ global $USER;
+
+ $access = false;
+ if (has_capability('moodle/grade:viewall', $systemcontext)) {
+ // Ok - can view all course grades.
+ $access = true;
+
+ } else if (has_capability('moodle/grade:viewall', $context)) {
+ // Ok - can view any grades in context.
+ $access = true;
+
+ } else if ($userid == $USER->id and ((has_capability('moodle/grade:view', $context) and $course->showgrades)
+ || $course->id == SITEID)) {
+ // Ok - can view own course grades.
+ $access = true;
+
+ } else if (has_capability('moodle/grade:viewall', $personalcontext) and $course->showgrades) {
+ // Ok - can view grades of this user - parent most probably.
+ $access = true;
+ } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and $course->showgrades) {
+ // Ok - can view grades of this user - parent most probably.
+ $access = true;
+ }
+ return $access;
+ }
+
+ /**
+ * Trigger the grade_report_viewed event
+ *
+ * @param stdClass $context course context
+ * @param int $courseid course id
+ * @param int $userid user id
+ * @since Moodle 3.2
+ */
+ public static function viewed($context, $courseid, $userid) {
+ $event = \gradereport_overview\event\grade_report_viewed::create(
+ array(
+ 'context' => $context,
+ 'courseid' => $courseid,
+ 'relateduserid' => $userid,
+ )
+ );
+ $event->trigger();
+ }
}
function grade_report_overview_settings_definition(&$mform) {
--- /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/>.
+
+/**
+ * Overview grade report functions unit tests
+ *
+ * @package gradereport_overview
+ * @category external
+ * @copyright 2015 Juan Leyva <juan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+
+require_once($CFG->dirroot . '/webservice/tests/helpers.php');
+
+/**
+ * Overview grade report functions unit tests
+ *
+ * @package gradereport_overview
+ * @category external
+ * @copyright 2015 Juan Leyva <juan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class gradereport_overview_externallib_testcase extends externallib_advanced_testcase {
+
+ /**
+ * Set up for every test
+ */
+ public function setUp() {
+ global $DB;
+ $this->resetAfterTest(true);
+
+ $s1grade1 = 80;
+ $s1grade2 = 40;
+ $s2grade = 60;
+
+ $this->course1 = $this->getDataGenerator()->create_course();
+ $this->course2 = $this->getDataGenerator()->create_course();
+
+ $studentrole = $DB->get_record('role', array('shortname' => 'student'));
+ $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
+ $this->student1 = $this->getDataGenerator()->create_user();
+ $this->teacher = $this->getDataGenerator()->create_user();
+ $this->getDataGenerator()->enrol_user($this->teacher->id, $this->course1->id, $teacherrole->id);
+ $this->getDataGenerator()->enrol_user($this->student1->id, $this->course1->id, $studentrole->id);
+ $this->getDataGenerator()->enrol_user($this->student1->id, $this->course2->id, $studentrole->id);
+
+ $this->student2 = $this->getDataGenerator()->create_user();
+ $this->getDataGenerator()->enrol_user($this->student2->id, $this->course1->id, $studentrole->id);
+ $this->getDataGenerator()->enrol_user($this->student2->id, $this->course2->id, $studentrole->id);
+
+ $assignment1 = $this->getDataGenerator()->create_module('assign', array('name' => "Test assign", 'course' => $this->course1->id));
+ $assignment2 = $this->getDataGenerator()->create_module('assign', array('name' => "Test assign", 'course' => $this->course2->id));
+ $modcontext1 = get_coursemodule_from_instance('assign', $assignment1->id, $this->course1->id);
+ $modcontext2 = get_coursemodule_from_instance('assign', $assignment2->id, $this->course2->id);
+ $assignment1->cmidnumber = $modcontext1->id;
+ $assignment2->cmidnumber = $modcontext2->id;
+
+ $this->student1grade1 = array('userid' => $this->student1->id, 'rawgrade' => $s1grade1);
+ $this->student1grade2 = array('userid' => $this->student1->id, 'rawgrade' => $s1grade2);
+ $this->student2grade = array('userid' => $this->student2->id, 'rawgrade' => $s2grade);
+ $studentgrades = array($this->student1->id => $this->student1grade1, $this->student2->id => $this->student2grade);
+ assign_grade_item_update($assignment1, $studentgrades);
+ $studentgrades = array($this->student1->id => $this->student1grade2);
+ assign_grade_item_update($assignment2, $studentgrades);
+
+ grade_get_setting($this->course1->id, 'report_overview_showrank', 1);
+ }
+
+ /**
+ * Test get_course_grades function case student
+ */
+ public function test_get_course_grades_student() {
+
+ // A user can see his own grades in both courses.
+ $this->setUser($this->student1);
+ $studentgrades = gradereport_overview_external::get_course_grades();
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+
+ $this->assertCount(0, $studentgrades['warnings']);
+ $this->assertCount(2, $studentgrades['grades']);
+ foreach ($studentgrades['grades'] as $grade) {
+ if ($grade['courseid'] == $this->course1->id) {
+ $this->assertEquals(80.00, $grade['grade']);
+ $this->assertEquals(80.0000, $grade['rawgrade']);
+ $this->assertEquals(1, $grade['rank']);
+ } else {
+ $this->assertEquals(40.00, $grade['grade']);
+ $this->assertEquals(40.0000, $grade['rawgrade']);
+ $this->assertArrayNotHasKey('rank', $grade);
+ }
+ }
+
+ // Second student, no grade in one course.
+ $this->setUser($this->student2);
+ $studentgrades = gradereport_overview_external::get_course_grades();
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+
+ $this->assertCount(0, $studentgrades['warnings']);
+ $this->assertCount(2, $studentgrades['grades']);
+ foreach ($studentgrades['grades'] as $grade) {
+ if ($grade['courseid'] == $this->course1->id) {
+ $this->assertEquals(60.00, $grade['grade']);
+ $this->assertEquals(60.0000, $grade['rawgrade']);
+ $this->assertEquals(2, $grade['rank']);
+ } else {
+ $this->assertEquals('-', $grade['grade']);
+ $this->assertEmpty($grade['rawgrade']);
+ $this->assertArrayNotHasKey('rank', $grade);
+ }
+ }
+ }
+
+ /**
+ * Test get_course_grades function case admin
+ */
+ public function test_get_course_grades_admin() {
+
+ // A admin must see all student grades.
+ $this->setAdminUser();
+
+ $studentgrades = gradereport_overview_external::get_course_grades($this->student1->id);
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $this->assertCount(0, $studentgrades['warnings']);
+ $this->assertCount(2, $studentgrades['grades']);
+ foreach ($studentgrades['grades'] as $grade) {
+ if ($grade['courseid'] == $this->course1->id) {
+ $this->assertEquals(80.00, $grade['grade']);
+ $this->assertEquals(80.0000, $grade['rawgrade']);
+ } else {
+ $this->assertEquals(40.00, $grade['grade']);
+ $this->assertEquals(40.0000, $grade['rawgrade']);
+ }
+ }
+
+ $studentgrades = gradereport_overview_external::get_course_grades($this->student2->id);
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $this->assertCount(0, $studentgrades['warnings']);
+ $this->assertCount(2, $studentgrades['grades']);
+
+ // Admins don't see grades.
+ $studentgrades = gradereport_overview_external::get_course_grades();
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $this->assertCount(0, $studentgrades['warnings']);
+ $this->assertCount(0, $studentgrades['grades']);
+ }
+
+ /**
+ * Test get_course_grades function case teacher
+ */
+ public function test_get_course_grades_teacher() {
+ // Teachers don't see grades.
+ $this->setUser($this->teacher);
+
+ $studentgrades = gradereport_overview_external::get_course_grades();
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $this->assertCount(0, $studentgrades['warnings']);
+ $this->assertCount(0, $studentgrades['grades']);
+ }
+
+ /**
+ * Test get_course_grades function case incorrect permissions
+ */
+ public function test_get_course_grades_permissions() {
+ // Student can't see other student grades.
+ $this->setUser($this->student2);
+
+ $this->expectException('required_capability_exception');
+ $studentgrade = gradereport_overview_external::get_course_grades($this->student1->id);
+ }
+
+ /**
+ * Test view_grade_report function
+ */
+ public function test_view_grade_report() {
+ global $USER;
+
+ // Redirect events to the sink, so we can recover them later.
+ $sink = $this->redirectEvents();
+
+ $this->setUser($this->student1);
+ $result = gradereport_overview_external::view_grade_report($this->course1->id);
+ $result = external_api::clean_returnvalue(gradereport_overview_external::view_grade_report_returns(), $result);
+ $events = $sink->get_events();
+ $this->assertCount(1, $events);
+ $event = reset($events);
+
+ // Check the event details are correct.
+ $this->assertInstanceOf('\gradereport_overview\event\grade_report_viewed', $event);
+ $this->assertEquals(context_course::instance($this->course1->id), $event->get_context());
+ $this->assertEquals($USER->id, $event->get_data()['relateduserid']);
+
+ $this->setUser($this->teacher);
+ $result = gradereport_overview_external::view_grade_report($this->course1->id, $this->student1->id);
+ $result = external_api::clean_returnvalue(gradereport_overview_external::view_grade_report_returns(), $result);
+ $events = $sink->get_events();
+ $event = reset($events);
+ $sink->close();
+
+ // Check the event details are correct.
+ $this->assertInstanceOf('\gradereport_overview\event\grade_report_viewed', $event);
+ $this->assertEquals(context_course::instance($this->course1->id), $event->get_context());
+ $this->assertEquals($this->student1->id, $event->get_data()['relateduserid']);
+ }
+
+ /**
+ * Test view_grade_report_permissions function
+ */
+ public function test_view_grade_report_permissions() {
+ $this->setUser($this->student2);
+
+ $this->expectException('moodle_exception');
+ $studentgrade = gradereport_overview_external::view_grade_report($this->course1->id, $this->student1->id);
+ }
+}
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2016052300; // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version = 2016052301; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2016051900; // Requires this Moodle version
$plugin->component = 'gradereport_overview'; // Full name of the plugin (used for diagnostics)
$courseid = required_param('id', PARAM_INT);
$userid = optional_param('userid', $USER->id, PARAM_INT);
+$userview = optional_param('userview', 0, PARAM_INT);
$PAGE->set_url(new moodle_url('/grade/report/user/index.php', array('id'=>$courseid)));
+if ($userview == 0) {
+ $userview = get_user_preferences('gradereport_user_view_user', GRADE_REPORT_USER_VIEW_USER);
+} else {
+ set_user_preference('gradereport_user_view_user', $userview);
+}
+
/// basic access checks
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
+
+ $renderer = $PAGE->get_renderer('gradereport_user');
+
+ if ($userview == GRADE_REPORT_USER_VIEW_USER) {
+ $viewasuser = true;
+ } else {
+ $viewasuser = false;
+ }
+
if (empty($userid)) {
$gui = new graded_users_iterator($course, null, $currentgroup);
$gui->require_active_enrolment($showonlyactiveenrol);
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
if ($user_selector) {
- $renderer = $PAGE->get_renderer('gradereport_user');
echo $renderer->graded_users_selector('user', $course, $userid, $currentgroup, true);
}
+ echo $renderer->view_user_selector($userid, $userview);
+
while ($userdata = $gui->next_user()) {
$user = $userdata->user;
- $report = new grade_report_user($courseid, $gpr, $context, $user->id);
+ $report = new grade_report_user($courseid, $gpr, $context, $user->id, $viewasuser);
$studentnamelink = html_writer::link(new moodle_url('/user/view.php', array('id' => $report->user->id, 'course' => $courseid)), fullname($report->user));
echo $OUTPUT->heading(get_string('pluginname', 'gradereport_user') . ' - ' . $studentnamelink);
}
$gui->close();
} else { // Only show one user's report
- $report = new grade_report_user($courseid, $gpr, $context, $userid);
+ $report = new grade_report_user($courseid, $gpr, $context, $userid, $viewasuser);
$studentnamelink = html_writer::link(new moodle_url('/user/view.php', array('id' => $report->user->id, 'course' => $courseid)), fullname($report->user));
print_grade_page_head($courseid, 'report', 'user', get_string('pluginname', 'gradereport_user') . ' - ' . $studentnamelink,
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
if ($user_selector) {
- $renderer = $PAGE->get_renderer('gradereport_user');
$showallusersoptions = true;
echo $renderer->graded_users_selector('user', $course, $userid, $currentgroup, $showallusersoptions);
}
+ echo $renderer->view_user_selector($userid, $userview);
+
if ($currentgroup and !groups_is_member($currentgroup, $userid)) {
echo $OUTPUT->notification(get_string('groupusernotmember', 'error'));
} else {
$string['eventgradereportviewed'] = 'Grade user report viewed';
$string['pluginname'] = 'User report';
$string['user:view'] = 'View your own grade report';
+$string['myself'] = 'Myself';
+$string['otheruser'] = 'User';
$string['tablesummary'] = 'The table is arranged as a list of graded items including categories of graded items. When items are in a category they will be indicated as such.';
+$string['viewas'] = 'View report as';
define("GRADE_REPORT_USER_HIDE_UNTIL", 1);
define("GRADE_REPORT_USER_SHOW_HIDDEN", 2);
+define("GRADE_REPORT_USER_VIEW_SELF", 1);
+define("GRADE_REPORT_USER_VIEW_USER", 2);
+
/**
* Class providing an API for the user report building and displaying.
* @uses grade_report