Skip to content

Commit

Permalink
Include: Pulse 2.2 features.
Browse files Browse the repository at this point in the history
- PLS-763
  • Loading branch information
raja-lmsace committed Dec 13, 2024
1 parent c07ded1 commit 79ead93
Show file tree
Hide file tree
Showing 20 changed files with 532 additions and 22 deletions.
10 changes: 10 additions & 0 deletions amd/build/confirmcompletion.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/confirmcompletion.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions amd/src/confirmcompletion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Manual completion confirmation options.
*
* @module mod_pulse/confirmcompletion
* @copyright 2023, bdecent gmbh bdecent.de
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define(["jquery", 'core/str', "core/modal_factory", 'core/notification', 'core/ajax', "core/fragment", 'core/modal_events'],
(function($, Str, ModalFactory, notification, Ajax, Fragment, ModalEvents) {

/**
* Show mark as completion button confirmation modal.
* @param {init} contextid
*/
const buttonConfirmation = function(contextid) {
if (document.body.classList.contains('path-course-view')) {
var buttons = document.querySelectorAll('.pulse-user-manualcompletion-btn');
buttons.forEach(function(element) {
element.addEventListener('click', function(e) {
var classList = e.target.className;
var id = classList.match(/confirmation-(\d+)/);
if (id) {
id = id[1];
getModal(id, contextid);
}
});
});
}
};

/**
* Get the activity completion confirmation modal.
*
* @param {array} id instance id
* @param {int} contextid Context ID
*/
const getModal = function(id, contextid) {
var args = {id: id};

ModalFactory.create({
type: ModalFactory.types.SAVE_CANCEL,
title: Str.get_string('confirmation', 'pulse'),
body: '',
large: false
}).then(function(modal) {
modal.show();

Fragment.loadFragment('mod_pulse', 'get_confirmation_content', contextid, args)
.done((html, js) => {
modal.setBody(html);
return html;
})
.catch(notification.exception);

modal.setButtonText('save', Str.get_string('yes'));

modal.getRoot().on(ModalEvents.save, function(e) {
e.preventDefault();
submitformdata(args);
modal.getRoot().find('form').submit();
modal.hide();
});

modal.getRoot().on(ModalEvents.hidden, function() {
modal.destroy();
});

return modal;
}).catch(notification.exception);
};

/**
* Submit and recieve the message form the modal confirmation on the activity completion.
*
* @param {string} params
*/
const submitformdata = function(params) {
Ajax.call([{
methodname: 'mod_pulse_manual_completion',
args: params,
done: function(response) {
window.location.reload();
if (response.message) {
notification.addNotification({
message: response.message,
type: "success"
});
}
}
}]);
};

return {
init: function(contextid) {
buttonConfirmation(contextid);
},
};
}));
5 changes: 4 additions & 1 deletion backup/moodle2/backup_pulse_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ protected function define_structure() {
'pulse_contentformat', 'pulse', 'diff_pulse', 'displaymode',
'boxtype', 'boxicon', 'cssclass', 'resend_pulse',
'completionavailable', 'completionself', 'completionapproval',
'completionapprovalroles', 'timemodified',
'completionapprovalroles', 'completionbtnconfirmation',
'completionbtntext', 'completionbtn_content',
'completionbtn_contentformat', 'timemodified',
]);

