-
Notifications
You must be signed in to change notification settings - Fork 13
Send notifications (via Moodle notifications processors) #33
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
Closed
danielneis
wants to merge
6
commits into
learningworks:master
from
danielneis:sendnotifications-form
Closed
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b7fb5a2
adds course to breadcrumb if block is inside a course
danielneis 07d4e8d
add option to send notification (but not send them yet)
danielneis 4b439f8
send notifications using ad hoc tasks
danielneis 7d3cdcb
remove unneeded reload and add sendnotifications column on table
danielneis e3dc520
revert breadcrumb changes
danielneis 1d9ffca
fix no blockid case
danielneis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| <?php | ||
| // 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/>. | ||
|
|
||
| /** | ||
| * Ad hoc task to send notifications. | ||
| * | ||
| * @package block_advnotifications | ||
| * @copyright 2021 Daniel Neis Araujo <daniel@adapta.online> | ||
| * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
| */ | ||
|
|
||
| namespace block_advnotifications\task; | ||
|
|
||
| defined('MOODLE_INTERNAL') || die(); | ||
|
|
||
| /** | ||
| * Ad hoc task to send notifications class. | ||
| * | ||
| * @package block_advnotifications | ||
| * @copyright 2021 Daniel Neis Araujo <daniel@adapta.online> | ||
| * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
| */ | ||
| class sendnotifications extends \core\task\adhoc_task { | ||
|
|
||
| /** | ||
| * Return the task's name as shown in admin screens. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function get_name() { | ||
| return get_string('sendnotificationstask', 'block-advnotifications'); | ||
| } | ||
|
|
||
| public function execute() { | ||
| global $DB; | ||
|
|
||
| if (!get_config('block_advnotifications', 'enable')) { | ||
| return; | ||
| } | ||
|
|
||
| $from = \core_user::get_noreply_user(); | ||
|
|
||
| $notification = $DB->get_record('block_advnotifications', ['id' => $this->get_custom_data()->notificationid]); | ||
|
|
||
| if (!$notification->enabled) { | ||
| return; | ||
| } | ||
|
|
||
| $bcontext = \context_block::instance($notification->blockid); | ||
| if ($ccontext = $bcontext->get_course_context(false)) { | ||
| $users = get_enrolled_users($ccontext, '', 0 , 'u.id'); | ||
| } else { | ||
| $users = $DB->get_records('user', ['deleted' => 0, 'suspended' => 0], '', 'id'); | ||
| } | ||
|
|
||
| foreach ($users as $u) { | ||
| $eventdata = new \core\message\message(); | ||
| $eventdata->component = 'block_advnotifications'; | ||
| $eventdata->name = 'sendadvnotifications'; | ||
| $eventdata->userfrom = $from; | ||
| $eventdata->userto = $u->id; | ||
| $eventdata->subject = $notification->title; | ||
| $eventdata->fullmessage = format_text($notification->message, FORMAT_MOODLE); | ||
| $eventdata->fullmessageformat = FORMAT_MOODLE; | ||
| $eventdata->fullmessagehtml = format_text($notification->message, FORMAT_MOODLE); | ||
| $eventdata->smallmessage = ''; | ||
| $eventdata->notification = true; | ||
| message_send($eventdata); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.