diff --git a/README.md b/README.md index c1fda08..d993dfa 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,12 @@ At the end of the block a list of all courses is shown where the usere is enroll # Changelog # + +## [[v2.0.7]] ## +- added releaseinformation in version.php +- add first alpha version of htmlHelper to reduce codeinglines +- fix: duplicate entry problem with capability viewcontent --> viewblockcontent + ## [[v2.0.6]] ## 12.1.2021 - added languagestring for capability diff --git a/block_course_list_advanced.php b/block_course_list_advanced.php index 0f8f9a1..0e9d183 100644 --- a/block_course_list_advanced.php +++ b/block_course_list_advanced.php @@ -28,6 +28,7 @@ require_once($CFG->dirroot . '/course/lib.php'); use block_course_list_advanced\confighandler; +use block_course_list_advanced\htmlhelper; class block_course_list_advanced extends block_list { @@ -56,7 +57,7 @@ public function get_content() { // If not BOTH privileges then do not show content for performancereason. must be allowed to see course AND must be trainer. $isallowedtoseecontent = false; $isallowedtoseecontent = (has_capability('block/course_list_advanced:view', $this->context) - && has_capability('block/course_list_advanced:viewcontent', $this->context)); + && has_capability('block/course_list_advanced:viewblockcontent', $this->context)); if (!$isallowedtoseecontent) { $this->title = get_string('blocktitlealt', 'block_course_list_advanced'); $this->content->footer = get_string('blockfooteralt', 'block_course_list_advanced'); @@ -171,7 +172,6 @@ public function get_content() { . ' G'; } - $duration = $startdate . ' - ' . $enddate; $htmllinktocourse = " ..."; } } + + // TODO: closing the div from class row??? + $blockrow = '
'; if ($countcourseseditingteacher) { - $this->content->items[] = '
' - . $countcourseseditingteacher - . ' ' - . get_string('headlineteacher', 'block_course_list_advanced') - . '
'; - $this->content->items[] = $listalltrainercourses . '
'; + $blockrow = $blockrow . htmlhelper::generate_role_block($countcourseseditingteacher, "headlineteacher", $listalltrainercourses, ""); } if ($countcourseswithstudent) { - $this->content->items[] = '
' - . $countcourseswithstudent - . ' ' - . get_string('headlinestudent', 'block_course_list_advanced') - . '
'; - $this->content->items[] = $listallstudentcourses . '
'; + $blockrow = $blockrow . htmlhelper::generate_role_block($countcourseswithstudent, "headlinestudent", $listallstudentcourses, ""); } if ($countcoursesnoneditingteacher) { - $this->content->items[] = '
' - . $countcoursesnoneditingteacher - . ' ' - . get_string('headlinenoneditingteacher', 'block_course_list_advanced') - . '
'; - $this->content->items[] = $listallnoneditingteachercourses . '
'; + $blockrow = $blockrow . htmlhelper::generate_role_block($countcoursesnoneditingteacher, "headlinenoneditingteacher", $listallnoneditingteachercourses, ""); } - if ($countcourseswithguest && $showcourseswithguestrole) { - $this->content->items[] = '
' - . $countcourseswithguest - . ' ' - . get_string('headlineguest', 'block_course_list_advanced') - . '
'; - $this->content->items[] = $listallguestcourses . '
'; + $blockrow = $blockrow . htmlhelper::generate_role_block($countcourseswithguest, "headlineguest", $listallguestcourses, ""); } - - if ($countcoursesall) { - $this->content->items[] = '
' - . $countcoursesall . ' ' - . get_string('headlinenallcourses', 'block_course_list_advanced') - . ' (max. ' - . $confighandler->get_max_for_siteadmin() - . ')
'; - $this->content->items[] = $listallcourses . '
'; + // siteadmins can view all courses + if (is_siteadmin() && $countcoursesall) { + $max = ''; + $max = $confighandler->get_max_for_siteadmin() ; + $blockrow = $blockrow . htmlhelper::generate_role_block($countcoursesall, "headlinenallcourses", $listallcourses, " (max. $max )"); + $this->content->items[] = $blockrow; } + + + + + $this->get_remote_courses(); if ($this->content->items) { @@ -454,7 +438,7 @@ public function getallcoursesbyselect(): array { } /** - * @var $color string like #ff0000 + * @param string $color like #ff0000 * @return string indicator for the role as html-code */ public function createroleindicator($title, $shortcut, $color): string { @@ -466,9 +450,9 @@ public function createroleindicator($title, $shortcut, $color): string { } /** - * @var $USER - * @var $roleid - * @var $context + * @param string $USER + * @param string $roleid + * @param string $context * @return bool true, if $user is has role with $roleid in $context */ public function has_user_role_with_roleid_in_context($USER, $roleid, $context): bool { diff --git a/classes/htmlhelper.php b/classes/htmlhelper.php new file mode 100644 index 0000000..76c2635 --- /dev/null +++ b/classes/htmlhelper.php @@ -0,0 +1,47 @@ +. + +namespace block_course_list_advanced; +defined('MOODLE_INTERNAL') || die(); +use stdClass; + +class htmlhelper +{ + /** + * @param int $counter number of courses that where found the user has this role + * @param string $headline Title of the block that shows the role + * @param string $courselist html-code including the list of courses to be displayed + * @param string $additional + * + * @return string html-div-code with the heading and a list of courses + */ + public static function generate_role_block(int $counter, string $headline, string $courselist, string $additional) : string{ + $additionaltext = ''; + if (isset($additional)) { + $additionaltext = $additional; + } + $roleblock = '
' + . "
" + . $counter + . ' ' + . get_string("$headline", 'block_course_list_advanced') + . $additionaltext + . '
' + . $courselist + . "
"; + return $roleblock; + } +} diff --git a/db/access.php b/db/access.php index 1592b2c..75b28c5 100644 --- a/db/access.php +++ b/db/access.php @@ -61,7 +61,7 @@ ) ), - 'block/course_list_advanced:viewcontent' => array( + 'block/course_list_advanced:viewblockcontent' => array( 'riskbitmask' => RISK_SPAM | RISK_XSS, 'captype' => 'write', diff --git a/lang/de/block_course_list_advanced.php b/lang/de/block_course_list_advanced.php index 13b0b0d..d31e0c0 100644 --- a/lang/de/block_course_list_advanced.php +++ b/lang/de/block_course_list_advanced.php @@ -26,11 +26,11 @@ defined('MOODLE_INTERNAL') || die(); $string['allcourses'] = 'Administrator:innen sehen alle Kurse'; -$string['blocktitle'] = 'Meine Kurse advanced'; +$string['blocktitle'] = 'Meine Kurse und Rollen'; $string['blocktitlealt'] = 'nicht unterstützt'; $string['blockfooteralt'] = 'Inhalt wird nur in einem Kurs für Trainer:innen angezeigt'; -$string['course_list_advanced:viewcontent'] = 'Berechtigung, die Inhalte im Block zu sehen'; +$string['course_list_advanced:viewblockcontent'] = 'Berechtigung, die Inhalte im Block zu sehen'; $string['adminview'] = 'Adminansicht'; $string['configadminview'] = 'Alle Kurse anzeigen oder nur Kurse, in die Administratorin oder Administatorin mit einer Rolle eingeschrieben ist.'; diff --git a/lang/en/block_course_list_advanced.php b/lang/en/block_course_list_advanced.php index 3d155d6..05b7db3 100644 --- a/lang/en/block_course_list_advanced.php +++ b/lang/en/block_course_list_advanced.php @@ -26,11 +26,11 @@ defined('MOODLE_INTERNAL') || die(); $string['allcourses'] = 'Admin user sees all courses'; -$string['blocktitle'] = 'Courses advanced'; +$string['blocktitle'] = 'My courses and roles'; $string['blocktitlealt'] = 'not supported'; $string['blockfooteralt'] = 'Content only supported in a course where user is trainer'; -$string['course_list_advanced:viewcontent'] = 'capability to view the content in this block'; +$string['course_list_advanced:viewblockcontent'] = 'capability to view the content in this block'; $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.'; diff --git a/styles.css b/styles.css index e040949..3cd1609 100644 --- a/styles.css +++ b/styles.css @@ -21,15 +21,19 @@ } .block_course_list_advanced .coursecssactiv { - margin-bottom: 10px; + margin-bottom: 0; padding-left: 2px; border-left: solid 5px rgb(5, 148, 60); + border-bottom: solid 1px #ccc; + border-right: solid 1px #ccc; } .block_course_list_advanced .coursecssfinished { - margin-bottom: 10px; + margin-bottom: 0; padding-left: 2px; border-left: solid 5px rgb(155, 13, 13); + border-bottom: solid 1px #ccc; + border-right: solid 1px #ccc; } .block_course_list_advanced .dimmed .coursecssfinished { @@ -37,9 +41,11 @@ } .block_course_list_advanced .coursecssfuture { - margin-bottom: 10px; + margin-bottom: 0; padding-left: 2px; border-left: solid 5px rgb(58, 132, 241); + border-bottom: solid 1px #ccc; + border-right: solid 1px #ccc; } .block_course_list_advanced .headlineteacher, @@ -51,3 +57,10 @@ border: solid 1px #bbb; background-color: #ddd; } + +.block_course_list_advanced .roleblock { + margin: 15px; + width: 100%; + max-width: 365px; + box-shadow: 0 0 0 #bbb; +} diff --git a/version.php b/version.php index 7f3d7bc..68e24c3 100644 --- a/version.php +++ b/version.php @@ -25,6 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022011200; +$plugin->version = 2022020400; $plugin->requires = 2020060900; $plugin->component = 'block_course_list_advanced'; +$plugin->release = 'v2.0.7';