From ce4d1c4f92b5e8c19ac918a85b99a84f299b842c Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Fri, 29 Dec 2023 09:19:38 -0500 Subject: [PATCH 1/6] Fixed visibility in the init method --- block_profile_redirect.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block_profile_redirect.php b/block_profile_redirect.php index f7e9550..66098ce 100644 --- a/block_profile_redirect.php +++ b/block_profile_redirect.php @@ -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'); } From 0e32d1f848f3ed0188090abe417921e6f3388346 Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Fri, 29 Dec 2023 09:29:52 -0500 Subject: [PATCH 2/6] Fixed syntax in code formatting --- block_profile_redirect.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block_profile_redirect.php b/block_profile_redirect.php index 66098ce..814f031 100644 --- a/block_profile_redirect.php +++ b/block_profile_redirect.php @@ -23,9 +23,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class block_profile_redirect extends block_base { - public function init() { + public function init() { $this->title = get_string('blockname', 'block_profile_redirect'); - } + } function applicable_formats() { return array('all' => false, 'site' => true, 'my' => true); From 8978f4f81c03ab252ade0bda4331405387752d63 Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Fri, 29 Dec 2023 09:36:56 -0500 Subject: [PATCH 3/6] The added white space after commas and Removed extra newline --- block_profile_redirect.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/block_profile_redirect.php b/block_profile_redirect.php index 814f031..31c0a8e 100644 --- a/block_profile_redirect.php +++ b/block_profile_redirect.php @@ -25,7 +25,7 @@ class block_profile_redirect extends block_base { public function init() { $this->title = get_string('blockname', 'block_profile_redirect'); - } + } function applicable_formats() { return array('all' => false, 'site' => true, 'my' => true); @@ -38,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)) { @@ -65,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)) { // 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 = ''; @@ -84,11 +83,9 @@ function get_content() { return $this->content; } - function hide_header() { return true; } - function has_config() { return true; } From 3acfbca2bbe2dbdb557ef41ad17454564b54e495 Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Fri, 29 Dec 2023 09:37:51 -0500 Subject: [PATCH 4/6] Fixed syntax error with 'and' operator. --- block_profile_redirect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block_profile_redirect.php b/block_profile_redirect.php index 31c0a8e..4379643 100644 --- a/block_profile_redirect.php +++ b/block_profile_redirect.php @@ -66,7 +66,7 @@ function get_content() { // It also MUST return 1 record. $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); $content = ''; // Moodle complains if this isn't set. From 5dde3a299b88bec482616b0f9f017646c89fc2b1 Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Fri, 29 Dec 2023 09:59:36 -0500 Subject: [PATCH 5/6] Fixed array syntax issues. --- db/access.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/access.php b/db/access.php index 157e16f..cacd207 100644 --- a/db/access.php +++ b/db/access.php @@ -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', + ), ); From 5b0b8607dfafc7d588a1c137778db8e1f8e5e656 Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Fri, 29 Dec 2023 10:11:22 -0500 Subject: [PATCH 6/6] Added space after comma, fixed indentation, and added trailing space --- classes/privacy/provider.php | 2 +- lang/en/block_profile_redirect.php | 4 ++-- lib.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index e7dab74..d76b4e1 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -43,4 +43,4 @@ class provider implements \core_privacy\local\metadata\null_provider { public static function get_reason() : string { return 'privacy:metadata'; } -} \ No newline at end of file +} diff --git a/lang/en/block_profile_redirect.php b/lang/en/block_profile_redirect.php index 943bffd..387955a 100644 --- a/lang/en/block_profile_redirect.php +++ b/lang/en/block_profile_redirect.php @@ -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'] = '

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.

diff --git a/lib.php b/lib.php index 1ca278e..1b28394 100644 --- a/lib.php +++ b/lib.php @@ -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; @@ -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;