Skip to content

Commit 441900d

Browse files
authored
Merge pull request #142 from sumaiyamannan/errorfix
Fix error on draft or new messages
2 parents c0969e1 + 64c6b47 commit 441900d

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

classes/local/course_enrolment_manager.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ public function search_users_with_groups(string $search = '', bool $searchanywhe
7070
* @param int $perpage Number of users returned per page.
7171
* @param bool $returnexactcount Return the exact total users using count_record or not.
7272
* @param ?int $contextid Context ID we are in - we might use search on activity level and its group mode can be different from course group mode.
73-
* @return array with two or three elements:
74-
* int totalusers Number users matching the search. (This element only exist if $returnexactcount was set to true)
75-
* array users List of user objects returned by the query.
76-
* boolean moreusers True if there are still more users, otherwise is False.
73+
* @return array An array of users
7774
*/
7875
public function search_users(string $search = '', bool $searchanywhere = false, int $page = 0, int $perpage = 25,
7976
bool $returnexactcount = false, ?int $contextid = null) {

formlib.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected function definition() {
4646

4747
$mform->addElement('editor', 'body', get_string('message', 'dialogue'), null, self::editor_options());
4848
$mform->setType('body', PARAM_RAW);
49+
$mform->addRule('body', null, 'required', null, 'client');
4950

5051
// Maxattachments = 0 = No attachments at all.
5152
if (!get_config('dialogue', 'maxattachments') || !empty($PAGE->activityrecord->maxattachments)) {
@@ -254,14 +255,14 @@ protected function definition() {
254255
'ajax' => 'mod_dialogue/form-user-selector',
255256
'multiple' => true,
256257
'cmid' => $cm->id,
257-
'valuehtmlcallback' => function($value, $USER, $cm) {
258+
'valuehtmlcallback' => function($value) {
258259
global $OUTPUT;
259260
$userfieldsapi = \core_user\fields::for_name();
260261
$allusernames = $userfieldsapi->get_sql('', false, '', '', false)->selects;
261262
$fields = 'id, ' . $allusernames;
262263
$user = \core_user::get_user($value, $fields);
263264
$useroptiondata = [
264-
'fullname' => dialogue_add_user_fullname($user, $USER, $cm),
265+
'fullname' => dialogue_add_user_fullname($user),
265266
];
266267
return $OUTPUT->render_from_template('mod_dialogue/form-user-selector-suggestion', $useroptiondata);
267268
}

locallib.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -488,16 +488,24 @@ function dialogue_contains_draft_files($draftid) {
488488
}
489489

490490
/**
491-
* Get the name for a user - hiding their full name if the required capability
492-
* is missing.
491+
* Get the name for a user -
492+
* hiding their full name if the required capability is missing.
493493
*
494494
* @param stdClass $userviewed the user whose details are being viewed
495495
* @param stdClass $userviewedby the user who is viewing these details
496496
* @param stdClass $cm the course module object
497497
*
498498
* @return string fullname
499499
*/
500-
function dialogue_add_user_fullname(stdClass $userviewed, stdClass $userviewedby, stdClass $cm) {
500+
function dialogue_add_user_fullname(stdClass $userviewed,
501+
stdClass $userviewedby = null, stdClass $cm = null) {
502+
global $PAGE, $USER;
503+
if (!$userviewedby) {
504+
$userviewedby = $USER;
505+
}
506+
if (!$cm) {
507+
$cm = $PAGE->cm;
508+
}
501509
$capability = 'moodle/site:viewfullnames';
502510
$context = context_module::instance($cm->id);
503511
$hasviewfullnames = has_capability($capability, $context, $userviewedby);

0 commit comments

Comments
 (0)