Back and forth from course/mod.php

Back and forth from course/mod.php

by Pau Bofill -
Number of replies: 4

Hi,

I'm trying to develop a new module and the problem I have is the following: when adding a  new instance of the new module I have to edit two pages, and before I can edit the second one I need the new instance id. The instance id is provided by mod.php. Thus, between mod.html (first page form) and second.php (second page form) I have to go through mod.php and then redirect. But I can thing of no way of passing the instance id to second.php.

Is this a "bug" in mod.php? My solution has been to alter mod.php as shown below. But that would imply updating the core of moodle. Is there a way to do the same without modifying mod.php?

My solution has been to to set the session returnpage in mod/newmodule/mod.html

  $SESSION->returnpage="../mod/newmodule/second.php";

and then add the module instance before redirection in course/mod.php

        if (!empty($SESSION->returnpage)) {
            $return = $SESSION->returnpage;
            unset($SESSION->returnpage);
            $return=$return . "?a=$mod->instance";
            redirect($return);
        } else {
            redirect("view.php?id=$course->id");
        }

therefore receiving the module instance in second.php through the parameter a.

Best,

Pau

Average of ratings: -
In reply to Pau Bofill

Re: Back and forth from course/mod.php

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi, Pau.

No problems at all.  Just pass the data from the first form to the second form, then pass it back to mod.php.  You can see this in action in the old resource module (the new resource module in 1.4 is now a one-step process).  You can also see it in the quiz module done a little differently (it stores data in the session).
In reply to Martin Dougiamas

Re: Back and forth from course/mod.php

by Pau Bofill -
The problem is that the second form needs the new instance ID, which has to be provided by mod.php after visiting the first form and before visiting the second.

I am working on an extension of the assignment module and I want the teacher to be able to provide a file with the solution. The problem is that I can't built the directory path until I know the ID of the new assignment instance.

Best,
Pau
In reply to Pau Bofill

Re: Back and forth from course/mod.php

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Ah, I see what you mean now!

In this case I would recommend that the first page just returns normally to mod.php, then you deal with the second and later stages in the view.php (much as Lesson does). In view.php, if data is not completely setup yet then redirect to your second setup page.

In Moodle 1.4 you are taken directly to the module/view.php after creating the new activity (rather than the old situation which took you to the course page), so this should be more or less seamless to users.

Lastly, keep in mind that the assignment module is currently being refactored by Pablo Etcheverry's crew in Argentina, so you may want to think about how your code might fit in as a class in a subdirectory.
In reply to Martin Dougiamas

Re: Back and forth from course/mod.php

by Pau Bofill -
Ok, If users are to be taken to module/view.php then I agree with your solution wink

Thanks a lot,
Pau