Skip to content

Commit

Permalink
Merge pull request #16 from andreasschenkel/develop
Browse files Browse the repository at this point in the history
v2.0.7 fix: duplicate entry problem with capability viewcontent
  • Loading branch information
andreasschenkel authored Feb 4, 2022
2 parents c23d03d + c84bd6d commit 7fc5e33
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 49 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 24 additions & 40 deletions block_course_list_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -171,7 +172,6 @@ public function get_content() {
. ' <i class="text-info" data-toggle="tooltip" data-placement="right" title="Guest" ><font color="#888800">G</font></i>';
}


$duration = $startdate . ' - ' . $enddate;

$htmllinktocourse = "<a $linkcss title=\""
Expand Down Expand Up @@ -248,49 +248,33 @@ public function get_content() {
. "</a> ...";
}
}

// TODO: closing the div from class row???
$blockrow = '<div class="row">';
if ($countcourseseditingteacher) {
$this->content->items[] = '<div class="headlineteacher">'
. $countcourseseditingteacher
. ' '
. get_string('headlineteacher', 'block_course_list_advanced')
. '</div>';
$this->content->items[] = $listalltrainercourses . ' <br />';
$blockrow = $blockrow . htmlhelper::generate_role_block($countcourseseditingteacher, "headlineteacher", $listalltrainercourses, "");
}
if ($countcourseswithstudent) {
$this->content->items[] = '<div class="headlinestudent">'
. $countcourseswithstudent
. ' '
. get_string('headlinestudent', 'block_course_list_advanced')
. '</div>';
$this->content->items[] = $listallstudentcourses . '<br />';
$blockrow = $blockrow . htmlhelper::generate_role_block($countcourseswithstudent, "headlinestudent", $listallstudentcourses, "");
}
if ($countcoursesnoneditingteacher) {
$this->content->items[] = '<div class="headlinenoneditingteacher">'
. $countcoursesnoneditingteacher
. ' '
. get_string('headlinenoneditingteacher', 'block_course_list_advanced')
. '</div>';
$this->content->items[] = $listallnoneditingteachercourses . '<br />';
$blockrow = $blockrow . htmlhelper::generate_role_block($countcoursesnoneditingteacher, "headlinenoneditingteacher", $listallnoneditingteachercourses, "");
}

if ($countcourseswithguest && $showcourseswithguestrole) {
$this->content->items[] = '<div class="headlineguest">'
. $countcourseswithguest
. ' '
. get_string('headlineguest', 'block_course_list_advanced')
. '</div>';
$this->content->items[] = $listallguestcourses . '<br />';
$blockrow = $blockrow . htmlhelper::generate_role_block($countcourseswithguest, "headlineguest", $listallguestcourses, "");
}

if ($countcoursesall) {
$this->content->items[] = '<div class="headlinenallcourses">'
. $countcoursesall . ' '
. get_string('headlinenallcourses', 'block_course_list_advanced')
. ' (max. '
. $confighandler->get_max_for_siteadmin()
. ')</div>';
$this->content->items[] = $listallcourses . '<br />';
// 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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
47 changes: 47 additions & 0 deletions classes/htmlhelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

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 = '<div class="roleblock">'
. "<div class='$headline'>"
. $counter
. ' '
. get_string("$headline", 'block_course_list_advanced')
. $additionaltext
. '</div> '
. $courselist
. "</div>";
return $roleblock;
}
}
2 changes: 1 addition & 1 deletion db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
)
),

'block/course_list_advanced:viewcontent' => array(
'block/course_list_advanced:viewblockcontent' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,

'captype' => 'write',
Expand Down
4 changes: 2 additions & 2 deletions lang/de/block_course_list_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
4 changes: 2 additions & 2 deletions lang/en/block_course_list_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
19 changes: 16 additions & 3 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,31 @@
}

.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 {
border-left: #af8080 solid 5px;
}

.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,
Expand All @@ -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;
}
3 changes: 2 additions & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 7fc5e33

Please sign in to comment.