Merge branch 'MDL-65849-master' of git://github.com/rezaies/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 7 Jan 2020 05:17:08 +0000 (13:17 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 7 Jan 2020 05:17:08 +0000 (13:17 +0800)
mod/forum/classes/local/exporters/author.php
mod/forum/classes/local/exporters/discussion_summary.php
mod/forum/classes/local/factories/url.php
mod/forum/tests/exporters_author_test.php
mod/forum/tests/externallib_test.php

index 93f995b..31352c0 100644 (file)
@@ -147,6 +147,7 @@ class author extends exporter {
         $authorcontextid = $this->authorcontextid;
         $urlfactory = $this->related['urlfactory'];
         $context = $this->related['context'];
+        $forum = $this->related['forum'];
 
         if ($this->canview) {
             if ($author->is_deleted()) {
@@ -156,7 +157,7 @@ class author extends exporter {
                     '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)
                     ]
                 ];
@@ -192,7 +193,7 @@ class author extends exporter {
                     '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)
                     ]
                 ];
@@ -220,7 +221,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',
         ];
     }
 }
index 4637cb9..13a075f 100644 (file)
@@ -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(
index cfb6b4b..caae3d7 100644 (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
         ]);
     }
 
index 3b5dc57..7e85c10 100644 (file)
@@ -63,7 +63,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);
@@ -104,7 +105,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);
@@ -142,7 +144,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);
index 1e3878d..3ba370a 100644 (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;
@@ -551,7 +554,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
             '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),
             ]
         ];
@@ -565,7 +568,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
             '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),
             ]
         ];
@@ -575,9 +578,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;
@@ -652,7 +652,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
             '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),
             ]
         ];
@@ -2618,6 +2618,9 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
         $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 = [
@@ -2625,7 +2628,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
             '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,
@@ -2638,7 +2641,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),
             ],
             'isdeleted' => false,
@@ -2650,9 +2653,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;