Skip to content

Commit

Permalink
Implemented the Section Completed 0.2 Tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
vasanthlmsace committed Jan 22, 2024
1 parent 75fa22b commit 6f0c356
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 88 deletions.
137 changes: 137 additions & 0 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Moodle Plugin CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-20.04

services:
postgres:
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.6.7
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
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_403_STABLE'
# database: 'mariadb'
# - php: '8.1'
# moodle-branch: 'MOODLE_402_STABLE'
# database: 'pgsql'
# - php: '8.0'
# moodle-branch: 'MOODLE_402_STABLE'
# database: 'mariadb'
# - php: '8.0'
# moodle-branch: 'MOODLE_401_STABLE'
# database: 'pgsql'
# - php: '8.0'
# moodle-branch: 'MOODLE_400_STABLE'
# database: 'pgsql'
# - php: '7.4'
# moodle-branch: 'MOODLE_400_STABLE'
# database: 'pgsql'
# - php: '7.4'
# moodle-branch: 'MOODLE_311_STABLE'
# database: 'mariadb'
# - php: '7.4'
# moodle-branch: 'MOODLE_311_STABLE'
# database: 'pgsql'
# - php: '7.4'
# moodle-branch: 'MOODLE_310_STABLE'
# database: 'pgsql'
# - php: '7.3'
# moodle-branch: 'MOODLE_39_STABLE'
# database: 'mariadb'

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

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: max_input_vars=6000
coverage: none

- name: Initialise moodle-plugin-ci
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
- 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: ${{ always() }}
# run: moodle-plugin-ci phplint

# - name: PHP Copy/Paste Detector
# if: ${{ always() }}
# run: moodle-plugin-ci phpcpd

# - name: PHP Mess Detector
# if: ${{ always() }}
# run: moodle-plugin-ci phpmd

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

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

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

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

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

# - name: Grunt
# if: ${{ always() }}
# run: moodle-plugin-ci grunt

