Skip to content

Commit

Permalink
Merge pull request #9 from eLearning-TUDarmstadt/dev
Browse files Browse the repository at this point in the history
bugfix + plugin ci update
  • Loading branch information
andreasschenkel authored Jan 6, 2024
2 parents 44d8e6e + a951c38 commit 1f699c5
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 65 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/ci.yml → .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,42 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04

services:
postgres:
image: postgres:10
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3

mariadb:
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"

ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0']
moodle-branch: ['MOODLE_311_STABLE']
database: [pgsql, mariadb]
php: [ '8.0', '8.1', '8.2' ]
moodle-branch: [ 'MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE' ]
database: [ 'mariadb', 'pgsql' ]
exclude:
- php: '8.2'
moodle-branch: 'MOODLE_401_STABLE'

steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: plugin

Expand All @@ -46,12 +49,11 @@ jobs:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
# none to use phpdbg fallback. Specify pcov (Moodle 3.10 and up) or xdebug to use them instead.
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
Expand Down Expand Up @@ -80,7 +82,7 @@ jobs:

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker --max-warnings 0
run: moodle-plugin-ci phpcs --max-warnings 0

- name: Moodle PHPDoc Checker
if: ${{ always() }}
Expand Down
40 changes: 24 additions & 16 deletions block_overviewmyrolesincourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ public function get_content() {
$data->roleshortname = $rolefixname->shortname;
$data->rolelocalname = $rolefixname->localname;
$data->foldonstart = $foldonstart;
$data->mylist = $this->get_courses_enroled_with_roleid($USER->id,
$enroledcourses, $rolefixname->id, $favouritecourseids);
$data->mylist = $this->get_courses_enroled_with_roleid(
$USER->id,
$enroledcourses,
$rolefixname->id,
$favouritecourseids
);
$data->counter = count($data->mylist);
// To get example-json for mustache uncomment following line of code.
// This can be uses to get a json-example $objectasjson = json_encode($data);
Expand All @@ -101,7 +105,7 @@ public function get_content() {
$text .= $this->create_agenda();
}

$this->content = new stdClass;
$this->content = new stdClass();
$this->content->text = $text;
$footer = '';
$this->content->footer = $footer;
Expand All @@ -120,10 +124,12 @@ public function get_content() {
* @throws dml_exception
* @throws moodle_exception
*/
public function get_courses_enroled_with_roleid(string $userid,
array $enroledcourses,
string $roleid,
array $favouritecourseids = []): array {
public function get_courses_enroled_with_roleid(
string $userid,
array $enroledcourses,
string $roleid,
array $favouritecourseids = []
): array {
$result = [];
foreach ($enroledcourses as $enroledcourse) {
$coursecontext = context_course::instance($enroledcourse->id);
Expand Down Expand Up @@ -182,8 +188,8 @@ public function get_courses_enroled_with_roleid(string $userid,
// Add additional information like url to the course, ...
$url = new moodle_url('/course/view.php', ['id' => $enroledcourse->id]);
$urldelete = new moodle_url('/course/delete.php', ['id' => $enroledcourse->id]);
$enroledcoursewithrole->url = $url;
$enroledcoursewithrole->urldelete = $urldelete;
$enroledcoursewithrole->url = $url->__toString();
$enroledcoursewithrole->urldelete = $urldelete->__toString();
$enroledcoursewithrole->dimmed = $dimmed;
$enroledcoursewithrole->duration = $this->create_duration($enroledcourse)->duration;
$enroledcoursewithrole->durationstatus = $this->create_duration($enroledcourse)->durationstatus;
Expand Down Expand Up @@ -220,7 +226,7 @@ public function has_config() {
private function create_duration(stdClass $course): stdClass {
global $DB;
$now = time();
$startdate = userdate($course->startdate, get_string('strftimedatefullshort', 'core_langconfig'));
$startdate = userdate($course->startdate, get_string('strftimedatefullshort', 'core_langconfig'));

// Code: course->enddate is empty if function enrol_get_my_courses() was used.
$courserecord = $DB->get_record('course', ['id' => $course->id]);
Expand Down Expand Up @@ -313,13 +319,13 @@ public function create_agenda(): string {
* @return boolean
*/
public function instance_create() {
$data = array(
$data = [
'showpast' => get_config('block_overviewmyrolesincourses', 'defaultshowpast'),
'showinprogress' => get_config('block_overviewmyrolesincourses', 'defaultshowinprogress'),
'showfuture' => get_config('block_overviewmyrolesincourses', 'defaultshowfuture'),
'onlyshowfavourite' => get_config('block_overviewmyrolesincourses', 'onlyshowfavourite'),
'foldonstart' => get_config('block_overviewmyrolesincourses', 'defaultfoldonstart')
);
'onlyfavourite' => get_config('block_overviewmyrolesincourses', 'defaultonlyshowfavourite'),
'foldonstart' => get_config('block_overviewmyrolesincourses', 'defaultfoldonstart'),
];
$this->instance_config_save($data);
return true;
}
Expand All @@ -337,9 +343,11 @@ public function get_favourite_course_ids($userid): array {
$favourites = $ufservice->find_favourites_by_type('core_course', 'courses');
if ($favourites) {
$favouritecourseids = array_map(
function($favourite) {
function ($favourite) {
return $favourite->itemid;
}, $favourites);
},
$favourites
);
}
return $favouritecourseids;
}
Expand Down
28 changes: 14 additions & 14 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@

defined('MOODLE_INTERNAL') || die();

$capabilities = array(
'block/overviewmyrolesincourses:myaddinstance' => array(
$capabilities = [
'block/overviewmyrolesincourses:myaddinstance' => [
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'archetypes' => [
'user' => CAP_ALLOW,
),
),
],
],

'block/overviewmyrolesincourses:addinstance' => array(
'block/overviewmyrolesincourses:addinstance' => [
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'archetypes' => [
'user' => CAP_ALLOW,
),
),
],
],

'block/overviewmyrolesincourses:viewcontent' => array(
'block/overviewmyrolesincourses:viewcontent' => [
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'read',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'archetypes' => [
'user' => CAP_ALLOW,
),
)
);
],
],
];
10 changes: 5 additions & 5 deletions edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ protected function specific_definition($mform) {
$mform->addElement('header', 'config_header', get_string('blocksettings', 'block'));

$name = get_string('showpast', 'block_overviewmyrolesincourses');
$mform->addElement('advcheckbox', 'config_showpast', $name, '', array('group' => 1), array(0, 1));
$mform->addElement('advcheckbox', 'config_showpast', $name, '', ['group' => 1], [0, 1]);
$mform->setDefault('config_showpast', 0);

$name = get_string('showinprogress', 'block_overviewmyrolesincourses');
$mform->addElement('advcheckbox', 'config_showinprogress', $name, '', array('group' => 2), array(0, 1));
$mform->addElement('advcheckbox', 'config_showinprogress', $name, '', ['group' => 2], [0, 1]);
$mform->setDefault('config_showinprogress', 0);

$name = get_string('showfuture', 'block_overviewmyrolesincourses');
$mform->addElement('advcheckbox', 'config_showfuture', $name, '', array('group' => 3), array(0, 1));
$mform->addElement('advcheckbox', 'config_showfuture', $name, '', ['group' => 3], [0, 1]);
$mform->setDefault('config_showfuture', 0);

$name = get_string('onlyfavourite', 'block_overviewmyrolesincourses');
$mform->addElement('advcheckbox', 'config_onlyfavourite', $name, '', array('group' => 4), array(0, 1));
$mform->addElement('advcheckbox', 'config_onlyfavourite', $name, '', ['group' => 4], [0, 1]);
$mform->setDefault('config_onlyfavourite', 0);

$name = get_string('foldonstart', 'block_overviewmyrolesincourses');
$mform->addElement('advcheckbox', 'config_foldonstart', $name, '', array('group' => 5), array(0, 1));
$mform->addElement('advcheckbox', 'config_foldonstart', $name, '', ['group' => 5], [0, 1]);
$mform->setDefault('config_foldonstart', 0);
}
}
2 changes: 2 additions & 0 deletions lang/en/block_overviewmyrolesincourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
$string['defaultshowinprogress_desc'] = 'By default show courses in progress';
$string['defaultshowfuture'] = 'Default: Show future';
$string['defaultshowfuture_desc'] = 'By default show courses that start in future';
$string['defaultonlyshowfavourite'] = 'Default: Favorites only';
$string['defaultonlyshowfavourite_desc'] = 'By default show only favourite courses';
$string['foldonstart'] = 'Fold courselists on start';
$string['future'] = 'future';
$string['inprogress'] = 'in progress';
Expand Down
3 changes: 1 addition & 2 deletions privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
16 changes: 12 additions & 4 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$settings = new admin_settingpage( 'block_overviewmyrolesincourses', get_string('pluginname', 'block_overviewmyrolesincourses') );
$settings = new admin_settingpage('block_overviewmyrolesincourses', get_string('pluginname', 'block_overviewmyrolesincourses'));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox(
'block_overviewmyrolesincourses/isactiv',
Expand All @@ -47,10 +47,13 @@
$rolename->localname;
}
}
$settings->add(new admin_setting_configmultiselect('block_overviewmyrolesincourses/supportedroles',
$settings->add(new admin_setting_configmultiselect(
'block_overviewmyrolesincourses/supportedroles',
get_string('supportedroles', 'block_overviewmyrolesincourses'),
get_string('supportedroles_desc', 'block_overviewmyrolesincourses'),
array_keys($options), $options));
array_keys($options),
$options
));

$settings->add(new admin_setting_configcheckbox(
'block_overviewmyrolesincourses/showdeleteicon',
Expand Down Expand Up @@ -83,5 +86,10 @@
get_string('defaultfoldonstart_desc', 'block_overviewmyrolesincourses'),
0
));

$settings->add(new admin_setting_configcheckbox(
'block_overviewmyrolesincourses/defaultonlyshowfavourite',
get_string('defaultonlyshowfavourite', 'block_overviewmyrolesincourses'),
get_string('defaultonlyshowfavourite_desc', 'block_overviewmyrolesincourses'),
0
));
}
11 changes: 3 additions & 8 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
padding-left: 5px;
}
.overviewmyrolesincourses-foldonstart {
display: none;
}
display: none;
}

