Skip to content

Add Docker Support and Makefile for Development, Linting, and Fixing #14

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

Merged
merged 20 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3555d24
feat: implement proxy for exeonlinebaseuri to enhance security in Moo…
erseco Sep 27, 2024
50de89f
feat: add proxy functionality for exescorm module in Moodle
erseco Sep 27, 2024
ebdf3c2
fix: handle connection errors in proxy.php and set content type header
erseco Sep 27, 2024
a8c04bf
Initial proxy version
erseco Sep 27, 2024
918c697
Added makefile for easy management
erseco Oct 19, 2024
9834914
Added .env to .gitignore
erseco Oct 19, 2024
c0d3ff8
fix: Remove unused eslint-disable directive and fix CSS style issues
erseco Oct 20, 2024
33d636c
fix: Resolve HTML validation errors in Mustache templates by updating…
erseco Oct 20, 2024
459158d
fix: Correct PHPDoc tags and complete parameter lists in various files
erseco Oct 20, 2024
605768a
Some pipeline fixes and lint fixes
erseco Oct 20, 2024
12d0855
feat: Add composer.json for Moodle ExeSCORM plugin dependencies and s…
erseco Oct 20, 2024
7c53ca6
docs: Add English documentation for Composer commands in composer.json
erseco Oct 20, 2024
91546ae
chore: Add additional Makefile commands for dependency management and…
erseco Oct 20, 2024
ca3ec44
docs: Add documentation comments to Makefile commands
erseco Oct 20, 2024
c9eacd4
docs: Update Makefile help section with new Composer commands descrip…
erseco Oct 20, 2024
6a5c3ea
Some code fixes
erseco Oct 20, 2024
c7200f4
Disable temporary allowing using exelearninf from directory
erseco Oct 20, 2024
ef7553c
Pass the HOST_IP to moodle
erseco Oct 21, 2024
344177f
Set correct API key
erseco Oct 21, 2024
0e19131
Removed ip detection, unnedded
erseco Oct 22, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.1', '8.3']
php: ['8.1', '8.3']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_404_STABLE']
database: [pgsql, mariadb]

Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.aider*
.env

# mess detector rules
phpmd-rules.xml

# Composer ignores
/vendor/
/composer.lock
/composer.phar
122 changes: 122 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Makefile to facilitate the use of Docker in the exelearning-web project

# Detect the operating system and shell environment
ifeq ($(OS),Windows_NT)
# Initially assume Windows shell
SHELLTYPE := windows
# Check if we are in Cygwin or MSYS (e.g., Git Bash)
ifdef MSYSTEM
SHELLTYPE := unix
else ifdef CYGWIN
SHELLTYPE := unix
endif
else
SHELLTYPE := unix
endif

# Check if Docker is running
# This target verifies if Docker is installed and running on the system.
check-docker:
ifeq ($(SHELLTYPE),windows)
@echo "Detected system: Windows (cmd, powershell)"
@docker version > NUL 2>&1 || (echo. & echo Error: Docker is not running. Please make sure Docker is installed and running. & echo. & exit 1)
else
@echo "Detected system: Unix (Linux/macOS/Cygwin/MinGW)"
@docker version > /dev/null 2>&1 || (echo "" && echo "Error: Docker is not running. Please make sure Docker is installed and running." && echo "" && exit 1)
endif

# Check if the .env file exists, if not, copy from .env.dist
# This target ensures that the .env file is present by copying it from .env.dist if it doesn't exist.
check-env:
ifeq ($(SHELLTYPE),windows)
@if not exist .env ( \
echo The .env file does not exist. Copying from .env.dist... && \
copy .env.dist .env \
) 2>nul
else
@if [ ! -f .env ]; then \
echo "The .env file does not exist. Copying from .env.dist..."; \
cp .env.dist .env; \
fi
endif

# Start Docker containers in interactive mode
# This target builds and starts the Docker containers, allowing interaction with the terminal.
up: check-docker
docker compose up --build

# Start Docker containers in background mode (daemon)
# This target builds and starts the Docker containers in the background.
upd: check-docker
docker compose up -d

# Stop and remove Docker containers
# This target stops and removes all running Docker containers.
down: check-docker
docker compose down

