Lesson DataBase IDs

Lesson DataBase IDs

by Eduardo Tello -
Number of replies: 2
Hi guys! I was wondering if you could help me with something:

I'm trying to build an aplication to interact with the moodle database but I'm having this problem: When I find the page ID on the database its something like "564" but when seen on the browser the ID (you know the "http://moodle/mod/lesson/view.php?id=869") it is "869". I need to be able to find pages by their "url id".

Can anybody tell me why is there such diference, but more importantly, how is it that moodle manages to still keep things organized and send me to the correct page? Is it a table I'm not finding? some obscure Function in the Lesson/view.php file?

Thanks a bunch!
Average of ratings: -
In reply to Eduardo Tello

Re: Lesson DataBase IDs

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Eduardo,

The id number you can see in the browser, e.g. http://moodle/mod/lesson/view.php?id=869 is not the lesson id. It is the id of the course module. You will need to use the moodle database table mdl_course_modules table to find it. As far as I can see, the lesson id is not used anywhere in the lesson files.

You might like to have a look at file mod/lesson/locallib.php, function lesson_get_basics($cmid = 0, $lessonid = 0) {}.

You will see that this function is never called with the 2 parameters, but always with one parameter (the $cmid).

Hope that helps,

Joseph

Average of ratings: Useful (1)
In reply to Eduardo Tello

Re: Lesson DataBase IDs

by Chris Collman -
Picture of Documentation writers
Hi Eduardo,
Timely post for me ! Thank you Joseph for the mdl_course_module tip! Last week I was digging around the MySQL tables and could not figure out where the lesson id was coming from.

Let me use a different example showing an url of a 2nd page of a lesson.

http://localhost/moodle/mod/lesson/view.php?id=12&pageid=11

Where id=12 comes from mdl_course_module.id

Where pageid=11 comes from mdl_lesson_pages.id

You may notice mdl_lesson_pages.lessonid field which refers back to mdl_lesson. The mdl_lesson table contains the Lesson settings. Just figured this out thanks to Joseph. Humm, no I will not suggest changing the table to mdl_lesson_settings for newbies like me smile

I used the 2nd page because while the 1st page does have a pageid, it does not display when the student first opens the lesson. It will display if the student goes to the page via a jump. So in my course:

http://localhost/moodle/mod/lesson/view.php?id=12&pageid=10
or
http://localhost/moodle/mod/lesson/view.php?id=12

will both take the student to the same place, which is the 1st page of the lesson.

Best, Chris