Skip to content

Commit

Permalink
Merge pull request #142 from sumaiyamannan/errorfix
Browse files Browse the repository at this point in the history
Fix error on draft or new messages
  • Loading branch information
danmarsden authored Jan 19, 2025
2 parents c0969e1 + 64c6b47 commit 441900d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
5 changes: 1 addition & 4 deletions classes/local/course_enrolment_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ public function search_users_with_groups(string $search = '', bool $searchanywhe
* @param int $perpage Number of users returned per page.
* @param bool $returnexactcount Return the exact total users using count_record or not.
* @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.
* @return array with two or three elements:
* int totalusers Number users matching the search. (This element only exist if $returnexactcount was set to true)
* array users List of user objects returned by the query.
* boolean moreusers True if there are still more users, otherwise is False.
* @return array An array of users
*/
public function search_users(string $search = '', bool $searchanywhere = false, int $page = 0, int $perpage = 25,
bool $returnexactcount = false, ?int $contextid = null) {
Expand Down
5 changes: 3 additions & 2 deletions formlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected function definition() {

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

// Maxattachments = 0 = No attachments at all.
if (!get_config('dialogue', 'maxattachments') || !empty($PAGE->activityrecord->maxattachments)) {
Expand Down Expand Up @@ -254,14 +255,14 @@ protected function definition() {
'ajax' => 'mod_dialogue/form-user-selector',
'multiple' => true,
'cmid' => $cm->id,
'valuehtmlcallback' => function($value, $USER, $cm) {
'valuehtmlcallback' => function($value) {
global $OUTPUT;
$userfieldsapi = \core_user\fields::for_name();
$allusernames = $userfieldsapi->get_sql('', false, '', '', false)->selects;
$fields = 'id, ' . $allusernames;
$user = \core_user::get_user($value, $fields);
$useroptiondata = [
'fullname' => dialogue_add_user_fullname($user, $USER, $cm),
'fullname' => dialogue_add_user_fullname($user),
];
return $OUTPUT->render_from_template('mod_dialogue/form-user-selector-suggestion', $useroptiondata);
}
Expand Down
14 changes: 11 additions & 3 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,16 +488,24 @@ function dialogue_contains_draft_files($draftid) {
}

/**
* Get the name for a user - hiding their full name if the required capability
* is missing.
* Get the name for a user -
* hiding their full name if the required capability is missing.
*
* @param stdClass $userviewed the user whose details are being viewed
* @param stdClass $userviewedby the user who is viewing these details
* @param stdClass $cm the course module object
*
* @return string fullname
*/
function dialogue_add_user_fullname(stdClass $userviewed, stdClass $userviewedby, stdClass $cm) {
function dialogue_add_user_fullname(stdClass $userviewed,
stdClass $userviewedby = null, stdClass $cm = null) {
global $PAGE, $USER;
if (!$userviewedby) {
$userviewedby = $USER;
}
if (!$cm) {
$cm = $PAGE->cm;
}
$capability = 'moodle/site:viewfullnames';
$context = context_module::instance($cm->id);
$hasviewfullnames = has_capability($capability, $context, $userviewedby);
Expand Down

0 comments on commit 441900d

Please sign in to comment.