Skip to content

Commit

Permalink
Merge pull request #9 from andreasschenkel/develop
Browse files Browse the repository at this point in the history
version 1.0 only for trainer
  • Loading branch information
andreasschenkel authored Oct 27, 2021
2 parents 3a6445a + bcd9d32 commit 2d8969e
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/*
61 changes: 50 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
60 changes: 47 additions & 13 deletions block_course_list_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -175,20 +190,37 @@ function get_content()
. "</a>";

$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 = "<a $linkcss style=\"color: #921616\" title=\""
. format_string($course->shortname, true, array('context' => $coursecontext))
. "\" "
. "href=\"$CFG->wwwroot/course/delete.php?id=$course->id\">"
. $iconDeletion
. "</a>";

}

$iconOrphanedFilesLink =

' <i class="text-info"
data-toggle="tooltip"
data-placement="right"
title="Report über verwaiste Dateien" >
<i class="fa fa-server"></i> </i>';



$linkViewOrphanedFiles = '';
if ($usesphorphanedfiles) {
$orphanedFilesLink = new moodle_url('/report/sphorphanedfiles/index.php', array('id' => $course->id));
$linkViewOrphanedFiles = '<a href="' . $orphanedFilesLink . '"> ' . $iconOrphanedFilesLink . '</a>';
}

if ($isEditingTeacher) {
$listAllTrainerCourses = $listAllTrainerCourses . '<div ' . $linkcss . '>' . '<div ' . $coursecss . '>' . $htmllinktocourse . ' ' . $htmllinktocoursedeletion . ' ' . $roles . '<br>' . $duration . '</div></div>';
$listAllTrainerCourses = $listAllTrainerCourses . '<div ' . $linkcss . '>' . '<div ' . $coursecss . '>' . $htmllinktocourse . ' ' . $linkViewOrphanedFiles . ' ' . $htmllinktocoursedeletion . ' ' . $roles . '<br>' . $duration . '</div></div>';
$countCoursesWithTrainer++;
}
if ($isStudent) {
Expand All @@ -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 = "<a href=\"$CFG->wwwroot/course/index.php\">"
Expand Down Expand Up @@ -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) [
Expand Down
7 changes: 7 additions & 0 deletions blockcourselistadvanced.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": "."
}
]
}
12 changes: 12 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
),

);
22 changes: 20 additions & 2 deletions lang/de/block_course_list_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,35 @@
* @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.';
$string['headlineteacher'] = '<b>Kurs(e) - Lehrende</b>';
$string['headlinestudent'] = '<b>Kurs(e) - Teilnehmer</b>';
$string['headlinenoneditingteacher'] = '<b>Kurs(e) - Lehrende o Bearbeitung</b>';
$string['noenddate'] = 'offen';



19 changes: 17 additions & 2 deletions lang/en/block_course_list_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,32 @@
* @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.';
$string['headlineteacher'] = '<b>Course(s) - trainer</b>';
$string['headlinestudent'] = '<b>Course(s) - student</b>';
$string['headlinenoneditingteacher'] = '<b>Course(s) - trainer nonediting</b>';
$string['noenddate'] = 'open';

33 changes: 28 additions & 5 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2d8969e

Please sign in to comment.