Skip to content
Snippets Groups Projects
Unverified Commit c5b09e2b authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Added basic functionality for bulk sending mails

parent ece340e1
No related branches found
No related tags found
No related merge requests found
......@@ -104,6 +104,20 @@ class step_manager extends subplugin_manager {
return $steps;
}
/**
* Gets the list of step instances for a specific subpluginname.
* @return step_subplugin[] array of step instances.
*/
public static function get_step_instances_by_subpluginname($subpluginname) {
global $DB;
$records = $DB->get_records('tool_cleanupcourses_step', array('subpluginname' => $subpluginname));
$steps = array();
foreach ($records as $id => $record) {
$steps[$id] = step_subplugin::from_record($record);
}
return $steps;
}
/**
* Gets a specific step instance.
* @param int $instanceid id of the instance
......
......@@ -39,7 +39,7 @@ class process_cleanup extends \core\task\scheduled_task {
$processor->call_trigger();
$steps = step_manager::get_step_types();
/** @var \tool_cleanupcourses\step\base[] $steplibs stores the lib classes of all step subplugins.*/
/* @var \tool_cleanupcourses\step\base[] $steplibs stores the lib classes of all step subplugins.*/
$steplibs = array();
foreach ($steps as $id => $step) {
$steplibs[$id] = lib_manager::get_step_lib($id);
......
......@@ -25,7 +25,9 @@
*/
namespace tool_cleanupcourses\step;
use tool_cleanupcourses\manager\settings_manager;
use tool_cleanupcourses\response\step_response;
use tool_cleanupcourses\manager\step_manager;
defined('MOODLE_INTERNAL') || die();
......@@ -58,6 +60,31 @@ class email extends base {
return step_response::waiting();
}
public function post_processing_bulk_operation() {
global $DB;
$stepinstances = step_manager::get_step_instances_by_subpluginname($this->get_subpluginname());
foreach ($stepinstances as $step) {
$settings = settings_manager::get_settings($step->id);
$subject = $settings['subject'];
$content = $settings['content'];
$userstobeinformed = $DB->get_records('cleanupcoursesstep_email',
array('instanceid' => $step->id), '', 'distinct touser');
foreach ($userstobeinformed as $user) {
$transaction = $DB->start_delegated_transaction();
$mailentries = $DB->get_records('cleanupcoursesstep_email',
array('instanceid' => $step->id,
'touser' => $user->touser));
// TODO: use course info to parse content template!
email_to_user(\core_user::get_user($user->touser), \core_user::get_noreply_user(), $subject, $content);
$DB->delete_records('cleanupcoursesstep_email',
array('instanceid' => $step->id,
'touser' => $user->touser));
$transaction->allow_commit();
}
}
}
public function instance_settings() {
return array(
new instance_setting('subject', PARAM_TEXT),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment