Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to main for 7.0.0 release #11

Merged
merged 8 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ on: [push, pull_request]

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

services:
postgres:
image: postgres:10
image: postgres:13.0
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.5
image: mariadb:10.6.7
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
Expand All @@ -28,15 +28,30 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_402_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_311_STABLE'
database: pgsql
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_310_STABLE'
database: mariadb
- php: '7.3'
moodle-branch: 'MOODLE_39_STABLE'
database: pgsql
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'

steps:
- name: Check out repository code
Expand Down
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 7.0.0 ###

* New maintainer: bdecent gmbh.
* Behat and PHPUnit tests updated and tested on Moodle 4.1 - 4.3.
* Fixed minor coding style issues.
* Added monologo for Moodle 4.x.
* Fixed improper use of require_login method instead of require_course_login (resolves #10).
* New feature: Display block content on course page (based on work by Harald, David und Nicklas @devcamp19 — Thanks!).

### 6.0.1 ###

* Behat and PHPUnit tests updated and tested on Moodle 3.9 - 3.11.
Expand Down
7 changes: 3 additions & 4 deletions backup/moodle2/backup_poster_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

/**
* Provides the definition of the backup structure
Expand All @@ -44,11 +43,11 @@ class backup_poster_activity_structure_step extends backup_activity_structure_st
protected function define_structure() {

// Define the poster root element.
$poster = new backup_nested_element('poster', array('id'), array(
'name', 'intro', 'introformat', 'timecreated', 'timemodified', 'shownameview', 'showdescriptionview'));
$poster = new backup_nested_element('poster', ['id'], ['name', 'intro',
'introformat', 'timecreated', 'timemodified', 'shownameview', 'showdescriptionview', 'display', ]);

// Define the data source.
$poster->set_source_table('poster', array('id' => backup::VAR_ACTIVITYID));
$poster->set_source_table('poster', ['id' => backup::VAR_ACTIVITYID]);

// Define file annotations.
$poster->annotate_files('mod_poster', 'intro', null);
Expand Down
6 changes: 3 additions & 3 deletions backup/moodle2/restore_poster_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ protected function define_my_steps() {
* @return array of restore_decode_content
*/
public static function define_decode_contents() {
return array(new restore_decode_content('poster', array('intro'), 'poster'));
return [new restore_decode_content('poster', ['intro'], 'poster')];
}

/**
* Defines the decoding rules for links belonging to the activity to be executed by the link decoder.
*/
public static function define_decode_rules() {
return array(
return [
new restore_decode_rule('POSTERINDEX', '/mod/poster/index.php?id=$1', 'course'),
new restore_decode_rule('POSTERVIEWBYID', '/mod/poster/view.php?id=$1', 'course_module'),
);
];
}
}
4 changes: 1 addition & 3 deletions backup/moodle2/restore_poster_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

/**
* Structure step to restore poster activity instance.
*
Expand All @@ -39,7 +37,7 @@ class restore_poster_activity_structure_step extends restore_activity_structure_
* @return array of restore_path_element
*/
protected function define_structure() {
return $this->prepare_activity_structure(array(new restore_path_element('poster', '/activity/poster')));
return $this->prepare_activity_structure([new restore_path_element('poster', '/activity/poster')]);
}

/**
Expand Down
1 change: 0 additions & 1 deletion classes/event/course_module_instance_list_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

namespace mod_poster\event;

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

/**
* Class of the mod_poster instances list viewed events.
Expand Down
2 changes: 0 additions & 2 deletions classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace mod_poster\event;

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

/**
* Class of the mod_poster course module viewed events.
*
Expand Down
122 changes: 122 additions & 0 deletions classes/poster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?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/>.

/**
* Define poster class.
* @package mod_poster
* @copyright bdecent gmbh 2023 <info@bdecent.de>
* based on the work by
* 2015 David Mudrak <david@moodle.com> and
* 2019 Harald, David und Nicklas @devcamp19
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_poster;

use mod_poster\event\course_module_viewed;
use completion_info;

/**
* Class poster
*
* @package mod_poster
*/
class poster {

/**
* @var mixed|object|false fetched from get_record.
*/
protected $settings;

/**
* @var mixed course fetched from DB.
*/
protected $course;

/**
* @var \cm_info
*/
protected $cm;

/**
* poster constructor.
*
* @param \cm_info|\stdClass $cm
* @throws \dml_exception
*/
public function __construct($cm) {
global $DB;
$this->settings = $DB->get_record('poster', ['id' => $cm->instance], '*', MUST_EXIST);
$this->course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
$this->cm = $cm;
}

/**
* Get settings saved in DB for the poster module.
*
* @return false|mixed|object
*/
public function get_settings() {
return $this->settings;
}

/**
* Get course settings.
*
* @return false|mixed|object
*/
public function get_course() {
return $this->course;
}

/**
* Set up the page for displaying the content.
*
* @param \moodle_page $page
*/
public function setup_page(\moodle_page &$page) {
$page->set_url('/mod/poster/view.php', ['id' => $this->cm->id]);
$page->set_title($this->course->shortname.': '.$this->settings->name);
$page->set_heading($this->course->fullname);
$page->set_activity_record($this->settings);
// Define the custom block regions we want to use at the poster view page.
// Region names are limited to 16 characters.
$page->blocks->add_region('mod_poster-pre', true);
$page->blocks->add_region('mod_poster-post', true);
}

/**
* Trigger module view.
* @param \context $context
*/
public function trigger_module_viewed(\context $context) {
// Trigger module viewed event.
$event = course_module_viewed::create([
'objectid' => $this->settings->id,
'context' => $context,
]);
$event->add_record_snapshot('course_modules', $this->cm);
$event->add_record_snapshot('course', $this->course);
$event->add_record_snapshot('poster', $this->settings);
$event->trigger();

// Mark the module instance as viewed by the current user.
$completion = new completion_info($this->course);
$completion->set_module_viewed($this->cm);
}

}
2 changes: 0 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace mod_poster\privacy;

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

/**
* Privacy API implementation for the Poster plugin.
*
Expand Down
26 changes: 13 additions & 13 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@

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

$capabilities = array(
$capabilities = [

// Ability to add instance of the module to the course.
'mod/poster:addinstance' => array(
'mod/poster:addinstance' => [
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/course:manageactivities'
),
'manager' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/course:manageactivities',
],

// Ability to view the poster instance.
'mod/poster:view' => array(
'mod/poster:view' => [
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'archetypes' => [
'guest' => CAP_ALLOW,
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
);
'manager' => CAP_ALLOW,
],
],
];
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="shownameview" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Display the poster name as a heading title of the view page"/>
<FIELD NAME="showdescriptionview" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Display the intro description at the view page"/>
<FIELD NAME="display" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Display type of poster contents - on a separate page or inline"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
14 changes: 12 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

/**
* Performs the poster upgrade steps.
*
Expand All @@ -36,5 +34,17 @@ function xmldb_poster_upgrade($oldversion) {

$dbman = $DB->get_manager();

if ($oldversion < 2023112701) {
// Add new fields to poster table.
$table = new xmldb_table('poster');
$field = new xmldb_field('display');
$field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'showdescriptionview');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Poster savepoint reached.
upgrade_mod_savepoint(true, 2023112701, 'poster');
}
return true;
}
Loading
Loading