.row.duration {
margin-left: 0px;
margin-left: 0;
}
.row.duration .col-8 {
padding-left: 0;
Expand All @@ -64,11 +64,6 @@
padding-right: 10px;
}






.overviewmyrolesincourses-tools {
text-align: right;
}
Expand Down
12 changes: 6 additions & 6 deletions templates/overviewmyrolesincourses.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"coursefullname": "Mathe fractions xxx",
"visible": "1",
"favourite": true,
"url": {},
"urldelete": {},
"url": "",
"urldelete": "",
"dimmed": "",
"duration": "19\/08\/30 - 19\/08\/40",
"cssselectordurationstatusofcourse": "overviewmyrolesincourses-coursefuture",
Expand All @@ -47,8 +47,8 @@
"coursefullname": "Activities (plugins)",
"visible": "1",
"favourite": true,
"url": {},
"urldelete": {},
"url": "",
"urldelete": "",
"dimmed": "",
"duration": "23\/07\/21 - 24\/07\/23",
"cssselectordurationstatusofcourse": "overviewmyrolesincourses-courseinprogress",
Expand All @@ -63,8 +63,8 @@
"coursefullname": "Testing filters",
"visible": "0",
"favourite": true,
"url": {},
"urldelete": {},
"url": "",
"urldelete": "",
"dimmed": "dimmed",
"duration": "23\/07\/21 - 24\/07\/22",
"cssselectordurationstatusofcourse": "overviewmyrolesincourses-coursefinished",
Expand Down

0 comments on commit 1f699c5

Please sign in to comment.