# Pull the latest images from the registry
# This target pulls the latest Docker images from the registry.
pull: check-docker
docker compose -f docker-compose.yml pull

# Build or rebuild Docker containers
# This target builds or rebuilds the Docker containers.
build: check-docker
docker compose build

# Open a shell inside the moodle container
# This target opens an interactive shell session inside the running Moodle container.
shell: check-docker
docker compose exec moodle sh

# Clean up and stop Docker containers, removing volumes and orphan containers
# This target stops all containers and removes them along with their volumes and any orphan containers.
clean: check-docker
docker compose down -v --remove-orphans

# Install PHP dependencies using Composer
install-deps:
COMPOSER_ALLOW_SUPERUSER=1 composer install --no-interaction --prefer-dist --optimize-autoloader --no-progress

# Run code linting using Composer
lint:
composer lint

# Automatically fix code style issues using Composer
fix:
composer fix

# Run tests using Composer
test:
composer test

# Run PHP Mess Detector using Composer
phpmd:
composer phpmd

# Run Behat tests using Composer
behat:
composer behat
# Display help with available commands
# This target lists all available Makefile commands with a brief description.
help:
@echo "Available commands:"
@echo " up - Start Docker containers in interactive mode"
@echo " upd - Start Docker containers in background mode (daemon)"
@echo " down - Stop and remove Docker containers"
@echo " build - Build or rebuild Docker containers"
@echo " pull - Pull the latest images from the registry"
@echo " clean - Clean up and stop Docker containers, removing volumes and orphan containers"
@echo " shell - Open a shell inside the exelearning-web container"
@echo " install-deps - Install PHP dependencies using Composer"
@echo " lint - Run code linting using Composer"
@echo " fix - Automatically fix code style issues using Composer"
@echo " test - Run tests using Composer"
@echo " phpmd - Run PHP Mess Detector using Composer"
@echo " behat - Run Behat tests using Composer"
@echo " help - Display this help with available commands"


# Set help as the default goal if no target is specified
.DEFAULT_GOAL := help
22 changes: 11 additions & 11 deletions aicc.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

$cfgexescorm = get_config('exescorm');

$url = new moodle_url('/mod/exescorm/aicc.php', array('command' => $command, 'session_id' => $sessionid));
$url = new moodle_url('/mod/exescorm/aicc.php', ['command' => $command, 'session_id' => $sessionid]);
if ($aiccdata !== 0) {
$url->param('aicc_data', $aiccdata);
}
Expand All @@ -57,7 +57,7 @@
if (empty($exescormsession)) {
throw new \moodle_exception('invalidhacpsession', 'exescorm');
}
$aiccuser = $DB->get_record('user', array('id' => $exescormsession->userid), 'id,username,lastname,firstname', MUST_EXIST);
$aiccuser = $DB->get_record('user', ['id' => $exescormsession->userid], 'id,username,lastname,firstname', MUST_EXIST);
}

if (!empty($command)) {
Expand All @@ -83,7 +83,7 @@
}

