Commit 3505d1f8 authored by Plugins bot's avatar Plugins bot
Browse files

PLUGIN-25757 availability_coursecompleted: cibot precheck request

parent 3105d5bc
name: Cron
on:
schedule:
- cron: "5 10 9 * *"
jobs:
ci:
name: ci
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
moodle-branch: ['master']
php: ['8.0']
database: ['mysqli']
steps:
- name: checkout plugin
uses: actions/checkout@v2
with:
path: this-plugin
- name: setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, mysqli, gd, zip
coverage: xdebug
- name: composer
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
sed -i 's/phpdbg -d memory_limit=-1 -qrr//g' ci/src/Command/PHPUnitCommand.php
sudo systemctl start mysql.service
- name: install Moodle
run: moodle-plugin-ci install -v --db-user=root --db-pass=root --db-host=127.0.0.1 --plugin this-plugin
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
- name: phplint
if: ${{ always() }}
run: moodle-plugin-ci --ansi phplint
- name: phpcpd
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpcpd
- name: phpmd
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpmd
- name: phpdoc
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpdoc
- name: codechecker
if: ${{ always() }}
run: moodle-plugin-ci --ansi codechecker
- name: validate
if: ${{ always() }}
run: moodle-plugin-ci --ansi validate
- name: savepoints
if: ${{ always() }}
run: moodle-plugin-ci --ansi savepoints
- name: grunt
if: ${{ always() }}
run: moodle-plugin-ci --ansi grunt
- name: mustache
if: ${{ always() }}
run: moodle-plugin-ci --ansi mustache
- name: phpunit
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpunit --coverage-text --coverage-clover
- name: behat
if: ${{ always() }}
run: moodle-plugin-ci --ansi behat --profile=chrome
- name: admin bookmarks
if: ${{ always() }}
run: php admin/tool/behat/cli/run.php --tags=@block_admin_bookmarks --suite=${{ matrix.suite }}
working-directory: moodle
- name: privacy
if: ${{ always() }}
run: vendor/bin/phpunit --colors --no-coverage --testsuite tool_dataprivacy_testsuite,tool_policy_testsuite,core_privacy_testsuite
working-directory: moodle
- name: coveralls
env:
COVERALLS_RUN_LOCALLY: true
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: moodle-plugin-ci --ansi coveralls-upload
name: Tests
on: [push, pull_request]
jobs:
ci:
name: ci
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: --health-cmd="pg_isready" --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 5432:5432
mariadb:
image: mariadb:10.5
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
ports:
- 3306:3306
strategy:
fail-fast: false
matrix:
moodle-branch: ['master', 'MOODLE_311_STABLE']
php: ['8.0', '7.4']
database: ['mariadb', 'pgsql']
include:
- php: 7.4
moodle-branch: MOODLE_310_STABLE
database: mariadb
- php: 7.4
moodle-branch: MOODLE_39_STABLE
database: mariadb
steps:
- name: checkout plugin
uses: actions/checkout@v2
with:
path: this-plugin
- name: setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, pgsql, mysqli, gd, xmlrpc, zip
ini-values: max_input_vars=5000
coverage: xdebug
- name: composer
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
sed -i 's/phpdbg -d memory_limit=-1 -qrr//g' ci/src/Command/PHPUnitCommand.php
- name: install Moodle
run: moodle-plugin-ci --ansi install --db-host=127.0.0.1 --plugin this-plugin
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
- name: phplint
if: ${{ always() }}
run: moodle-plugin-ci --ansi phplint
- name: phpcpd
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpcpd
- name: phpmd
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpmd
- name: phpdoc
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpdoc
- name: codechecker
if: ${{ always() }}
run: moodle-plugin-ci --ansi codechecker
- name: validate
if: ${{ always() }}
run: moodle-plugin-ci --ansi validate
- name: savepoints
if: ${{ always() }}
run: moodle-plugin-ci --ansi savepoints
- name: grunt
if: ${{ always() }}
run: moodle-plugin-ci --ansi grunt
- name: mustache
if: ${{ always() }}
run: moodle-plugin-ci --ansi mustache
- name: phpunit
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpunit --coverage-text --coverage-clover
- name: firefox
if: ${{ always() }}
run: moodle-plugin-ci --ansi behat
- name: chrome
if: ${{ always() }}
run: moodle-plugin-ci --ansi behat --profile chrome
- name: firefox classic
if: ${{ always() }}
run: moodle-plugin-ci --ansi behat --suite="classic"
- name: chrome classic
if: ${{ always() }}
run: moodle-plugin-ci --ansi behat --suite="classic" --profile chrome
- name: admin bookmarks
if: ${{ always() }}
run: php admin/tool/behat/cli/run.php --tags=@block_admin_bookmarks --suite=${{ matrix.suite }}
working-directory: moodle
- name: privacy
if: ${{ always() }}
run: vendor/bin/phpunit --colors --no-coverage --testsuite tool_dataprivacy_testsuite,tool_policy_testsuite,core_privacy_testsuite
working-directory: moodle
- name: coveralls
env:
COVERALLS_RUN_LOCALLY: true
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: moodle-plugin-ci --ansi coveralls-upload
name: Releasing in the Plugins directory
on:
push:
tags:
- v*
workflow_dispatch:
inputs:
tag:
description: 'Tag to be released'
required: true
defaults:
run:
shell: bash
jobs:
release-at-moodle-org:
runs-on: ubuntu-latest
env:
PLUGIN: availability_coursecompleted
CURL: curl -s
ENDPOINT: https://moodle.org/webservice/rest/server.php
TOKEN: ${{ secrets.MOODLE_ORG_TOKEN }}
FUNCTION: local_plugins_add_version
steps:
- name: Call the service function
id: add-version
run: |
if [[ ! -z "${{ github.event.inputs.tag }}" ]]; then
TAGNAME="${{ github.event.inputs.tag }}"
elif [[ $GITHUB_REF = refs/tags/* ]]; then
TAGNAME="${GITHUB_REF##*/}"
fi
if [[ -z "${TAGNAME}" ]]; then
echo "No tag name has been provided!"
exit 1
fi
ZIPURL="https://api.github.com/repos/${{ github.repository }}/zipball/${TAGNAME}"
RESPONSE=$(${CURL} ${ENDPOINT} --data-urlencode "wstoken=${TOKEN}" \
--data-urlencode "wsfunction=${FUNCTION}" \
--data-urlencode "moodlewsrestformat=json" \
--data-urlencode "frankenstyle=${PLUGIN}" \
--data-urlencode "zipurl=${ZIPURL}" \
--data-urlencode "vcssystem=git" \
--data-urlencode "vcsrepositoryurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
--data-urlencode "vcstag=${TAGNAME}" \
--data-urlencode "changelogurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAGNAME}" \
--data-urlencode "altdownloadurl=${ZIPURL}")
echo "::set-output name=response::${RESPONSE}"
- name: Evaluate the response
id: evaluate-response
env:
RESPONSE: ${{ steps.add-version.outputs.response }}
run: |
jq <<< ${RESPONSE}
jq --exit-status ".id" <<< ${RESPONSE} > /dev/null
{
"name": "moodle-availability_coursecompletion"
}
{
"coverage": false,
"lint": "config",
"clean": true
}
This diff is collapsed.
moodle-availability_coursecompleted
==============================================
Restrict module and section access based on course completion.
This availability condition makes it easy to show modules or sections only when a user
completed a course. A course certificate is a good sample, but it can also be used to close
discussion forums, hide quizes or exams when a user finished a course.
Check the global documentation about availability conditions : https://docs.moodle.org/en/Conditional_activities_settings
Installation:
1. Unpack the zip file into the availability/condition/ directory. A new directory will be created called coursecompleted.
2. Go to Site administration > Notifications to complete the plugin installation.
[![Build Status](https://github.com/ewallah/moodle-availability_coursecompleted/workflows/Tests/badge.svg)](https://github.com/ewallah/moodle-availability_coursecompleted/actions)
[![Coverage Status](https://coveralls.io/repos/github/ewallah/moodle-availability_coursecompleted/badge.svg?branch=main)](https://coveralls.io/github/ewallah/moodle-availability_coursecompleted?branch=main)
<?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/>.
/**
* Condition main class.
*
* @package availability_coursecompleted
* @copyright 2015 iplusacademy (www.iplusacademy.org)
* @author Renaat Debleu <info@eWallah.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace availability_coursecompleted;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/completionlib.php');
/**
* Condition main class.
*
* @package availability_coursecompleted
* @copyright 2015 iplusacademy (www.iplusacademy.org)
* @author Renaat Debleu <info@eWallah.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class condition extends \core_availability\condition {
/** @var string coursecompleted 0 => No, 1 => Yes */
protected $coursecompleted;
/**
* Constructor.
*
* @param \stdClass $structure Data structure from JSON decode
* @throws \coding_exception If invalid data.
*/
public function __construct($structure) {
if (!property_exists($structure, 'id')) {
$this->coursecompleted = '';
} else if (is_string($structure->id)) {
$this->coursecompleted = $structure->id;
} else {
throw new \coding_exception('Invalid value for course completed condition');
}
}
/**
* Saves tree data back to a structure object.
*
* @return \stdClass Structure object (ready to be made into JSON format)
*/
public function save() {
return (object)['type' => 'coursecompleted', 'id' => $this->coursecompleted];
}
/**
* Returns a JSON object which corresponds to a condition of this type.
*
* Intended for unit testing, as normally the JSON values are constructed
* by JavaScript code.
*
* @param string $coursecompleted default empty string
* @return stdClass Object representing condition
*/
public static function get_json($coursecompleted = '') {
return (object)['type' => 'coursecompleted', 'id' => $coursecompleted];
}
/**
* Determines whether a particular item is currently available
* according to this availability condition.
*
* @param bool $not Set true if we are inverting the condition
* @param \core_availability\info $info Item we're checking
* @param bool $grabthelot Performance hint: if true, caches information
* required for all course-modules, to make the front page and similar
* pages work more quickly (works only for current user)
* @param int $userid User ID to check availability for
* @return bool True if available
*/
public function is_available($not, \core_availability\info $info, $grabthelot, $userid) {
global $USER;
$completioninfo = new \completion_info($info->get_course());
$allow = $completioninfo->is_course_complete($userid != $USER->id ? $userid : $USER->id);
if (!$this->coursecompleted) {
$allow = !$allow;
}
if ($not) {
$allow = !$allow;
}
return $allow;
}
/**
* Obtains a string describing this restriction (whether or not
* it actually applies). Used to obtain information that is displayed to
* students if the activity is not available to them, and for staff to see
* what conditions are.
*
* @param bool $full Set true if this is the 'full information' view
* @param bool $not Set true if we are inverting the condition
* @param \core_availability\info $info Item we're checking
* @return string Information string (for admin) about all restrictions on
* this item
*/
public function get_description($full, $not, \core_availability\info $info) {
$allow = $this->coursecompleted;
if ($not) {
$allow = !$allow;
}
return get_string($allow ? 'getdescription' : 'getdescriptionnot', 'availability_coursecompleted');
}
/**
* Obtains a representation of the options of this condition as a string,
* for debugging.
*
* @return string Text representation of parameters
*/
protected function get_debug_string() {
return $this->coursecompleted ? '#' . 'True' : 'False';
}
}
<?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/>.
/**
* Front-end class.
*
* @package availability_coursecompleted
* @copyright 2015 iplusacademy (www.iplusacademy.org)
* @author Renaat Debleu <info@eWallah.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace availability_coursecompleted;
defined('MOODLE_INTERNAL') || die();
/**
* Front-end class.
*
* @package availability_coursecompleted
* @copyright 2015 iplusacademy (www.iplusacademy.org)
* @author Renaat Debleu <info@eWallah.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class frontend extends \core_availability\frontend {
/**
* Decides whether this plugin should be available in a given course. The
* plugin can do this depending on course or system settings.
*
* @param \stdClass $course Course object
* @param \cm_info $cm Course-module currently being edited (null if none)
* @param \section_info $section Section currently being edited (null if Course object)
* @return bool True if there are completion criteria
*/
protected function allow_add($course, \cm_info $cm = null, \section_info $section = null) {
return $course->enablecompletion == 1;
}
}
<?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/>.
/**
* Privacy main class.
*
* @package availability_coursecompleted
* @copyright 2017 iplusacademy (www.iplusacademy.org)
* @author Renaat Debleu <info@eWallah.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace availability_coursecompleted\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy main class.
*
* @package availability_coursecompleted
* @copyright 2017 iplusacademy (www.iplusacademy.org)
* @author Renaat Debleu <info@eWallah.net>
* @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 {
return 'privacy:metadata';
}
}
<?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/>.
/**
* Language strings.