Skip to content

Commit

Permalink
Finish the first implementation of the plugin
Browse files Browse the repository at this point in the history
* Unit test
* Form and basic fields
  • Loading branch information
laurentdavid committed Nov 29, 2023
1 parent 187245d commit 8897c98
Show file tree
Hide file tree
Showing 12 changed files with 647 additions and 106 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Moodle Plugin CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-22.04

services:
postgres:
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: ['8.1']
moodle-branch: ['MOODLE_403_STABLE']
database: [pgsql, mariadb]

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

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
# If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug".
# If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems).
coverage: none

- name: Initialise moodle-plugin-ci
run: |
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
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: PHP Lint
if: ${{ !cancelled() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpcpd

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

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

- name: Moodle PHPDoc Checker
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpdoc --max-warnings 0

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

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

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

- name: Grunt
if: ${{ !cancelled() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpunit --fail-on-warning

- name: Behat features
if: ${{ !cancelled() }}
run: moodle-plugin-ci behat --profile chrome

- name: Mark cancelled jobs as failed.
if: ${{ cancelled() }}
run: exit 1
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ BigblueButton Extension - FlexURL
* Copyright: Blindside Networks Inc
* License: GNU GENERAL PUBLIC LICENSE Version 3

This is an extension plugin for BigBluebButtonBN module that will allow you to some parameters dynamically
to the create and join URL. This is sometimes needed for specific BigBlueButton integrations.
This is an extension plugin for the BigBlueButtonBN module. This will allow user to add parameters to a create and join action url, so to
be able to address a variety of use cases.
For now the parameters are not "free forms" but fixed on entities like user, course and module so to be able to address the most common use cases while
keeping some control on the parameters that are passed to the BigBlueButton server.


Description
===========
This plugin shows how to extend BigBluebButtonBN module to:
* Add a new parameter to an Action URL (create and join)
* Setup a new parameter in the BigBlueButtonBN module settings (and edit form)


Installation
Expand Down
12 changes: 8 additions & 4 deletions backup/moodle2/backup_bbbext_flexurl_subplugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ protected function define_bigbluebuttonbn_subplugin_structure() {
// Create XML elements.
$subplugin = $this->get_subplugin_element();
$subpluginwrapper = new backup_nested_element($this->get_recommended_name());
$subpluginelement = new backup_nested_element('bbbext_flexurl',
$subpluginelement = new backup_nested_element(
'bbbext_flexurl',
null,
['additionalparams']);
['eventtype', 'paramname', 'paramvalue']
);

// Connect XML elements into the tree.
$subplugin->add_child($subpluginwrapper);
$subpluginwrapper->add_child($subpluginelement);

// Set source to populate the data.
$subpluginelement->set_source_table('bbbext_flexurl',
['bigbluebuttonbnid' => backup::VAR_PARENTID]);
$subpluginelement->set_source_table(
'bbbext_flexurl',
['bigbluebuttonbnid' => backup::VAR_PARENTID]
);

return $subplugin;
}
Expand Down
2 changes: 0 additions & 2 deletions backup/moodle2/restore_bbbext_flexurl_subplugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ class restore_bbbext_flexurl_subplugin extends restore_subplugin {
* @return array
*/
protected function define_bigbluebuttonbn_subplugin_structure() {

$paths = [];

$elename = $this->get_namefor('bigbluebuttonbn');
// We used get_recommended_name() so this works.
$elepath = $this->get_pathfor('/bbbext_flexurl');

$paths[] = new restore_path_element($elename, $elepath);

return $paths;
}

Expand Down
40 changes: 18 additions & 22 deletions classes/bigbluebuttonbn/action_url_addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace bbbext_flexurl\bigbluebuttonbn;

use bbbext_flexurl\utils;
use core_form\util;
use mod_bigbluebuttonbn\instance;

/**
* A single action class to mutate the action URL.
*
Expand All @@ -36,31 +40,23 @@ class action_url_addons extends \mod_bigbluebuttonbn\local\extension\action_url_
* 'metadata' keys)
*/
public function execute(string $action = '', array $data = [], array $metadata = [], ?int $instanceid = null): array {
if ($action == 'create') {
$analyticcburl = get_config('bbbext_flexurl', 'analytics_callback_url');
if ($analyticcburl) {
$metadata['analytics-callback-url'] = $analyticcburl;
}
}
if ($action == 'create' || $action == 'join') {
if (empty($instanceid)) {
if (!(defined('PHPUNIT_TEST') && PHPUNIT_TEST) && !defined('BEHAT_SITE_RUNNING')) {
// Debugging messages will fail mod_bigbluebuttonbn behat or phpunit tests as soon as the plugin is installed.
// Which is not what we want here.
debugging('No instanceid provided to action_url_addons, this mean we will not be able to retrieve any' .
'instance specific data in the subplugins.');
}
} else {
global $DB;
$record = $DB->get_record(mod_instance_helper::SUBPLUGIN_TABLE, [
'bigbluebuttonbnid' => $instanceid,
]);
if ($record) {
$metadata['additionalparams'] = $record->additionalparams ?? '';
global $DB;
if ($instanceid) {
$instance = instance::get_from_instanceid($instanceid);
$flexurlrecords = $DB->get_records(mod_instance_helper::SUBPLUGIN_TABLE, [
'bigbluebuttonbnid' => $instanceid,
]);
$eventtypes = array_flip(utils::ACTION_CODES);
foreach ($flexurlrecords as $flexurlrecord) {
if ($flexurlrecord->eventtype != utils::ACTION_CODES['all'] &&
$eventtypes[$flexurlrecord->eventtype] != $action) {
continue;
}

$metadata[$flexurlrecord->paramname] = utils::get_value_for_field($flexurlrecord->paramvalue, $instance);

}
}

return ['data' => $data, 'metadata' => $metadata];
}
}
Loading

0 comments on commit 8897c98

Please sign in to comment.