$notifiedusers = new backup_nested_element('notifiedusers');
Expand Down Expand Up @@ -79,6 +81,7 @@ protected function define_structure() {
// Define file annotations.
$pulse->annotate_files('mod_pulse', 'intro', null);
$pulse->annotate_files('mod_pulse', 'pulse_content', null);
$pulse->annotate_files('mod_pulse', 'completionbtn_content', null);

$pulse = \mod_pulse\extendpro::pulse_extend_backup_steps($pulse, $userinfo);

Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/restore_pulse_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function define_my_steps() {
public static function define_decode_contents() {
$contents = [];

$contents[] = new restore_decode_content('pulse', ['intro', 'pulse_content'], 'pulse');
$contents[] = new restore_decode_content('pulse', ['intro', 'pulse_content', 'completionbtn_content'], 'pulse');

\mod_pulse\extendpro::pulse_extend_restore_content($contents);

Expand Down
1 change: 1 addition & 0 deletions backup/moodle2/restore_pulse_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,6 @@ protected function after_execute() {
// Add pulse related files.
$this->add_related_files('mod_pulse', 'intro', null);
$this->add_related_files('mod_pulse', 'pulse_content', null);
$this->add_related_files('mod_pulse', 'completionbtn_content', null);
}
}
3 changes: 2 additions & 1 deletion classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ public function get_custom_rule_descriptions(): array {
if ($this->is_available('completionself') ) {
$state = $this->get_state('completionself');
if (in_array($state, [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS])) {
$pulse = $this->get_pulse();
$date = \mod_pulse\helper::pulse_already_selfcomplete($this->cm->instance, $this->userid);
$selfstring = get_string('selfmarked', 'pulse', ['date' => $date]);
$selfstring = \mod_pulse\helper::get_complete_state_button_text($pulse->completionbtntext, $date);
}
}
// Approval completion description.
Expand Down
11 changes: 8 additions & 3 deletions classes/extendpro.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public static function mod_pulse_extend_form($mform, $instance, $method='') {
}
}

/** Extende the pro plugins validation error messages.
/**
* Extende the pro plugins validation error messages.
*
* @param mixed $data module form submitted data.
* @param mixed $files Module form submitted files.
Expand All @@ -108,7 +109,9 @@ public static function mod_pulse_extend_formvalidation($data, $files) {
}
}

/** Inject form elements into mod instance form.
/**
* Inject form elements into mod instance form.
*
* @param mform $mform the form to inject elements into.
*/
public static function mod_pulse_extend_formdata($mform) {
Expand All @@ -120,7 +123,9 @@ public static function mod_pulse_extend_formdata($mform) {
}
}

/** Extend form post process method from pro plugin.
/**
* Extend form post process method from pro plugin.
*
* @param object $data module form submitted data object.
*/
public static function pulse_extend_postprocessing($data) {
Expand Down
67 changes: 67 additions & 0 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir.'/externallib.php');
require_once($CFG->libdir.'/completionlib.php');

/**
* Pulse preset external definitions.
Expand Down Expand Up @@ -85,4 +86,70 @@ public static function apply_presets(int $contextid, string $formdata, $pagepara
public static function apply_presets_returns() {
return new \external_value(PARAM_RAW, 'Count of Page user notes');
}

/**
* Manual completion confirmation configdata.
*
* @return void
*/
public static function manual_completion_parameters() {
return new \external_function_parameters(
[
'id' => new \external_value(PARAM_INT, 'The id for the course module id'),
]
);
}

/**
* Activity manual completion.
*
* @param int $id course module ID.
*
* @return array $message
*/
public static function manual_completion($id) {
global $DB, $USER;
$params = self::validate_parameters(self::manual_completion_parameters(), ['id' => $id]);
$cm = get_coursemodule_from_id('pulse', $params['id']);
$pulse = $DB->get_record('pulse', ['id' => $cm->instance]);
$course = get_course($cm->course);
$message = '';
if ($record = $DB->get_record('pulse_completion', ['userid' => $USER->id, 'pulseid' => $cm->instance])) {
$record->selfcompletion = 1;
$record->selfcompletiontime = time();
$record->timemodified = time();
$result = $DB->update_record('pulse_completion', $record);
} else {
$record = new \stdclass();
$record->userid = $USER->id;
$record->pulseid = $cm->instance;
$record->selfcompletion = 1;
$record->selfcompletiontime = time();
$record->timemodified = time();
$result = $DB->insert_record('pulse_completion', $record);
}
if ($result) {
$completion = new \completion_info($course);
if ($completion->is_enabled($cm) && $pulse->completionself) {
$completion->update_state($cm, COMPLETION_COMPLETE, $USER->id);
}
$message = get_string('completionmessage', 'pulse');
}
return [
'message' => $message,
];
}

/**
* Retuns the redirect message for manual completion.
*
* @return array message.
*/
public static function manual_completion_returns() {
return new \external_single_structure(
[
'message' => new \external_value(PARAM_TEXT, 'Return message'),
]
);
}
}
Loading

0 comments on commit 79ead93

Please sign in to comment.