Last active
January 24, 2019 19:58
-
-
Save mhughes2k/83479aa4db5ccd8e5f0a7700270d66cf to your computer and use it in GitHub Desktop.
Generating Emails in Moodle...
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
<?php | |
//Preview an email | |
require_once("../../../../config.php"); | |
require_once($CFG->dirroot . '/mod/assign/locallib.php'); | |
$ex =\assignsubmission_strathfm\local\model\extension_request::get_record(['id' => 11]); | |
$u = core_user::get_user($ex->get('userid')); | |
$u = $USER; | |
$config = \assignsubmission_strathfm\local\helper::get_config(); | |
$emaildata = new \assignsubmission_strathfm\output\extensionrequest_email($ex, $u, $config); | |
$o = $PAGE->get_renderer('core'); | |
//print_r($emaildata->export_for_template($o)); | |
//echo $OUTPUT->render_from_template('assignsubmission_strathfm/extensionrequest_receipt_html', $emaildata->export_for_template($o)); | |
echo $OUTPUT->render_from_template('assignsubmission_strathfm/extensionrequest_new_request_notification', $emaildata->export_for_template($o)); |
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
<?php | |
namespace assignsubmission_strathfm\output; | |
use assignsubmission_strathfm\local\exporter\extension_request_exporter; | |
use assignsubmission_strathfm\local\model\extension_request; | |
use renderer_base; | |
use assignsubmission_strathfm\local\helper; | |
use report_groups\export\export; | |
use stdClass; | |
use assignsubmission_strathfm\extension_form; | |
/** | |
* Class extensionrequest_email | |
* @package assignsubmission_strathfm\output | |
* | |
* Holds all of the information required to email a user (staff or student) | |
* about an extension. | |
*/ | |
class extensionrequest_email implements \renderable, \templatable | |
{ | |
private $_request; | |
private $_recipient; | |
private $_config; | |
private $_extensioninfo; | |
private $_course; | |
private $_cm; | |
/** | |
* extensionrequest_email constructor. | |
* @param extension_request $request Request record | |
* @param \stdClass $decision Decision record | |
*/ | |
public function __construct( | |
$request, | |
$recipient, | |
$config | |
) { | |
$this->_request = $request; | |
$this->_recipient = $recipient; | |
$this->_config = $config; | |
list($course, $cm) = get_course_and_cm_from_cmid($request->get('cmid')); | |
$this->_course = $course; | |
$this->_cm = $cm; | |
$context = $cm->context; | |
$this->_extensioninfo = helper::get_extension_info($context); | |
} | |
public function export_for_template(renderer_base $output) | |
{ | |
$requester = \core_user::get_user($this->_request->get('userid')); | |
$data = []; | |
$data['recipient_fullname'] = fullname($this->_recipient); | |
foreach($this->_recipient as $property=>$value) { | |
$data['recipient_'.$property] = $value; | |
} | |
$rqe = new extension_request_exporter($this->_request); | |
$rq = $rqe->export($output); | |
foreach($rq as $property=>$value) { | |
$data["extension_". $property] = $value; | |
} | |
$data['extension_userfullname'] = fullname($requester) ?? ""; | |
$data['extension_coursefullname'] = $this->course->fullname ?? ""; | |
$data['extension_cmurl'] = $this->_cm->url ?? ""; | |
$data['extension_activitylink'] = $output->action_link( | |
$this->_cm->url, $this->_cm->name | |
); | |
$data['extension_managelink'] = $output->action_link( | |
new \moodle_url('/mod/assign/submission/strathfm/manage.php', ['id' => $this->_cm->id]), | |
get_string('activityextensions', 'assignsubmission_strathfm', $this->_cm->name) | |
); | |
$data['extension_managethislink'] = $output->action_link( | |
new \moodle_url('/mod/assign/submission/strathfm/manage.php', ['id' => $this->_cm->id, 'extid' => $this->_request->get('id')]), | |
get_string('userextensionrequest', 'assignsubmission_strathfm', $data['extension_userfullname']) | |
); | |
foreach($this->_config as $property=>$value) { | |
$data["config_". $property] = $value; | |
} | |
foreach($this->_extensioninfo as $property=>$value) { | |
$data["info_". $property] = $value; | |
} | |
$data['info_warninterval_readable'] = helper::elapsed_time($data['info_warninterval']); | |
$data['info_criticalinterval_readable'] = helper::elapsed_time($data['info_criticalinterval']); | |
return (object)$data; | |
} | |
} |
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 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/>. | |
}} | |
{{! | |
@template assignsubmission_strathfm/extensionrequest_receipt_html | |
Generates HTML email for notifying staff about a new request | |
Classes required for JS: | |
* none | |
Data attributes required for JS: | |
* none | |
Context variables required for this template: | |
}} | |
<div>{{#str}}dearuser, assignsubmission_strathfm, {{recipient_fullname}}{{/str}}</div> | |
<div>{{#str}}emailrequestcreatednotification, assignsubmission_strathfm, | |
{ | |
"extension_userfullname": "{{extension_userfullname}}", | |
"extension_activitylink": {{#quote}}{{{extension_activitylink}}}{{/quote}}, | |
"info_warninterval_readable": {{#quote}}{{info_warninterval_readable}}{{/quote}}, | |
"info_criticalinterval_readable": {{#quote}}{{info_criticalinterval_readable}}{{/quote}}, | |
"extension_managethislink": {{#quote}}{{{extension_managethislink}}}{{/quote}}, | |
"extension_managelink": {{#quote}}{{{extension_managelink}}}{{/quote}} | |
} | |
{{/str}}</div> | |
<div>{{#str}}contactinfo, assignsubmission_strathfm, {{{info_contact}}}{{/str}}</div> |
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
$string['emailrequestcreatedrecipt'] = 'Your request has been submitted for review.'; | |
$string['emailrequestcreatednotification'] = '<p>{$a->extension_userfullname} has submitted a request for an | |
extension or exceptional circumstances for {$a->extension_activitylink}.</p> | |
<p>This request will be marked as "warn" after {$a->info_warninterval_readable} and as "critical" after {$a->info_criticalinterval_readable}.</p> | |
<p>You can action this request by going to {$a->extension_managethislink}.</p> | |
<p>You can access the list of requests for this activity by going to {$a->extension_managelink}.</p> | |
'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment