Skip to content

Commit

Permalink
PGSQL preset behat issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Sep 25, 2023
1 parent 5410e54 commit 8942b45
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
31 changes: 31 additions & 0 deletions actions/notification/classes/actionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,37 @@ protected function recreate_instance_schedules(int $templateid) {

}

/**
* Generate the warnings if the instance is not compatibile to send notifications.
*
* @param \stdclass $course
* @return array
*/
public function display_instance_warnings(\stdclass $course): array {

// Course visibility warnings.
if (!$course->visible) {
$warning[] = get_string('coursehidden', 'pulseaction_notification');
}

// Course active users warnings.
$coursecontext = \context_course::instance($course->id);
if (!count_enrolled_users($coursecontext, '', null, true)) {
$warning[] = get_string('noactiveusers', 'pulseaction_notification');
}

// Course is not started.
if ($course->startdate > time()) {
$warning[] = get_string('coursenotstarted', 'pulseaction_notification');
}

// Course is not started.
if ($course->enddate && $course->enddate < time()) {
$warning[] = get_string('courseenddatereached', 'pulseaction_notification');
}

return $warning ?? [];
}
/**
* Save the template config.
*
Expand Down
28 changes: 13 additions & 15 deletions actions/notification/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ function xmldb_pulseaction_notification_upgrade($oldversion) {

$dbman = $DB->get_manager();

if ($oldversion < 2023080409) {
// Auto templates instance.
$instable = new xmldb_table('pulseaction_notification');
$timemodified = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '11', null, null, null, null);
// Verify field exists.
if ($dbman->field_exists($instable, $timemodified)) {
// Change the field.
$dbman->change_field_precision($instable, $timemodified);
}
// Auto templates instance.
$instable = new xmldb_table('pulseaction_notification');
$timemodified = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '11', null, null, null, null);
// Verify field exists.
if ($dbman->field_exists($instable, $timemodified)) {
// Change the field.
$dbman->change_field_precision($instable, $timemodified);
}

// Update the templates table timemodified.
$temptable = new xmldb_table('pulseaction_notification_ins');
if ($dbman->field_exists($temptable, $timemodified)) {
// Change the field.
$dbman->change_field_precision($temptable, $timemodified);
}
// Update the templates table timemodified.
$temptable = new xmldb_table('pulseaction_notification_ins');
if ($dbman->field_exists($temptable, $timemodified)) {
// Change the field.
$dbman->change_field_precision($temptable, $timemodified);
}

return true;
Expand Down
5 changes: 5 additions & 0 deletions actions/notification/lang/en/pulseaction_notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,8 @@
// Chapters.
$string['chapters'] = 'Chapters';
$string['chapters_help'] = 'Provides support to select specific chapters from a Book activity.';
// ...Course instance warning messages.
$string['coursehidden'] = 'Course is hidden from the students. <span> Please enable the visibility of the course to send notifications.</span>';
$string['noactiveusers'] = 'Course doesn\'t contain any active enrolments. <span> Please enroll users in the course.</span>';
$string['coursenotstarted'] = 'Course has not started. <span> Please set the course start date to a date in the past.</span>';
$string['courseenddatereached'] = 'Course has ended. <span> Please set the course end date to a date in the future or remove the end date.</span>';
4 changes: 4 additions & 0 deletions classes/automation/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,12 @@ public static function display_actions_course_warnings($course) {
foreach ($actions as $component => $action) {
if (method_exists($action, 'display_instance_warnings')) {
$messages += $action->display_instance_warnings($course);
// $messages = array_merge($messages, $message);
}
}

$ul = \html_writer::tag('ul', implode('', array_map(fn($val) => '<li>' . $val . '</li>', array_filter($messages))));
echo \html_writer::div($ul, 'pulse-warnings text-warning');
}

}
4 changes: 4 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,7 @@
.path-mod-pulse-automation #fitem_id_insreference #pulse-template-reference {
margin-right: 10px;
}
/* Warning message info */
#page-mod-pulse-automation-instances-edit .pulse-warnings li span {
color: initial;
}
1 change: 0 additions & 1 deletion tests/behat/pulse_preset.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@ Feature: Preset create pulse with custom params.
Then ".modal-body" "css_element" should not be visible
Then the field "id_name" matches value "Customize preset"
And the field "id_introeditor" matches value "Pulse created using apply and customize - custom value"
Then I should see "Pulse created using apply and customize - custom value"
And I press "Save and return to course"
Then I should see "Pulse created using apply and customize - custom value"

0 comments on commit 8942b45

Please sign in to comment.