Skip to content
Merged
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
13 changes: 2 additions & 11 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,14 @@ jobs:
matrix:
include:
- php: '8.2'
moodle-branch: 'main'
moodle-branch: 'MOODLE_405_STABLE'
database: 'mariadb'
- php: '8.2'
moodle-branch: 'main'
moodle-branch: 'MOODLE_405_STABLE'
database: 'pgsql'
- php: '8.1'
moodle-branch: 'MOODLE_405_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_403_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'

steps:
- name: Check out repository code
Expand Down
1 change: 0 additions & 1 deletion block_lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* @author Alex Yeung <k.yeung@ucl.ac.uk>
*/
class block_lifecycle extends block_base {

/**
* Initialize the block with its title.
*/
Expand Down
8 changes: 5 additions & 3 deletions classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function get_course_lifecycle_info(int $courseid) {
$enddate = ((int)$courseacademicyear + 1) . '-' . $academicyeardate;

// Current time within the course's academic year period.
if (time() > strtotime($startdate) && time() < strtotime($enddate)) {
if (time() >= strtotime($startdate) && time() < strtotime($enddate)) {
$class = 'current';
// Current time earlier than the course's academic year start date.
} else if (time() < strtotime($startdate)) {
Expand Down Expand Up @@ -132,8 +132,10 @@ public static function get_courses_for_context_freezing(): array {
WHERE c.id <> :siteid AND ctx.contextlevel = 50 AND ctx.locked = 0
AND c.enddate <> 0 AND (c.enddate + :enddateextend) < :currenttime";

$potentialcourses = $DB->get_records_sql($sql,
['siteid' => SITEID, 'enddateextend' => $enddateextend, 'currenttime' => time()]);
$potentialcourses = $DB->get_records_sql(
$sql,
['siteid' => SITEID, 'enddateextend' => $enddateextend, 'currenttime' => time()]
);

if (!empty($potentialcourses)) {
foreach ($potentialcourses as $course) {
Expand Down
1 change: 0 additions & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @author Alex Yeung <k.yeung@ucl.ac.uk>
*/
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.
Expand Down
3 changes: 1 addition & 2 deletions classes/settings/admin_setting_configdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* An admin setting for a date input.
*/
class admin_setting_configdate extends admin_setting_configtext {

/**
* Validate the submitted data of the setting.
*
Expand Down Expand Up @@ -60,7 +59,7 @@ public function validate($data) {
* @param string $query
* @return string
*/
public function output_html($data, $query=''): string {
public function output_html($data, $query = ''): string {
global $OUTPUT;

$default = $this->get_defaultsetting();
Expand Down
3 changes: 1 addition & 2 deletions classes/task/freezecontext.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author Alex Yeung <k.yeung@ucl.ac.uk>
*/
class freezecontext extends \core\task\scheduled_task {

/**
* Name for this task.
*
Expand All @@ -47,7 +46,7 @@ public function execute() {
foreach ($courses as $course) {
try {
manager::freeze_course($course->id);
mtrace($course->id . '_' .$course->fullname . ' is frozen now.');
mtrace($course->id . '_' . $course->fullname . ' is frozen now.');
} catch (\Exception $e) {
mtrace($e->getMessage());
}
Expand Down
2 changes: 0 additions & 2 deletions db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,3 @@
'loginrequired' => true,
],
];


1 change: 0 additions & 1 deletion db/tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@
'disabled' => 0,
],
];

6 changes: 4 additions & 2 deletions externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public static function update_auto_freezing_preferences(int $courseid, string $p
// Parameters validation.
$params = self::validate_parameters(
self::update_auto_freezing_preferences_parameters(),
['courseid' => $courseid, 'preferences' => $preferences]);
['courseid' => $courseid, 'preferences' => $preferences]
);

return (array) manager::update_auto_freezing_preferences($params['courseid'], json_decode($params['preferences']));
}
Expand Down Expand Up @@ -115,7 +116,8 @@ public static function get_scheduled_freeze_date(int $courseid): array {
// Parameters validation.
$params = self::validate_parameters(
self::get_scheduled_freeze_date_parameters(),
['courseid' => $courseid]);
['courseid' => $courseid]
);

$success = 'true';
$result = manager::get_scheduled_freeze_date($params['courseid']);
Expand Down
2 changes: 0 additions & 2 deletions lang/en/block_lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,3 @@
$string['settings:weeksdelay'] = 'Weeks Delay';
$string['settings:weeksdelay:desc'] = 'The number of weeks after course end date to delay context freezing';
$string['task:freezecontext'] = 'Task to freeze course context';


38 changes: 24 additions & 14 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,27 @@ public function fetch_block_content(int $courseid): string {

// Scheduled freeze date.
$content .= html_writer::div(
'<h6>' . get_string('label:readonlydate', 'block_lifecycle') . '</h6>'.
'<h6>' . get_string('label:readonlydate', 'block_lifecycle') . '</h6>' .
'<div class="scheduled-freeze-date" id="scheduled-freeze-date"></div>',
'', ['id' => 'scheduled-freeze-date-container']);
'',
['id' => 'scheduled-freeze-date-container']
);

$content .= html_writer::div('<a class="btn btn-success"><i class="fa-edit fa fa-fw"></i>' .
$content .= html_writer::div(
'<a class="btn btn-success"><i class="fa-edit fa fa-fw"></i>' .
get_string('button:editsettings', 'block_lifecycle') .
'</a>',
'override-freeze-date-button', ['id' => 'override-freeze-date-button']);
'override-freeze-date-button',
['id' => 'override-freeze-date-button']
);
$content .= html_writer::start_div('automatic-read-only-settings', ['id' => 'automatic-read-only-settings']);
$content .= html_writer::div(
'<label>' . get_string('button:toggleautoreadonly', 'block_lifecycle') . '</label>'. $helpicontogglefreezinghtml .
'<div class="form-check form-switch">'.
'<input class="form-check-input" type="checkbox" role="switch" id="togglefreezebutton" '.
$togglefreezing . ' ' . $disabled . '>'.
'</div>', 'togglefreezebutton'
'<label>' . get_string('button:toggleautoreadonly', 'block_lifecycle') . '</label>' . $helpicontogglefreezinghtml .
'<div class="form-check form-switch">' .
'<input class="form-check-input" type="checkbox" role="switch" id="togglefreezebutton" ' .
$togglefreezing . ' ' . $disabled . '>' .
'</div>',
'togglefreezebutton'
);

// Create delay freeze date help icon.
Expand All @@ -83,14 +89,18 @@ public function fetch_block_content(int $courseid): string {

// Delay freezing date input.
$content .= html_writer::div(
'<p><label>' . get_string('label:readonlydateinput', 'block_lifecycle') . '</label>'. $helpicondelayfreezedatehtml .
'<input type="date" class="delayfreezedate-input" id="delayfreezedate" value="'. $delayfreezedate .'" ' . $disabled . '>
</p>', 'delayfreezedate'
'<p>'
. '<label>' . get_string('label:readonlydateinput', 'block_lifecycle') . '</label>'
. $helpicondelayfreezedatehtml
. '<input type="date" class="delayfreezedate-input" id="delayfreezedate" value="'
. $delayfreezedate . '" ' . $disabled . '>
</p>',
'delayfreezedate'
);

// Update button.
$content .= html_writer::div(
'<button id="update_auto_freezing_preferences_button" class="btn btn-primary" '. $disabled .'>Save</button>',
'<button id="update_auto_freezing_preferences_button" class="btn btn-primary" ' . $disabled . '>Save</button>',
'updatebutton'
);

Expand Down Expand Up @@ -130,7 +140,7 @@ public function fetch_course_dates(int $courseid): string {
if ($course = get_course($courseid)) {
$content = html_writer::start_div('course-dates');
$content .= html_writer::div(
get_string('lifecycle:startdate', 'block_lifecycle', date('d/m/Y', $course->startdate)) .'<br>'.
get_string('lifecycle:startdate', 'block_lifecycle', date('d/m/Y', $course->startdate)) . '<br>' .
get_string('lifecycle:enddate', 'block_lifecycle', date('d/m/Y', $course->enddate))
);
$content .= html_writer::end_div();
Expand Down
16 changes: 12 additions & 4 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

if ($ADMIN->fulltree) {
// General settings.
$settings->add(new admin_setting_heading('block_lifecycle_general',
$settings->add(new admin_setting_heading(
'block_lifecycle_general',
get_string('generalsettings', 'block_lifecycle'),
''
));
Expand All @@ -44,7 +45,10 @@
$settings->add(new admin_setting_configselect(
'block_lifecycle/weeks_delay',
get_string('settings:weeksdelay', 'block_lifecycle'),
get_string('settings:weeksdelay:desc', 'block_lifecycle'), 0, $options));
get_string('settings:weeksdelay:desc', 'block_lifecycle'),
0,
$options
));

// The CLC course custom field use for getting potential academic years.
$options = [];
Expand All @@ -57,7 +61,10 @@
$settings->add(new admin_setting_configselect(
'block_lifecycle/clcfield',
get_string('settings:clcfield', 'block_lifecycle'),
get_string('settings:clcfield:desc', 'block_lifecycle'), '', $options));
get_string('settings:clcfield:desc', 'block_lifecycle'),
'',
$options
));

// Setting to enable/disable the scheduled task for auto context freezing.
$settings->add(new admin_setting_configcheckbox(
Expand All @@ -71,7 +78,8 @@

// Academic year start date used to calculate the current academic year period.
// Default '08-01', e.g. academic year for 2022 starts at 2022-08-01.
$settings->add(new admin_setting_configtext('block_lifecycle/academic_year_start_date',
$settings->add(new admin_setting_configtext(
'block_lifecycle/academic_year_start_date',
get_string('settings:academicyearstartdate', 'block_lifecycle'),
get_string('settings:academicyearstartdate:desc', 'block_lifecycle'),
'08-01'
Expand Down
3 changes: 2 additions & 1 deletion tests/behat/behat_lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function the_following_custom_field_exists_for_lifecycle_block(TableNode
'customfield_category',
['name' => $data['category'],
'component' => 'core_course',
'area' => 'course']);
'area' => 'course']
);

if (!$category) {
$category = (object)[
Expand Down
16 changes: 14 additions & 2 deletions tests/freezecontext_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

use block_lifecycle\task\freezecontext;
use context_course;
use core_customfield\field_controller;
use stdClass;

/**
* Unit tests for block_lifecycle's freezecontext class.
Expand All @@ -28,6 +30,15 @@
* @author Alex Yeung <k.yeung@ucl.ac.uk>
*/
final class freezecontext_test extends \advanced_testcase {
/**
* @var stdClass
*/
private stdClass $course;
/**
* @var field_controller
*/
private field_controller $field1;

protected function setUp(): void {
parent::setUp();
$this->resetAfterTest();
Expand All @@ -43,7 +54,8 @@ protected function setUp(): void {

// Start date: 2020-09-01, end date: 2021-06-30.
$this->course = $dg->create_course(
['startdate' => 1598914800, 'enddate' => 1625007600, 'customfield_course_year' => '2020']);
['startdate' => 1598914800, 'enddate' => 1625007600, 'customfield_course_year' => '2020']
);
}

/**
Expand All @@ -66,7 +78,7 @@ public function test_get_name(): void {
*/
public function test_execute(): void {
// Suppress text output during tests.
$this->setOutputCallback(function(){
$this->setOutputCallback(function () {
});

// Test freeze context task.
Expand Down
Loading