MDL-65849 mod_forum: Add course param to the author's profile url

This commit is contained in:
Shamim Rezaie
2019-11-29 17:19:04 +11:00
parent 26a1bee863
commit 43536c4490
5 changed files with 29 additions and 17 deletions
+4 -2
View File
@@ -141,6 +141,7 @@ class author extends exporter {
$authorcontextid = $this->authorcontextid;
$urlfactory = $this->related['urlfactory'];
$context = $this->related['context'];
$forum = $this->related['forum'];
if ($this->canview) {
$groups = array_map(function($group) use ($urlfactory, $context) {
@@ -169,7 +170,7 @@ class author extends exporter {
'fullname' => $author->get_full_name(),
'groups' => $groups,
'urls' => [
'profile' => ($urlfactory->get_author_profile_url($author))->out(false),
'profile' => ($urlfactory->get_author_profile_url($author, $forum->get_course_id()))->out(false),
'profileimage' => ($urlfactory->get_author_profile_image_url($author, $authorcontextid))->out(false)
]
];
@@ -195,7 +196,8 @@ class author extends exporter {
protected static function define_related() {
return [
'urlfactory' => 'mod_forum\local\factories\url',
'context' => 'context'
'context' => 'context',
'forum' => 'mod_forum\local\entities\forum',
];
}
}
@@ -140,6 +140,7 @@ class discussion_summary extends exporter {
$related = [
'urlfactory' => $this->related['urlfactory'],
'context' => $this->related['forum']->get_context(),
'forum' => $forum,
];
$firstpostauthor = new author(
+4 -2
View File
@@ -394,11 +394,13 @@ class url {
* Get the url to view an author's profile.
*
* @param author_entity $author The author
* @param int $courseid The course id
* @return moodle_url
*/
public function get_author_profile_url(author_entity $author) : moodle_url {
public function get_author_profile_url(author_entity $author, int $courseid) : moodle_url {
return new moodle_url('/user/view.php', [
'id' => $author->get_id()
'id' => $author->get_id(),
'course' => $courseid
]);
}
+6 -3
View File
@@ -62,7 +62,8 @@ class mod_forum_exporters_author_testcase extends advanced_testcase {
$exporter = new author_exporter($author, 1, [], true, [
'urlfactory' => \mod_forum\local\container::get_url_factory(),
'context' => $context
'context' => $context,
'forum' => $forum,
]);
$exportedauthor = $exporter->export($renderer);
@@ -102,7 +103,8 @@ class mod_forum_exporters_author_testcase extends advanced_testcase {
$exporter = new author_exporter($author, 1, [$group], true, [
'urlfactory' => \mod_forum\local\container::get_url_factory(),
'context' => $context
'context' => $context,
'forum' => $forum,
]);
$exportedauthor = $exporter->export($renderer);
@@ -139,7 +141,8 @@ class mod_forum_exporters_author_testcase extends advanced_testcase {
$exporter = new author_exporter($author, 1, [$group], false, [
'urlfactory' => \mod_forum\local\container::get_url_factory(),
'context' => $context
'context' => $context,
'forum' => $forum,
]);
$exportedauthor = $exporter->export($renderer);
+14 -10
View File
@@ -527,7 +527,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
* Tests is similar to the get_forum_discussion_posts only utilizing the new return structure and entities
*/
public function test_mod_forum_get_discussion_posts() {
global $CFG, $PAGE;
global $CFG;
$this->resetAfterTest(true);
@@ -538,6 +538,9 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
$legacyfactory = mod_forum\local\container::get_legacy_data_mapper_factory();
$entityfactory = mod_forum\local\container::get_entity_factory();
// Create course to add the module.
$course1 = self::getDataGenerator()->create_course();
// Create a user who can track forums.
$record = new stdClass();
$record->trackforums = true;
@@ -550,7 +553,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'fullname' => fullname($user2),
'groups' => [],
'urls' => [
'profile' => $urlfactory->get_author_profile_url($user2entity),
'profile' => $urlfactory->get_author_profile_url($user2entity, $course1->id)->out(false),
'profileimage' => $urlfactory->get_author_profile_image_url($user2entity),
]
];
@@ -563,7 +566,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'fullname' => fullname($user3),
'groups' => [],
'urls' => [
'profile' => $urlfactory->get_author_profile_url($user3entity),
'profile' => $urlfactory->get_author_profile_url($user3entity, $course1->id)->out(false),
'profileimage' => $urlfactory->get_author_profile_image_url($user3entity),
]
];
@@ -573,9 +576,6 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
// Set the first created user to the test user.
self::setUser($user1);
// Create course to add the module.
$course1 = self::getDataGenerator()->create_course();
// Forum with tracking off.
$record = new stdClass();
$record->course = $course1->id;
@@ -683,7 +683,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'html' => [
'rating' => null,
'taglist' => null,
'authorsubheading' => $forumgenerator->get_author_subheading_html((object)$exporteduser3, $discussion1reply2->created)
'authorsubheading' => $forumgenerator->get_author_subheading_html((object)$exporteduser3,
$discussion1reply2->created)
],
'capabilities' => [
'view' => 1,
@@ -699,7 +700,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'urls' => [
'view' => $urlfactory->get_view_post_url_from_post_id($discussion1reply2->discussion, $discussion1reply2->id),
'viewisolated' => $isolatedurl->out(false),
'viewparent' => $urlfactory->get_view_post_url_from_post_id($discussion1reply2->discussion, $discussion1reply2->parent),
'viewparent' => $urlfactory->get_view_post_url_from_post_id($discussion1reply2->discussion,
$discussion1reply2->parent),
'edit' => null,
'delete' =>null,
'split' => null,
@@ -738,7 +740,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'html' => [
'rating' => null,
'taglist' => null,
'authorsubheading' => $forumgenerator->get_author_subheading_html((object)$exporteduser2, $discussion1reply1->created)
'authorsubheading' => $forumgenerator->get_author_subheading_html((object)$exporteduser2,
$discussion1reply1->created)
],
'capabilities' => [
'view' => 1,
@@ -754,7 +757,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'urls' => [
'view' => $urlfactory->get_view_post_url_from_post_id($discussion1reply1->discussion, $discussion1reply1->id),
'viewisolated' => $isolatedurl->out(false),
'viewparent' => $urlfactory->get_view_post_url_from_post_id($discussion1reply1->discussion, $discussion1reply1->parent),
'viewparent' => $urlfactory->get_view_post_url_from_post_id($discussion1reply1->discussion,
$discussion1reply1->parent),
'edit' => null,
'delete' =>null,
'split' => null,