diff --git a/mod/forum/classes/local/data_mappers/legacy/author.php b/mod/forum/classes/local/data_mappers/legacy/author.php index a8ddb12f1b1..b62e5a6f5da 100644 --- a/mod/forum/classes/local/data_mappers/legacy/author.php +++ b/mod/forum/classes/local/data_mappers/legacy/author.php @@ -51,6 +51,7 @@ class author { 'lastname' => $author->get_last_name(), 'fullname' => $author->get_full_name(), 'email' => $author->get_email(), + 'deleted' => $author->is_deleted(), 'middlename' => $author->get_middle_name(), 'firstnamephonetic' => $author->get_first_name_phonetic(), 'lastnamephonetic' => $author->get_last_name_phonetic(), diff --git a/mod/forum/classes/local/entities/author.php b/mod/forum/classes/local/entities/author.php index d2ed541cd68..527ecedaa2d 100644 --- a/mod/forum/classes/local/entities/author.php +++ b/mod/forum/classes/local/entities/author.php @@ -45,6 +45,8 @@ class author { private $fullname; /** @var string $email Email */ private $email; + /** @var bool $deleted Deleted */ + private $deleted; /** @var string $middlename Middle name */ private $middlename; /** @var string $firstnamephonetic Phonetic spelling of first name */ @@ -78,6 +80,7 @@ class author { string $lastname, string $fullname, string $email, + bool $deleted, string $middlename = null, string $firstnamephonetic = null, string $lastnamephonetic = null, @@ -90,6 +93,7 @@ class author { $this->lastname = $lastname; $this->fullname = $fullname; $this->email = $email; + $this->deleted = $deleted; $this->middlename = $middlename; $this->firstnamephonetic = $firstnamephonetic; $this->lastnamephonetic = $lastnamephonetic; @@ -151,6 +155,15 @@ class author { return $this->email; } + /** + * Is the author deleted? + * + * @return bool + */ + public function is_deleted() : bool { + return !empty($this->deleted); + } + /** * Return the middle name. * diff --git a/mod/forum/classes/local/exporters/author.php b/mod/forum/classes/local/exporters/author.php index 7beb5d56564..21508abd94f 100644 --- a/mod/forum/classes/local/exporters/author.php +++ b/mod/forum/classes/local/exporters/author.php @@ -91,6 +91,12 @@ class author extends exporter { 'default' => null, 'null' => NULL_ALLOWED ], + 'isdeleted' => [ + 'type' => PARAM_BOOL, + 'optional' => true, + 'default' => null, + 'null' => NULL_ALLOWED + ], 'groups' => [ 'multiple' => true, 'optional' => true, @@ -143,41 +149,56 @@ class author extends exporter { $context = $this->related['context']; if ($this->canview) { - $groups = array_map(function($group) use ($urlfactory, $context) { - $imageurl = null; - $groupurl = null; - if (!$group->hidepicture) { - $imageurl = get_group_picture_url($group, $group->courseid, true); - } - if (course_can_view_participants($context)) { - $groupurl = $urlfactory->get_author_group_url($group); - } - + if ($author->is_deleted()) { return [ - 'id' => $group->id, - 'name' => $group->name, + 'id' => $author->get_id(), + 'fullname' => get_string('deleteduser', 'mod_forum'), + 'isdeleted' => true, + 'groups' => [], 'urls' => [ - 'image' => $imageurl ? $imageurl->out(false) : null, - 'group' => $groupurl ? $groupurl->out(false) : null - + 'profile' => ($urlfactory->get_author_profile_url($author))->out(false), + 'profileimage' => ($urlfactory->get_author_profile_image_url($author, $authorcontextid))->out(false) ] ]; - }, $this->authorgroups); + } else { + $groups = array_map(function($group) use ($urlfactory, $context) { + $imageurl = null; + $groupurl = null; + if (!$group->hidepicture) { + $imageurl = get_group_picture_url($group, $group->courseid, true); + } + if (course_can_view_participants($context)) { + $groupurl = $urlfactory->get_author_group_url($group); + } - return [ - 'id' => $author->get_id(), - 'fullname' => $author->get_full_name(), - 'groups' => $groups, - 'urls' => [ - 'profile' => ($urlfactory->get_author_profile_url($author))->out(false), - 'profileimage' => ($urlfactory->get_author_profile_image_url($author, $authorcontextid))->out(false) - ] - ]; + return [ + 'id' => $group->id, + 'name' => $group->name, + 'urls' => [ + 'image' => $imageurl ? $imageurl->out(false) : null, + 'group' => $groupurl ? $groupurl->out(false) : null + + ] + ]; + }, $this->authorgroups); + + return [ + 'id' => $author->get_id(), + 'fullname' => $author->get_full_name(), + 'isdeleted' => false, + 'groups' => $groups, + 'urls' => [ + 'profile' => ($urlfactory->get_author_profile_url($author))->out(false), + 'profileimage' => ($urlfactory->get_author_profile_image_url($author, $authorcontextid))->out(false) + ] + ]; + } } else { // The author should be anonymised. return [ 'id' => null, 'fullname' => get_string('forumauthorhidden', 'mod_forum'), + 'isdeleted' => null, 'groups' => [], 'urls' => [ 'profile' => null, diff --git a/mod/forum/classes/local/exporters/post.php b/mod/forum/classes/local/exporters/post.php index 0d23672d378..f854e4613f3 100644 --- a/mod/forum/classes/local/exporters/post.php +++ b/mod/forum/classes/local/exporters/post.php @@ -386,7 +386,7 @@ class post extends exporter { $author, $authorcontextid, $authorgroups, - ($canview && !$isdeleted), + $canview, $this->related ); $exportedauthor = $authorexporter->export($output); @@ -402,10 +402,6 @@ class post extends exporter { $subject = $isdeleted ? get_string('forumsubjectdeleted', 'forum') : get_string('forumsubjecthidden', 'forum'); $message = $isdeleted ? get_string('forumbodydeleted', 'forum') : get_string('forumbodyhidden', 'forum'); $timecreated = null; - - if ($isdeleted) { - $exportedauthor->fullname = null; - } } $replysubject = $subject; diff --git a/mod/forum/classes/local/factories/entity.php b/mod/forum/classes/local/factories/entity.php index 55263f025c0..e40e59634fe 100644 --- a/mod/forum/classes/local/factories/entity.php +++ b/mod/forum/classes/local/factories/entity.php @@ -172,6 +172,7 @@ class entity { $record->lastname, fullname($record), $record->email, + $record->deleted, $record->middlename, $record->firstnamephonetic, $record->lastnamephonetic, diff --git a/mod/forum/classes/local/vaults/discussion_list.php b/mod/forum/classes/local/vaults/discussion_list.php index 6cfcebf2f58..a4a345b76e6 100644 --- a/mod/forum/classes/local/vaults/discussion_list.php +++ b/mod/forum/classes/local/vaults/discussion_list.php @@ -120,8 +120,8 @@ class discussion_list extends db_table_vault { // - Most recent editor. $thistable = new dml_table(self::TABLE, $alias, $alias); $posttable = new dml_table('forum_posts', 'fp', 'p_'); - $firstauthorfields = \user_picture::fields('fa', null, self::FIRST_AUTHOR_ID_ALIAS, self::FIRST_AUTHOR_ALIAS); - $latestuserfields = \user_picture::fields('la', null, self::LATEST_AUTHOR_ID_ALIAS, self::LATEST_AUTHOR_ALIAS); + $firstauthorfields = \user_picture::fields('fa', ['deleted'], self::FIRST_AUTHOR_ID_ALIAS, self::FIRST_AUTHOR_ALIAS); + $latestuserfields = \user_picture::fields('la', ['deleted'], self::LATEST_AUTHOR_ID_ALIAS, self::LATEST_AUTHOR_ALIAS); $fields = implode(', ', [ $thistable->get_field_select(), diff --git a/mod/forum/classes/local/vaults/preprocessors/extract_user.php b/mod/forum/classes/local/vaults/preprocessors/extract_user.php index ae6aa6b9a80..ae01ce21fbd 100644 --- a/mod/forum/classes/local/vaults/preprocessors/extract_user.php +++ b/mod/forum/classes/local/vaults/preprocessors/extract_user.php @@ -65,7 +65,7 @@ class extract_user { $alias = $this->alias; return array_map(function($record) use ($idalias, $alias) { - return user_picture::unalias($record, null, $idalias, $alias); + return user_picture::unalias($record, ['deleted'], $idalias, $alias); }, $records); } } \ No newline at end of file diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 71c312f3568..be2f7000032 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -146,6 +146,7 @@ $string['delete'] = 'Delete'; $string['deleteddiscussion'] = 'The discussion topic has been deleted'; $string['deletedpost'] = 'The post has been deleted'; $string['deletedposts'] = 'Those posts have been deleted'; +$string['deleteduser'] = 'Deleted user'; $string['deletesure'] = 'Are you sure you want to delete this post?'; $string['deletesureplural'] = 'Are you sure you want to delete this post and all replies? ({$a} posts)'; $string['digestmailheader'] = 'This is your daily digest of new posts from the {$a->sitename} forums. To change your default forum email preferences, go to {$a->userprefs}.'; diff --git a/mod/forum/templates/forum_discussion_modern_first_post.mustache b/mod/forum/templates/forum_discussion_modern_first_post.mustache index 7abcf15bb3e..3df50fabec1 100644 --- a/mod/forum/templates/forum_discussion_modern_first_post.mustache +++ b/mod/forum/templates/forum_discussion_modern_first_post.mustache @@ -236,14 +236,14 @@ {{/readonly}} - {{$subject}} -