Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions block_profile_redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_profile_redirect extends block_base {

function init() {
public function init() {
$this->title = get_string('blockname', 'block_profile_redirect');
}

Expand All @@ -39,9 +38,8 @@ function get_content() {
}

$context = context_system::instance();

if (has_capability('moodle/site:config', $context)) { // 'moodle/site:doanything' no longer exists.
$content = get_string('sysadmin','block_profile_redirect');
$content = get_string('sysadmin', 'block_profile_redirect');
} else {
$config = get_config('blocks/profile_redirect');
if (isset($config->profilefield)) {
Expand All @@ -66,11 +64,11 @@ function get_content() {
}
// $courefieldvalue must not be empty (if it's empty it redirects infinitly).
// It also MUST return 1 record.
$course = $DB->get_record('course',array($config->coursefield => $coursefieldvalue));
$course = $DB->get_record('course', array($config->coursefield => $coursefieldvalue));

if (!empty($coursefieldvalue) and !empty($course)) {
if (!empty($coursefieldvalue) && !empty($course)) {
// Since M2 doesn't output any code we can redirect cleanly.
redirect($CFG->wwwroot.'/course/view.php?id='.$course->id,'',0);
redirect($CFG->wwwroot.'/course/view.php?id='.$course->id, '', 0);
$content = ''; // Moodle complains if this isn't set.
} else {
$content = '';
Expand All @@ -85,11 +83,9 @@ function get_content() {

return $this->content;
}

function hide_header() {
return true;
}

function has_config() {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ class provider implements \core_privacy\local\metadata\null_provider {
public static function get_reason() : string {
return 'privacy:metadata';
}
}
}
10 changes: 5 additions & 5 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
'manager' => CAP_ALLOW,
),

'clonepermissionsfrom' => 'moodle/site:manageblocks'
'clonepermissionsfrom' => 'moodle/site:manageblocks',
),

'block/profile_redirect:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
'user' => CAP_ALLOW,
),

'clonepermissionsfrom' => 'moodle/my:manageblocks'
)
'clonepermissionsfrom' => 'moodle/my:manageblocks',
),
);
4 changes: 2 additions & 2 deletions lang/en/block_profile_redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['pluginname'] = 'Profile Redirect';
$string['pluginname'] = 'Profile Redirect';
$string['blockname'] = 'Profile Redirect';
$string['description'] ='Description';
$string['description'] = 'Description';
$string['descriptiontxt'] = '<p>The Profile Redirect block is designed to redirect a user from the site front page or My Moodle page containing the block to
a new course. The new course the user is redirected to is based on a value in a profile field matching a value in the course fullname, shortname, or id number based on the site configurations below.</p>

Expand Down
6 changes: 3 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

/**
* Return user fields and custom fields
*
* @return array of userfields without the id fields
*
* @return array of userfields without the id fields
*/
function block_profile_redirect_profile_fields() {
global $CFG, $DB;
Expand All @@ -37,7 +37,7 @@ function block_profile_redirect_profile_fields() {
require_once($CFG->dirroot.'/user/profile/lib.php');

// Only grab the custom profile fields that can contain a course's full name.
if ($fields = $DB->get_records_select('user_info_field','')) {
if ($fields = $DB->get_records_select('user_info_field', '')) {
foreach ($fields as $field) {
require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
$newfield = 'profile_field_'.$field->datatype;
Expand Down