x2002uwh / moodle2-skillsoft-activity

Automatically exported from code.google.com/p/moodle2-skillsoft-activity
0 stars 0 forks source link

Update report.php script to work with id=cmid instead of instanceid #7

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
We use this plugin to expose our content via LTI.
https://moodle.org/plugins/view.php?plugin=local_ltiprovider

It has a setting in it to force navigation to the LTI exposed page. This makes 
the report tab(s) unavailable when viewing via LTI. 

I have converted the tabs.php script to generate the tabs with id=cmid and the 
reports.php script to load via id=cmid as well as updated the login for 
reports.php to set the $PAGE->context to the Course Module.

How would you like me to get these changes to you?

Here is the diff inline

Index: report.php
===================================================================
--- report.php  (revision 135)
+++ report.php  (working copy)
@@ -38,20 +38,21 @@
 $url = new moodle_url('/mod/skillsoft/report.php',array('id'=>$id));

 if (!empty($id)) {
-   if (! $skillsoft = $DB->get_record('skillsoft', array('id'=>$id))) {
-       print_error('Course module is incorrect');
-   }
-   if (! $course = $DB->get_record('course', array('id'=> $skillsoft->course))) {
-       print_error('Course is misconfigured');
-   }
-   if (! $cm = get_coursemodule_from_instance('skillsoft', $skillsoft->id, 
$course->id)) {
-       print_error('Course Module ID was incorrect');
-   }
+    if (! $cm = get_coursemodule_from_id('skillsoft', $id)) {
+        print_error('Course Module ID was incorrect');
+    }
+    if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
+        print_error('Course is misconfigured');
+    }
+    if (! $skillsoft = $DB->get_record('skillsoft', array('id'=> 
$cm->instance))) {
+        print_error('Course module is incorrect');
+    }
+
 } else {
    print_error('A required parameter is missing');
 }
 $PAGE->set_url($url);
-require_course_login($course);
+require_login($course->id, false, $cm);

 //$PAGE->set_context(CONTEXT_MODULE, $cm->id);

@@ -272,4 +273,4 @@

 if (empty($noheader)) {
    echo $OUTPUT->footer();
-}
\ No newline at end of file
+}
Index: tabs.php
===================================================================
--- tabs.php    (revision 135)
+++ tabs.php    (working copy)
@@ -45,11 +45,11 @@
 $infourl = new moodle_url('/mod/skillsoft/view.php', array('id'=>$cm->id));
 $row[] = new tabobject('info', $infourl, get_string('skillsoft_info', 'skillsoft'));

-$reporturl = new moodle_url('/mod/skillsoft/report.php', 
array('id'=>$skillsoft->id, 'user'=>'true', 'attempt'=>$attempt));
+$reporturl = new moodle_url('/mod/skillsoft/report.php', array('id'=>$cm->id, 
'user'=>'true', 'attempt'=>$attempt));
 $row[] = new tabobject('reports', $reporturl, get_string('skillsoft_results', 'skillsoft'));

 if (has_capability('mod/skillsoft:viewreport', $contextmodule)) {
-   $reportallurl = new moodle_url('/mod/skillsoft/report.php', 
array('id'=>$skillsoft->id, 'attempt'=>$attempt));
+   $reportallurl = new moodle_url('/mod/skillsoft/report.php', 
array('id'=>$cm->id, 'attempt'=>$attempt));
     $row[] = new tabobject('allreports', $reportallurl, get_string('skillsoft_allresults', 'skillsoft'));
 }
 $tabs[] = $row;

Original issue reported on code.google.com by jojohns...@kaplan.edu on 2 Sep 2014 at 9:34

GoogleCodeExporter commented 8 years ago
Hi I am looking at this now, but there are a number of other links to reporting 
I need to fix up to work as you would like. Give me a week or so

Original comment by martinho...@googlemail.com on 4 Sep 2014 at 9:10

GoogleCodeExporter commented 8 years ago

Original comment by martinho...@googlemail.com on 4 Sep 2014 at 9:13

GoogleCodeExporter commented 8 years ago
I'll handle this one.

Original comment by martinho...@googlemail.com on 4 Sep 2014 at 9:17

GoogleCodeExporter commented 8 years ago
Thanks! Let me know how I can help out. We recently started using this plugin 
and its been great!

Original comment by johnston...@gmail.com on 4 Sep 2014 at 11:43

GoogleCodeExporter commented 8 years ago
Here is the code block that causes the issue with the report.php script:

https://github.com/jleyva/moodle-local_ltiprovider/blob/master/lib.php#L85-L97

The issue here is that the $PAGE->context is not the same as the $context. It 
may just be because of require_course_login() setting $PAGE->context to the 
course while $context is the course module instance. I will test again today 
but it may be fixed with just

-require_course_login($course);
+require_login($course->id, false, $cm);

Original comment by jojohns...@kaplan.edu on 4 Sep 2014 at 1:03

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r147.

Original comment by martinho...@googlemail.com on 4 Sep 2014 at 2:54

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r148.

Original comment by martinho...@googlemail.com on 4 Sep 2014 at 3:01