Databases: modinfo in the course table

Databases: modinfo in the course table

by Kevin TREUSSIER -
Number of replies: 10

hello,

I use 1.5.3 moodle version.

I try to create many course with sql requests in phpmyadmin.

I want to put a "questionnaire" activity on each course I create.

For that, I need to understand how work the field "modinfo" in the "course" table.

this field in a course with just 1 questionnaire is something like this :

a:1:{i:1;O:8:"stdClass":6:{s:2:"cm";s:1:"1";s:3:"mod";s:13:"questionnaire";s:7:"section";s:1:"1";s:4:"name";s:21:"eval+questionnaire++2";s:7:"visible";s:1:"1";s:5:"extra";s:0:"";}}

Could you help me ? This field is quite strange for me...

Thanks and sorry for my bad english...

Kevin

Average of ratings: -
In reply to Kevin TREUSSIER

Re: Databases: modinfo in the course table

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
I have not tried this in the specific context you are working with; however, I have generally tended to ignore modinfo. My assumption is that it is calculated and populated as it needs to be. It is a strange field - so strange that I decided just to ignore it. Have you experienced a particular error if you just add the course data and then add the questionnaire data?
In reply to Anthony Borrow

Re: Databases: modinfo in the course table

by Kevin TREUSSIER -

I have try what you say but the problem is if I do that, there is no link on the course to the questionnaire (which exist on the database ).

When you add an activitie or a document to your course, the link is made with the field "modinfo" in the course table so its the only way for me to do that...

But I'm agree with you, the "modinfo" field seem's to be very strange...

My objective is to create many courses (450 ?) with one "questionnaire" on it. So I think add data on the base is the best way (with a little program) but if you have another better solution... (not with restore a course because it's too long...)

Thanks for your help

Kevin

In reply to Kevin TREUSSIER

Re: Databases: modinfo in the course table

by Martín Langhoff -
It's a serialized array. Grab it from the DB and do $array = unserialize($string). Fiddle with the array and use serialize to prepare it to be stored again. Cheers!
Average of ratings: Useful (1)
In reply to Martín Langhoff

Re: Databases: modinfo in the course table

by Ger Tielemans -
Can I also grab the section title from modinfo?
In reply to Martín Langhoff

Re: Databases: modinfo in the course table

by udhayakumar R -

Hi all,

         How to extract full course details and images using webservice from android, 

here i am getting course firstname, lastname, id, etc...., but i have the content of the course (moodle.get_course(cli, sess, info)), using android webview , i am gonna show the content of a course, 

In reply to Kevin TREUSSIER

Re: Databases: modinfo in the course table

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
As Marting L says, it is a serialised array.

I managed to corrupt that field in my test database, and the following sequence fixed it up:

1. Switch to edit mode.
2. Click the edit button next to the broken module.
3. Don't change anything, just click "Save changes".

Presumably it is somthing in stage 3 that recomputes what the modinfo field should be, and saves it back to the database. If you could work out what function call that is, you could write a scritp that you run after loading all the data into your database, that calls that function for every module on every course you have just loaded.

If you work out how to do that, it would be really great if you could post what you find back here. We will be investigating automatically loading courses into the database in the new year, and we would love to learn from you.

Thank you very much,

Tim.

In reply to Tim Hunt

Re: Databases: modinfo in the course table

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
It seems that if moodle finds an empty string in the database (''), then it automatically rebuilds the value as needed. So just loading '' into this database field should work.

But I have not tested that, we just noticed it in the code.

Tim.

In reply to Tim Hunt

Re: Databases: modinfo in the course table

by Kevin TREUSSIER -

I test to put ('') on the 'modinfo' field but nothing appear... the field doesn't change...

I try to see what contain $array with $array = unserialize($string) method but I saw nothing... I think we need to define the class of this object in my php page, but I don't know wath is this class... (http://php.benscom.com/manual/fr/language.oop.serialization.php)

This change and programmation seems to be too difficult for me... and I don't know how I will create so much courses rapidly...

am I the only one who needs to create so much courses ? Does someone have done it before ?

thanks for your answer...

Kevin

In reply to Kevin TREUSSIER

Re: Databases: modinfo in the course table

by Jan Dierckx -

Have you looked at the function rebuild_course_cache ?

It's in course/lib.php

It does what Tim Hunt describes: it rebuilds the modinfo field automatically for you.

I searched for days to find out how one could programmatically add a label to a specific course. Calling this function with the course id as an argument after adding the label did the trick. Hope this works for you too...

In reply to Jan Dierckx

Re: Databases: modinfo in the course table

by Ronnie Brito -
great, so its a performance related field...
i just ask if its worthy doing this database model distortion to get this result, because the batabase system should care about that... its its responsibility...

i had to do some selective course content replication and was stucked on this for some time...