Skip to content

Commit

Permalink
MDL-65849 mod_forum: Add course param to the author's profile url
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Nov 29, 2019
1 parent 800563e commit 53b5c4f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
8 changes: 5 additions & 3 deletions mod/forum/classes/local/exporters/author.php
Expand Up @@ -147,6 +147,7 @@ protected function get_other_values(renderer_base $output) {
$authorcontextid = $this->authorcontextid;
$urlfactory = $this->related['urlfactory'];
$context = $this->related['context'];
$forum = $this->related['forum'];

if ($this->canview) {
if ($author->is_deleted()) {
Expand All @@ -156,7 +157,7 @@ protected function get_other_values(renderer_base $output) {
'isdeleted' => true,
'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)
]
];
Expand Down Expand Up @@ -192,7 +193,7 @@ protected function get_other_values(renderer_base $output) {
'isdeleted' => false,
'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)
]
];
Expand Down Expand Up @@ -220,7 +221,8 @@ protected function get_other_values(renderer_base $output) {
protected static function define_related() {
return [
'urlfactory' => 'mod_forum\local\factories\url',
'context' => 'context'
'context' => 'context',
'forum' => 'mod_forum\local\entities\forum',
];
}
}
1 change: 1 addition & 0 deletions mod/forum/classes/local/exporters/discussion_summary.php
Expand Up @@ -140,6 +140,7 @@ protected function get_other_values(renderer_base $output) {
$related = [
'urlfactory' => $this->related['urlfactory'],
'context' => $this->related['forum']->get_context(),
'forum' => $forum,
];

$firstpostauthor = new author(
Expand Down
6 changes: 4 additions & 2 deletions mod/forum/classes/local/factories/url.php
Expand Up @@ -394,11 +394,13 @@ public function get_export_attachment_url_from_post_and_attachment(post_entity $
* 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
]);
}

Expand Down
9 changes: 6 additions & 3 deletions mod/forum/tests/exporters_author_test.php
Expand Up @@ -63,7 +63,8 @@ public function test_export_author() {

$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);
Expand Down Expand Up @@ -104,7 +105,8 @@ public function test_export_author_with_groups() {

$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);
Expand Down Expand Up @@ -142,7 +144,8 @@ public function test_export_author_no_view_capability() {

$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);
Expand Down
24 changes: 12 additions & 12 deletions mod/forum/tests/externallib_test.php
Expand Up @@ -527,7 +527,7 @@ public function test_mod_forum_get_forum_discussion_posts() {
* 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);

Expand All @@ -538,6 +538,9 @@ public function test_mod_forum_get_discussion_posts() {
$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;
Expand All @@ -551,7 +554,7 @@ public function test_mod_forum_get_discussion_posts() {
'isdeleted' => false,
'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),
]
];
Expand All @@ -565,7 +568,7 @@ public function test_mod_forum_get_discussion_posts() {
'groups' => [],
'isdeleted' => false,
'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),
]
];
Expand All @@ -575,9 +578,6 @@ public function test_mod_forum_get_discussion_posts() {
// 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;
Expand Down Expand Up @@ -652,7 +652,7 @@ public function test_mod_forum_get_discussion_posts() {
'groups' => [],
'isdeleted' => true,
'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),
]
];
Expand Down Expand Up @@ -2618,14 +2618,17 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
$legacydatamapper = mod_forum\local\container::get_legacy_data_mapper_factory();
$legacypostmapper = $legacydatamapper->get_post_data_mapper();

// Create course to add the module.
$course1 = self::getDataGenerator()->create_course();

$user1 = self::getDataGenerator()->create_user();
$user1entity = $entityfactory->get_author_from_stdclass($user1);
$exporteduser1 = [
'id' => (int) $user1->id,
'fullname' => fullname($user1),
'groups' => [],
'urls' => [
'profile' => $urlfactory->get_author_profile_url($user1entity),
'profile' => $urlfactory->get_author_profile_url($user1entity, $course1->id)->out(false),
'profileimage' => $urlfactory->get_author_profile_image_url($user1entity),
],
'isdeleted' => false,
Expand All @@ -2638,7 +2641,7 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'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),
],
'isdeleted' => false,
Expand All @@ -2650,9 +2653,6 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
// 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;
Expand Down

0 comments on commit 53b5c4f

Please sign in to comment.