frumbert / wp2moodle-moodle

Moodle end of a Wordpress to Moodle Single Sign On auth plugin
28 stars 29 forks source link

How do you determine activity numerical index number #24

Closed elmonemo21 closed 7 years ago

elmonemo21 commented 8 years ago

Where is says,

activity: (optional, number) the numerical index of an activity to open after enrolment. E.g. "2" will attempt to open the second activity in the destination course.

What Moodle database field does it use to determine the numerical index? In a course with a large number of activities, how do you find the index number as the number doesn't see to correlate with the position of the activity in the course?

Thanks, I love this pluggin!

frumbert commented 8 years ago

Yeah the code that does this assumes a great deal, since it's definitely not a standard Moodle built-in function and it makes assumptions about the structure of the course. One thing I do know that it skips hidden activities and blindly ignores activity types that are non-openable (the label activity is one example).

A course has one or more sections, and each section has one or more activities (called modules in the database) so the plugin runs a query that joins the course sections to the modules then plucks the nth item from that list, ordering them in the sequence that is stored in the sections table.

So it's not even trying to examine the course in the context of the end user - if there were activities that conditionally release to a user, or were hidden, or were labels, or permissions ... it's basically a hack.

What can you tell me about the structure of activities in the course? What types of activities are you using, in what order?

elmonemo21 commented 8 years ago

Thanks for the quick reply. With your explanation, I understand enough to make it work :-) Basically, the course has lots of URL and Resource activities but there is also a forum activity and that is the one they want to link to directly from WordPress. Looking at the mdl_course_modules table, I can kinda see how the activity number is being pulled out. Although on one course, the mdl_course_modules shows the course has 19 modules but in the shortcode in WP, the activity index number I use to make it work is 32?? I'm happy though that it is working so I think my questions have been answered. Thanks again!

frumbert commented 7 years ago

For reference this was resolved, just closing job. An example of code that can be used to determine activity ids is here: https://gist.github.com/frumbert/bde8da383c3e0530559b54ccf21096c2