# - name: PHPUnit tests
# if: ${{ always() }}
# run: moodle-plugin-ci phpunit

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome
27 changes: 15 additions & 12 deletions classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct($structure) {
* @return object|\stdClass $result
*/
public function save() {
$result = (object)array('type' => 'sectioncompleted');
$result = (object)['type' => 'sectioncompleted'];
if ($this->sectionid) {
$result->id = $this->sectionid;
} else {
Expand Down Expand Up @@ -121,9 +121,9 @@ public function is_available($not, \core_availability\info $info, $grabthelot, $
$allow = true;
if ($this->sectionid) {
$modinfo = get_fast_modinfo($info->get_course());
$section = $DB->get_record('course_sections', array('id' => $this->sectionid));
if (isset($section)) {
if (isset($modinfo->sections[@$section->section])) {
$section = $modinfo->get_section_info_by_id($this->sectionid);
if (!empty($section)) {
if (isset($modinfo->sections[$section->section])) {
foreach ($modinfo->sections[$section->section] as $modnumber) {
$module = $modinfo->cms[$modnumber];
$completiondata = $completioninfo->get_data($module);
Expand Down Expand Up @@ -162,23 +162,25 @@ public function get_description($full, $not, \core_availability\info $info) {
}
global $DB;
$format = course_get_format($info->get_course()->id);
$section = $DB->get_record('course_sections', array('id' => $this->sectionid));
$section = $DB->get_record('course_sections', ['id' => $this->sectionid]);
$title = @$format->get_section_name($section->section);
if ($not) {
return get_string('getdescriptionnot', 'availability_sectioncompleted', $title);
}
return get_string('getdescription', 'availability_sectioncompleted', $title);
}
/**
* Checks whether this condition applies to user lists.
*
* @return bool
* @throws \coding_exception
*/


/**
* Checks whether this condition applies to user lists.
*
* @return bool
* @throws \coding_exception
*/
public function is_applied_to_user_lists() {
// Group conditions are assumed to be 'permanent', so they affect the
// display of user lists for activities.
return true;
return false;
}


Expand All @@ -190,4 +192,5 @@ public function is_applied_to_user_lists() {
public function get_debug_string() {
return $this->sectionid ?? 'any';
}

}
49 changes: 39 additions & 10 deletions classes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

namespace availability_sectioncompleted;

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

/**
* Availability role - Frontend form class
*
Expand All @@ -45,28 +43,58 @@ class frontend extends \core_availability\frontend {
* @return array
*/
protected function get_javascript_init_params($course, \cm_info $cm = null, \section_info $section = null) {
$jsarray = array();
global $PAGE;
$jsarray = [];
$context = \context_course::instance($course->id);

$format = course_get_format($course->id);
$course = $format->get_course(); // Needed to have numsections property available.
if (!$format->uses_sections()) {
return array();
return [];
}
if (($format instanceof format_digidagotabs) || ($format instanceof format_horizontaltabs)) {
// Don't show the menu in a tab.
return array();
return [];
// Only show the block inside activities of courses.
} else {
$coursesections = $format->get_sections();
}
if (empty($coursesections)) {
return array();
return [];
}
if ($section != null) {
if (isset($coursesections[$section->section - 1])) {
$presection = $coursesections[$section->section - 1];
$jsarray[] = (object) [
'id' => $presection->id,
'name' => get_string('previoussection'),
];
}
} else if ($cm != null) {
$cmsection = $cm->get_section_info();
if (isset($coursesections[$cmsection->section - 1])) {
$presection = $coursesections[$cmsection->section - 1];
$jsarray[] = (object) [
'id' => $presection->id,
'name' => get_string('previoussection'),
];
}
} else if ($sectionnum = optional_param('section', 0, PARAM_INT)) {
if (isset($coursesections[$sectionnum - 1])) {
$presection = $coursesections[$sectionnum - 1];
$jsarray[] = (object) [
'id' => $presection->id,
'name' => get_string('previoussection'),
];
}
}

foreach ($coursesections as $section) {

if (@$cm->section == $section->id) {
continue;
}

if (!$section->uservisible) {
continue;
}
Expand All @@ -80,12 +108,13 @@ protected function get_javascript_init_params($course, \cm_info $cm = null, \sec
} else {
$title = $format->get_section_name($section);
}
$jsarray[] = (object)array(

$jsarray[] = (object) [
'id' => $section->id,
'name' => $title
);
'name' => $title,
];
}
return array($jsarray);
return [$jsarray];
}


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

namespace availability_sectioncompleted\privacy;

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

/**
* Privacy Subsystem implementing null_provider.
*
Expand Down
3 changes: 2 additions & 1 deletion lang/en/availability_sectioncompleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
$string['missing'] = '(Missing section)';
$string['requires_incomplete'] = 'You have not completed <strong>{$a}</strong>';
$string['requires_complete'] = 'You have completed <strong>{$a}</strong>';
$string['privacy:metadata'] = 'The Restriction by other section completion plugin does not store any personal data.';
$string['privacy:metadata'] = 'The Restriction by other section completion plugin does not store any personal data.';
$string['previoussection'] = "Previous section";
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


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

use \core_privacy\tests\provider_testcase;
namespace availability_sectioncompleted;
use core_privacy\tests\provider_testcase;

/**
* Unit tests for the sectioncompleted condition.
Expand All @@ -39,12 +37,12 @@ class availability_sectioncompleted_privacy_testcase extends provider_testcase {

/**
* Test returning metadata.
* @coversDefaultClass availability_sectioncompleted\privacy\provider
* @covers ::availability_sectioncompleted\privacy\provider
*/
public function test_get_metadata() {
$collection = new \core_privacy\local\metadata\collection('availability_sectioncompleted');
$reason = \availability_sectioncompleted\privacy\provider::get_reason($collection);
$this->assertEquals($reason, 'privacy:metadata');
$this->assertStringContainsString('does not store', get_string($reason, 'availability_sectioncompleted'));
}
}
}
Loading

0 comments on commit 6f0c356

Please sign in to comment.