if ($sco = exescorm_get_sco($scoid, EXESCORM_SCO_ONLY)) {
if (!$exescorm = $DB->get_record('exescorm', array('id' => $sco->exescorm))) {
if (!$exescorm = $DB->get_record('exescorm', ['id' => $sco->exescorm])) {
throw new \moodle_exception('cannotcallscript');
}
} else {
Expand All @@ -99,7 +99,7 @@
exescorm_debug_log_write("aicc", "HACP Request:\r\n$aiccrequest", $scoid);
ob_start();

if ($exescorm = $DB->get_record('exescorm', array('id' => $sco->exescorm))) {
if ($exescorm = $DB->get_record('exescorm', ['id' => $sco->exescorm])) {
switch ($command) {
case 'getparam':
if ($status == 'Not Initialized') {
Expand Down Expand Up @@ -233,7 +233,7 @@
$attempt, $element, $value);
break;
case 'cmi.core.lesson_status':
$statuses = array(
$statuses = [
'passed' => 'passed',
'completed' => 'completed',
'failed' => 'failed',
Expand All @@ -245,16 +245,16 @@
'f' => 'failed',
'i' => 'incomplete',
'b' => 'browsed',
'n' => 'not attempted'
);
$exites = array(
'n' => 'not attempted',
];
$exites = [
'logout' => 'logout',
'time-out' => 'time-out',
'suspend' => 'suspend',
'l' => 'logout',
't' => 'time-out',
's' => 'suspend',
);
];
$values = explode(',', $value);
$value = '';
if (count($values) > 1) {
Expand Down Expand Up @@ -402,11 +402,11 @@
case 'exitau':
if ($status == 'Running') {
if (isset($exescormsession->sessiontime) && ($exescormsession->sessiontime != '')) {
if ($track = $DB->get_record('exescorm_scoes_track', array("userid" => $aiccuser->id,
if ($track = $DB->get_record('exescorm_scoes_track', ["userid" => $aiccuser->id,
"exescormid" => $exescorm->id,
"scoid" => $sco->id,
"attempt" => $attempt,
"element" => 'cmi.core.total_time'))) {
"element" => 'cmi.core.total_time'])) {
// Add session_time to total_time.
$value = exescorm_add_time($track->value, $exescormsession->sessiontime);
$track->value = $value;
Expand Down
1 change: 1 addition & 0 deletions amd/src/fullscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ define([
'core/templates'
], function($, Str, Ajax, Templates) {
"use strict";
/* eslint-disable no-console */
/**
* @constructor
*/
Expand Down
60 changes: 30 additions & 30 deletions backup/moodle2/backup_exescorm_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// Define each element separated.
$exescorm = new backup_nested_element('exescorm', array('id'), array(
$exescorm = new backup_nested_element('exescorm', ['id'], [
'name', 'exescormtype', 'reference', 'intro',
'introformat', 'version', 'maxgrade', 'grademethod',
'whatgrade', 'maxattempt', 'forcecompleted', 'forcenewattempt',
Expand All @@ -47,56 +47,56 @@ protected function define_structure() {
'height', 'timeopen', 'timeclose', 'timemodified',
'completionstatusrequired', 'completionscorerequired',
'completionstatusallscos',
'autocommit'));
'autocommit']);

$scoes = new backup_nested_element('scoes');

$sco = new backup_nested_element('sco', array('id'), array(
$sco = new backup_nested_element('sco', ['id'], [
'manifest', 'organization', 'parent', 'identifier',
'launch', 'exescormtype', 'title', 'sortorder'));
'launch', 'exescormtype', 'title', 'sortorder']);

$scodatas = new backup_nested_element('sco_datas');

$scodata = new backup_nested_element('sco_data', array('id'), array(
'name', 'value'));
$scodata = new backup_nested_element('sco_data', ['id'], [
'name', 'value']);

$seqruleconds = new backup_nested_element('seq_ruleconds');

$seqrulecond = new backup_nested_element('seq_rulecond', array('id'), array(
'conditioncombination', 'ruletype', 'action'));
$seqrulecond = new backup_nested_element('seq_rulecond', ['id'], [
'conditioncombination', 'ruletype', 'action']);

$seqrulecondsdatas = new backup_nested_element('seq_rulecond_datas');

$seqrulecondsdata = new backup_nested_element('seq_rulecond_data', array('id'), array(
'refrencedobjective', 'measurethreshold', 'operator', 'cond'));
$seqrulecondsdata = new backup_nested_element('seq_rulecond_data', ['id'], [
'refrencedobjective', 'measurethreshold', 'operator', 'cond']);

$seqrolluprules = new backup_nested_element('seq_rolluprules');

$seqrolluprule = new backup_nested_element('seq_rolluprule', array('id'), array(
$seqrolluprule = new backup_nested_element('seq_rolluprule', ['id'], [
'childactivityset', 'minimumcount', 'minimumpercent', 'conditioncombination',
'action'));
'action']);

$seqrollupruleconds = new backup_nested_element('seq_rllprlconds');

$seqrolluprulecond = new backup_nested_element('seq_rllprlcond', array('id'), array(
'cond', 'operator'));
$seqrolluprulecond = new backup_nested_element('seq_rllprlcond', ['id'], [
'cond', 'operator']);

$seqobjectives = new backup_nested_element('seq_objectives');

$seqobjective = new backup_nested_element('seq_objective', array('id'), array(
'primaryobj', 'objectiveid', 'satisfiedbymeasure', 'minnormalizedmeasure'));
$seqobjective = new backup_nested_element('seq_objective', ['id'], [
'primaryobj', 'objectiveid', 'satisfiedbymeasure', 'minnormalizedmeasure']);

$seqmapinfos = new backup_nested_element('seq_mapinfos');

$seqmapinfo = new backup_nested_element('seq_mapinfo', array('id'), array(
$seqmapinfo = new backup_nested_element('seq_mapinfo', ['id'], [
'targetobjectiveid', 'readsatisfiedstatus', 'readnormalizedmeasure', 'writesatisfiedstatus',
'writenormalizedmeasure'));
'writenormalizedmeasure']);

$scotracks = new backup_nested_element('sco_tracks');

$scotrack = new backup_nested_element('sco_track', array('id'), array(
$scotrack = new backup_nested_element('sco_track', ['id'], [
'userid', 'attempt', 'element', 'value',
'timemodified'));
'timemodified']);

// Build the tree.
$exescorm->add_child($scoes);
Expand Down Expand Up @@ -127,24 +127,24 @@ protected function define_structure() {
$scotracks->add_child($scotrack);

// Define sources.
$exescorm->set_source_table('exescorm', array('id' => backup::VAR_ACTIVITYID));
$exescorm->set_source_table('exescorm', ['id' => backup::VAR_ACTIVITYID]);

// Order is important for several EXESCORM calls (especially exescorm_scoes)
// in the following calls to set_source_table.
$sco->set_source_table('exescorm_scoes', array('exescorm' => backup::VAR_PARENTID), 'sortorder, id');
$scodata->set_source_table('exescorm_scoes_data', array('scoid' => backup::VAR_PARENTID), 'id ASC');
$seqrulecond->set_source_table('exescorm_seq_ruleconds', array('scoid' => backup::VAR_PARENTID), 'id ASC');
$sco->set_source_table('exescorm_scoes', ['exescorm' => backup::VAR_PARENTID], 'sortorder, id');
$scodata->set_source_table('exescorm_scoes_data', ['scoid' => backup::VAR_PARENTID], 'id ASC');
$seqrulecond->set_source_table('exescorm_seq_ruleconds', ['scoid' => backup::VAR_PARENTID], 'id ASC');
$seqrulecondsdata->set_source_table(
'exescorm_seq_rulecond', array('ruleconditionsid' => backup::VAR_PARENTID), 'id ASC'
'exescorm_seq_rulecond', ['ruleconditionsid' => backup::VAR_PARENTID], 'id ASC'
);
$seqrolluprule->set_source_table('exescorm_seq_rolluprule', array('scoid' => backup::VAR_PARENTID), 'id ASC');
$seqrolluprulecond->set_source_table('exescorm_seq_rllprlcond', array('rollupruleid' => backup::VAR_PARENTID), 'id ASC');
$seqobjective->set_source_table('exescorm_seq_objective', array('scoid' => backup::VAR_PARENTID), 'id ASC');
$seqmapinfo->set_source_table('exescorm_seq_mapinfo', array('objectiveid' => backup::VAR_PARENTID), 'id ASC');
$seqrolluprule->set_source_table('exescorm_seq_rolluprule', ['scoid' => backup::VAR_PARENTID], 'id ASC');
$seqrolluprulecond->set_source_table('exescorm_seq_rllprlcond', ['rollupruleid' => backup::VAR_PARENTID], 'id ASC');
$seqobjective->set_source_table('exescorm_seq_objective', ['scoid' => backup::VAR_PARENTID], 'id ASC');
$seqmapinfo->set_source_table('exescorm_seq_mapinfo', ['objectiveid' => backup::VAR_PARENTID], 'id ASC');

// All the rest of elements only happen if we are including user info.
if ($userinfo) {
$scotrack->set_source_table('exescorm_scoes_track', array('scoid' => backup::VAR_PARENTID), 'id ASC');
$scotrack->set_source_table('exescorm_scoes_track', ['scoid' => backup::VAR_PARENTID], 'id ASC');
}

// Define id annotations.
Expand Down
Loading
Loading