diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75ec3f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/* \ No newline at end of file diff --git a/README.md b/README.md index 921746a..705d06b 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,67 @@ # moodle-block_course_list_advanced The normal block course list shows all courses and has no information about the role in the course. -The block moodle-block_course_list_advanced adds some more information about a course. I adds the information whitch of the following roles a user is enrolled into a course. +The block moodle-block_course_list_advanced adds some more information about a course. I adds the information which of the following roles a user is enrolled into a course. + +For performance and testing-reason this first version only shows the content if the block is added into a course AND the user is trainer. + +![image](https://user-images.githubusercontent.com/31856043/139007404-9f72772a-6e79-4d07-8fd0-4924613c47ac.png) + +## numbers ## +### 1, 2: ### +counts the courses with the role trainer or student + + +### 3, 4, 5: ### Also colors indicates courses that - are in progress --> green - are past -> red - are in the future --> blue + (are in progress --> green), + (are past -> red), + (are in the future --> blue) + +### 6, 7, 8: +Startdate and enddate of a course + +### 9: +able to delete a course if capability moodle/course:delete + +### 10: +Indicates trainer or student + +### 11: +note jet supported + + +# Configure the block # + +![image](https://user-images.githubusercontent.com/31856043/139007295-62e27c76-1eb5-415f-9aab-8c9929968d17.png) -![grafik](https://user-images.githubusercontent.com/31856043/132042960-dc6645ea-7c34-4b5e-99fa-e4bcac4511c9.png) At the end of the block a list of all courses is shown where the usere is enrolled as teacher. # ToDo # -block may be "expensive" in large moodleinstances with many users. instead of using a block it might be a good idea to implement the functionality as a part of the profile-page +- block may be "expensive" in large moodleinstances with many users. instead of using a block it might be a good idea to implement the functionality as a part of the profile-page +- configuration to be able to activate block also for student if performance is ok (e.g. small schools) +- choose better colors +- add some more languagestring to instead of hardcoded text +- optimize code for enrollmentcheck +- change form php to moodle-codestyle +- correct some spelling mistake + + # Changelog # +## [[v1.00]] ## +- added some docúmentation +- added configuration +- only show content if block is in a course AND user is trainer +- added delete-icon (can be activated or deactivated) + + ## [[v0.92]] ## -Adding startdate and enddate. -Also colors indicates courses that - are in progress --> green - are past -> red - are in the future --> blue +- Adding startdate and enddate. +- Also colors indicates courses that (are in progress --> green), (are past -> red), (are in the future --> blue) ## [[v0.91]] ## added letter after the coursename to indicate role diff --git a/block_course_list_advanced.php b/block_course_list_advanced.php index c25f0e6..62b7d4a 100644 --- a/block_course_list_advanced.php +++ b/block_course_list_advanced.php @@ -19,7 +19,7 @@ * * @package block_course_list_advanced * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) - * @author Andreas Schenkel - Schulportal Hessen + * @author Andreas Schenkel - Schulportal Hessen 2021 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -50,15 +50,29 @@ function get_content() $this->content->icons = array(); $this->content->footer = ''; - $icon = $OUTPUT->pix_icon('i/course', get_string('course')); + // if not BOTH privileges then do not show content for performancereason. must be allowed to see course AND must be trainer + if ( !(has_capability('block/course_list_advanced:view', $this->context) && has_capability('moodle/course:update', $this->context )) ) { + $this->title = get_string('blocktitlealt', 'block_course_list_advanced'); + $this->content->footer = get_string('blockfooteralt', 'block_course_list_advanced'); + return $this->content; + } + $icon = $OUTPUT->pix_icon('i/course', get_string('course')); $iconDeletion = $OUTPUT->pix_icon('i/delete', get_string('delete')); $adminseesall = true; - if (isset($CFG->block_course_list_advanced_adminview)) { - if ($CFG->block_course_list_advanced_adminview == 'own') { - $adminseesall = false; - } + if (isset($CFG->block_course_list_advanced_adminview) && $CFG->block_course_list_advanced_adminview == 'own') { + $adminseesall = false; + } + + $showdeleteicon = false; + if (isset($CFG->block_course_list_advanced_showdeleteicon) && $CFG->block_course_list_advanced_showdeleteicon == true) { + $showdeleteicon = true; + } + + $usesphorphanedfiles = false; + if (isset($CFG->block_course_list_advanced_showdeleteicon) && $CFG->block_course_list_advanced_usesphorphanedfiles == true) { + $usesphorphanedfiles = true; } $allcourselink = @@ -122,6 +136,7 @@ function get_content() * getting all users with moodle/course:manageactivities. * This should be all user with role teacher (without noneditingteacher) * @todo implement better way to find role of the user in the course + * @todo see at https://docs.moodle.org/dev/NEWMODULE_Adding_capabilities */ $editingteachers = get_users_by_capability($coursecontext, 'moodle/course:manageactivities'); $isEditingTeacher = false; @@ -175,20 +190,37 @@ function get_content() . ""; $isallowedtodelete = false; - if (is_enrolled($coursecontext, $USER, 'moodle/course:delete', $onlyactive = false)) { - $isallowedtodelete = true; - } - if ($isallowedtodelete) { + + // only if showdeleteicon is true, then we have to check, which courses are deletable and show a delete-icon + if ($showdeleteicon && is_enrolled($coursecontext, $USER, 'moodle/course:delete', $onlyactive = false)) { + //$isallowedtodelete = true; $htmllinktocoursedeletion = "shortname, true, array('context' => $coursecontext)) . "\" " . "href=\"$CFG->wwwroot/course/delete.php?id=$course->id\">" . $iconDeletion . ""; + + } + + $iconOrphanedFilesLink = + + ' + '; + + + + $linkViewOrphanedFiles = ''; + if ($usesphorphanedfiles) { + $orphanedFilesLink = new moodle_url('/report/sphorphanedfiles/index.php', array('id' => $course->id)); + $linkViewOrphanedFiles = ' ' . $iconOrphanedFilesLink . ''; } if ($isEditingTeacher) { - $listAllTrainerCourses = $listAllTrainerCourses . '
' . '
' . $htmllinktocourse . ' ' . $htmllinktocoursedeletion . ' ' . $roles . '
' . $duration . '
'; + $listAllTrainerCourses = $listAllTrainerCourses . '
' . '
' . $htmllinktocourse . ' ' . $linkViewOrphanedFiles . ' ' . $htmllinktocoursedeletion . ' ' . $roles . '
' . $duration . '
'; $countCoursesWithTrainer++; } if ($isStudent) { @@ -210,7 +242,8 @@ function get_content() $countCoursesWithNoneditingTeacher++; } } - $this->title = get_string('mycourses'); + //$this->title = get_string('mycourses'); + $this->title = get_string('blocktitle', 'block_course_list_advanced'); /// If we can update any course of the view all isn't hidden, show the view all courses link if ($allcourselink) { $this->content->footer = "wwwroot/course/index.php\">" @@ -365,7 +398,8 @@ public function get_config_for_external() // Return all settings for all users since it is safe (no private keys, etc..). $configs = (object) [ 'adminview' => $CFG->block_course_list_advanced_adminview, - 'hideallcourseslink' => $CFG->block_course_list_advanced_hideallcourseslink + 'hideallcourseslink' => $CFG->block_course_list_advanced_hideallcourseslink, + 'showdeleteicon' => $CFG->block_course_list_advanced_showdeleteicon ]; return (object) [ diff --git a/blockcourselistadvanced.code-workspace b/blockcourselistadvanced.code-workspace new file mode 100644 index 0000000..362d7c2 --- /dev/null +++ b/blockcourselistadvanced.code-workspace @@ -0,0 +1,7 @@ +{ + "folders": [ + { + "path": "." + } + ] +} \ No newline at end of file diff --git a/db/access.php b/db/access.php index 080a939..d29f30f 100644 --- a/db/access.php +++ b/db/access.php @@ -49,4 +49,16 @@ 'clonepermissionsfrom' => 'moodle/site:manageblocks' ), + + 'block/course_list_advanced:view' => array( + 'riskbitmask' => RISK_SPAM | RISK_XSS, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_BLOCK, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'student' => CAP_PREVENT, + ) + ), + ); diff --git a/lang/de/block_course_list_advanced.php b/lang/de/block_course_list_advanced.php index c31f210..b9feee0 100644 --- a/lang/de/block_course_list_advanced.php +++ b/lang/de/block_course_list_advanced.php @@ -23,13 +23,28 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['adminview'] = 'Adminansicht'; $string['allcourses'] = 'Administrator:innen sehen alle Kurse'; +$string['blocktitle'] = 'Meine Kurse advanced'; +$string['blocktitlealt'] = 'nicht unterstützt'; +$string['blockfooteralt'] = 'Inhalt wird nur in einem Kurs für Trainer:innen angezeigt'; + +$string['adminview'] = 'Adminansicht'; $string['configadminview'] = 'Alle Kurse anzeigen oder nur Kurse, in die Administratorin oder Administatorin mit einer Rolle eingeschrieben ist.'; + +$string['hideallcourseslink'] = 'Verberge \'Alle Kurse\' Link'; $string['confighideallcourseslink'] = 'Entferne den \'Alle Kurse\' Link unter der Liste aller Kurse. Einstellung beeinflusst nicht die Anzeoge für Admins.)'; + +$string['usesphorphanedfiles'] = 'Nutze Plugin für verwaiste Dateien (Plugin muss installiert sein!)'; +$string['configusesphorphanedfiles'] = 'Wenn aktiviert wird im Block ein ? als Link angezeigt um direkt zur Anzeige der verwaisten Dateien des Kurses zu gelangen.'; + $string['course_list_advanced:addinstance'] = 'Block Kursliste erweitert hinzufügen'; $string['course_list_advanced:myaddinstance'] = 'Block Kursliste erweitert zum Arbeitsplatz hinzufügen'; -$string['hideallcourseslink'] = 'Verberge \'Alle Kurse\' Link'; +$string['course_list_advanced:view'] = 'Block anzeigen'; + +$string['showdeleteicon'] = 'Löschen-Icon anzeigen, um direkt im Block löschen zu können.'; +$string['configshowdeleteicon'] = 'Wenn aktiviert, dann wird im Block neben dem Kursnamen ein Löschen-Icon angezeigt, um den Kurs gegebenenfalls direkt löschen zu können.'; + + $string['owncourses'] = 'Admin sieht eigene Kurse'; $string['pluginname'] = 'Kursliste erweitert'; $string['privacy:metadata'] = 'Der Block Kursliste erweitert zeigt nur Daten über Kurse an und speichert keine Daten.'; @@ -37,3 +52,6 @@ $string['headlinestudent'] = 'Kurs(e) - Teilnehmer'; $string['headlinenoneditingteacher'] = 'Kurs(e) - Lehrende o Bearbeitung'; $string['noenddate'] = 'offen'; + + + diff --git a/lang/en/block_course_list_advanced.php b/lang/en/block_course_list_advanced.php index 40c9ef1..5032566 100644 --- a/lang/en/block_course_list_advanced.php +++ b/lang/en/block_course_list_advanced.php @@ -23,13 +23,27 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['adminview'] = 'Admin view'; $string['allcourses'] = 'Admin user sees all courses'; +$string['blocktitle'] = 'Courses advanced'; +$string['blocktitlealt'] = 'not supported'; +$string['blockfooteralt'] = 'Content only supported in a course where user is trainer'; + +$string['adminview'] = 'Admin view'; $string['configadminview'] = 'Whether to display all courses in the Courses advanced block, or only courses that the admin is enrolled in.'; + +$string['hideallcourseslink'] = 'Hide \'All courses\' link'; $string['confighideallcourseslink'] = 'Remove the \'All courses\' link under the list of courses. (This setting does not affect the admin view.)'; + +$string['showdeleteicon'] = 'Show a delete-icon to delete directly from the block.'; +$string['configshowdeleteicon'] = 'If set to true an delete-icon is shown nearby the coursename in order to be able to delet the course directly from the block.'; + +$string['usesphorphanedfiles'] = 'Use Plugin sphorphanedfiles (Plugin must be installed!)'; +$string['configusesphorphanedfiles'] = 'When activatet a ? as a link is shown to jump direktly to the List of orphaned files in this course.'; +$string['course_list_advanced:view'] = 'Show block'; + $string['course_list_advanced:addinstance'] = 'Add a new courses block'; $string['course_list_advanced:myaddinstance'] = 'Add a new courses block to Dashboard'; -$string['hideallcourseslink'] = 'Hide \'All courses\' link'; + $string['owncourses'] = 'Admin user sees own courses'; $string['pluginname'] = 'Courses advanced'; $string['privacy:metadata'] = 'The Courses block only shows data about courses and does not store any data itself.'; @@ -37,3 +51,4 @@ $string['headlinestudent'] = 'Course(s) - student'; $string['headlinenoneditingteacher'] = 'Course(s) - trainer nonediting'; $string['noenddate'] = 'open'; + diff --git a/settings.php b/settings.php index c5cc6c2..d40c33f 100644 --- a/settings.php +++ b/settings.php @@ -25,11 +25,34 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { - $options = array('all'=>get_string('allcourses', 'block_course_list_advanced'), 'own'=>get_string('owncourses', 'block_course_list_advanced')); + $options = array('all' => get_string('allcourses', 'block_course_list_advanced'), 'own' => get_string('owncourses', 'block_course_list_advanced')); - $settings->add(new admin_setting_configselect('block_course_list_advanced_adminview', get_string('adminview', 'block_course_list_advanced'), - get_string('configadminview', 'block_course_list_advanced'), 'all', $options)); + $settings->add(new admin_setting_configselect( + 'block_course_list_advanced_adminview', + get_string('adminview', 'block_course_list_advanced'), + get_string('configadminview', 'block_course_list_advanced'), + 'all', + $options + )); - $settings->add(new admin_setting_configcheckbox('block_course_list_advanced_hideallcourseslink', get_string('hideallcourseslink', 'block_course_list_advanced'), - get_string('confighideallcourseslink', 'block_course_list_advanced'), 0)); + $settings->add(new admin_setting_configcheckbox( + 'block_course_list_advanced_hideallcourseslink', + get_string('hideallcourseslink', 'block_course_list_advanced'), + get_string('confighideallcourseslink', 'block_course_list_advanced'), + 0 + )); + + $settings->add(new admin_setting_configcheckbox( + 'block_course_list_advanced_showdeleteicon', + get_string('showdeleteicon', 'block_course_list_advanced'), + get_string('configshowdeleteicon', 'block_course_list_advanced'), + 0 + )); + + $settings->add(new admin_setting_configcheckbox( + 'block_course_list_advanced_usesphorphanedfiles', + get_string('usesphorphanedfiles', 'block_course_list_advanced'), + get_string('configusesphorphanedfiles', 'block_course_list_advanced'), + 0 + )); } diff --git a/version.php b/version.php index 98af34a..39269ba 100644 --- a/version.php +++ b/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2021081400; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2021102502; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2020060900; // Requires this Moodle version $plugin->component = 'block_course_list_advanced'; // Full name of the plugin (used for diagnostics)