MDL-54894 comments: Get course from context if not informed
authorPau Ferrer Ocaña <crazyserver@gmail.com>
Fri, 10 Jun 2016 14:36:00 +0000 (16:36 +0200)
committerPau Ferrer Ocaña <crazyserver@gmail.com>
Mon, 20 Jun 2016 06:58:05 +0000 (08:58 +0200)
comment/lib.php

index 7df025c..42b3d42 100644 (file)
@@ -153,7 +153,11 @@ class comment {
         } else if (!empty($options->courseid)) {
             $this->courseid = $options->courseid;
         } else {
-            $this->courseid = SITEID;
+            if ($coursecontext = $this->context->get_course_context(false)) {
+                $this->courseid = $coursecontext->instanceid;
+            } else {
+                $this->courseid = SITEID;
+            }
         }
 
         // setup coursemodule