Skip to content
Open
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
77 changes: 37 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,90 @@ on: [push, pull_request]

jobs:
test:
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
matrix:
include:
- php: '7.4'
moodle-branch: 'master'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
runs-on: ubuntu-latest

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

options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
mariadb:
image: 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: ['8.2', '8.3']
moodle-branch: ['main']
database: [pgsql, mariadb]

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

- name: Setup PHP
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, pgsql, mysqli
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
coverage: none

- name: Deploy moodle-plugin-ci
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
# Add dirs to $PATH
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
# PHPUnit depends on en_AU.UTF-8 locale
sudo locale-gen en_AU.UTF-8

- name: Install Moodle
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: phplint
- name: PHP Lint
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: phpcpd
- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpcpd || true
run: moodle-plugin-ci phpmd

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

- name: codechecker
- name: Moodle PHPDoc Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker
run: moodle-plugin-ci phpdoc

- name: validate
- name: Validating
if: ${{ always() }}
run: moodle-plugin-ci validate

- name: savepoints
- name: Check upgrade savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints

- name: mustache
- name: Mustache Lint
if: ${{ always() }}
run: moodle-plugin-ci mustache

Expand Down
47 changes: 37 additions & 10 deletions blocks/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;


/**
* Example {@link report_editdates_block_date_extractor} subclass.
* Example {report_editdates_block_date_extractor} subclass.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand All @@ -40,25 +37,55 @@ class report_editdates_block_html_date_extractor extends report_editdates_block
* Constructor.
* @param object $course course settings from the DB.
*/
/**
* Constructor for the assignment date extractor.
*
* Initializes the date extractor for assignment modules by invoking
* the parent constructor with the course and 'assignment' as the module type.
* Additionally, it loads necessary data related to the assignments.
*
* @param stdClass $course The course object.
*/
public function __construct($course) {
parent::__construct($course, 'html');
parent::load_data();
}

/**
* Return an array of settings for the dates that we handle.
*
* This function takes in the course module information and returns an associative array
* of date settings for the module. The keys of the returned array are the string names
* of the settings, and the values are objects of the report_editdates_date_setting class.
*
* @param block_base $block the block to get the settings for.
* @return array an associative array of date settings for the block.
*/
public function get_settings(block_base $block) {
// Check if title text is a valid date then return the array.
$title = $block->title;
if ((string) (int) $title === $title) {
return array('title' => new report_editdates_date_setting
(get_string('availabledate', 'assignment'),
$block->title,
self::DATETIME, false, 5)
);
return [
'title' => new report_editdates_date_setting(get_string('availabledate', 'assignment'),
$block->title,
self::DATETIME, false, 5),
];
}
}

/**
* Validate the submitted dates for this course_module instance.
*
* This function takes in the course module information and an associative array of date
* settings and returns an associative array of validation errors. The keys of the returned
* array are the same as the keys of the input array, and the values are error strings.
*
* @param block_base $block the block to validate the dates for.
* @param array $dates an associative array of date settings for the block.
* @return array an associative array of validation errors.
*/
public function validate_dates(block_base $block, array $dates) {
$errors = array();
$errors = [];
if ($dates['title'] == 0 ) {
$errors['title'] = get_string('datemustnotzero', 'report_editdates');
}
Expand Down
23 changes: 1 addition & 22 deletions classes/event/report_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

namespace report_editdates\event;

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

/**
*
* @package report_editdates
Expand Down Expand Up @@ -72,30 +70,11 @@ public static function get_name() {
* @return \moodle_url
*/
public function get_url() {
$params = array('id' => $this->courseid);
$params = ['id' => $this->courseid];
if ($this->other['activitytype']) {
$params['activitytype'] = $this->other['activitytype'];
}
return new \moodle_url('/report/editdates/index.php', $params);
}

public static function get_legacy_eventname() {
return 'report edit dates';
}

/**
* Return the legacy event log data.
*
* @return array|null
*/
protected function get_legacy_logdata() {
return array(
$this->courseid,
"course",
"report edit dates",
"report/editdates/index.php?id={$this->courseid}",
$this->contextinstanceid
);
}

}
6 changes: 4 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Privacy Subsystem implementation for report_editdates.
*
* @package report_editdates
* @copyright 2018 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace report_editdates\privacy;
defined('MOODLE_INTERNAL') || die();

/**
* Privacy Subsystem for report_editdates implementing null_provider.
*
Expand All @@ -35,7 +37,7 @@ class provider implements \core_privacy\local\metadata\null_provider {
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
14 changes: 7 additions & 7 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

defined('MOODLE_INTERNAL') || die;

$capabilities = array(
'report/editdates:view' => array(
$capabilities = [
'report/editdates:view' => [
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'manager' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/site:viewreports',
)
);
],
];
30 changes: 24 additions & 6 deletions db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,26 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;

/**
* Upgrades the editdates plugin after install.
*
* This function is needed when a site is upgrading from a version of Moodle
* that had the old 'coursereport_editdates' plugin. It is needed even if the
* site is not using the editdates plugin, because some things need to be
* fixed in the database.
*
* The first part of this function is a hack to copy the permission from the
* old place, if they were present. If this report is installed into a new
* Moodle, we just do what it says in access.php and clone the permissions
* from moodle/site:viewreports, but if we are upgrading a Moodle that had the
* old course report plugin installed, then we get rid of the new cloned
* capabilities, and transfer the old permissions.
*
* The second part of this function is a hack which is needed for cleanup of
* original coursereport_completion stuff.
*
* The third part of this function is a hack to update existing block page patterns.
*/
function xmldb_report_editdates_install() {
global $DB;

Expand All @@ -32,10 +50,10 @@ function xmldb_report_editdates_install() {
// and clone the permissions from moodle/site:viewreports, but if we are upgrading
// a Moodle that had the old course report plugin installed, then we get rid of the
// new cloned capabilities, and transfer the old permissions.
if ($DB->record_exists('role_capabilities', array('capability' => 'coursereport/editdates:view'))) {
$DB->delete_records('role_capabilities', array('capability' => 'report/editdates:view'));
if ($DB->record_exists('role_capabilities', ['capability' => 'coursereport/editdates:view'])) {
$DB->delete_records('role_capabilities', ['capability' => 'report/editdates:view']);
$DB->set_field('role_capabilities', 'capability', 'report/editdates:view',
array('capability' => 'coursereport/editdates:view'));
['capability' => 'coursereport/editdates:view']);
}

// This is a hack which is needed for cleanup of original coursereport_completion stuff.
Expand All @@ -44,6 +62,6 @@ function xmldb_report_editdates_install() {

// Update existing block page patterns.
$DB->set_field('block_instances', 'pagetypepattern', 'report-editdates-index',
array('pagetypepattern' => 'course-report-editdates-index'));
['pagetypepattern' => 'course-report-editdates-index']);
}

Loading