view.php programming question

view.php programming question

by Deleted user -
Number of replies: 3

I'm just learning to program in php, and hope some of you 'programmers' out there can answer a couple of my questions...

1) What sort of limit is there on arrays? Is it memory specific? Does php impose a hard limit on the number of elements that an array can contain?

2) In the mod/quiz/view.php file, whenever I click on a Quiz, and get the screen that shows previous attempts (if any) and the attempt quiz now button (if available), the $id parameter is passed into the file (ex: http://mysite.com/mod/quiz/view.php?id=63). I understand exactly how this works ($id), and how it relates to each Quiz in the database. When you look at the code for view.php, it also allows you pass in the $q parameter instead of the $id parameter. I also completely understand how this works ($q), and how it relates to each Quiz in the databse. My question is this... WHEN is the $q parameter used? Where would I be coming from in Moodle, that would use $q instead of $id? In all cases that I can find, Moodle always passes the $id into view.php.

Thanks

Average of ratings: -
In reply to Deleted user

Re: view.php programming question

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
1) The only limit on arrays is the memory of the computer it is running on (that is your web server). Except that it would be dangerous if one web page request could use all the memory on the server, so actually, PHP imposes a limit on itself. See: http://uk2.php.net/manual/en/ini.core.php#ini.memory-limit. You don't need to worry about this however. The limit is always much bigger than you need. I don't think I have every hit it.

2) Looking at view.php for a quiz you can edit, click on the edit tab, then back to the info tab.

More generally, all modules in Moodle work this way. For example, you will sometimes see forums with id= or f=. The reason you see this is to do with where data is stored in the database. Quizzes are stored in the mdl_quiz table (forums in mdl_forum) the q= (or f=) parameter gives the id of a row in that table. All the instances of modules in a course are listed in the mdl_course_modules table, which links courseid, module type, and module instanceid (which in our case would be the q= parameter). The id= paramter refers to the id in this table.

I'm not saying this is a sensible system, but as I say all modules are like this, and you don't really need to understand it to understand the quiz.
In reply to Tim Hunt

Re: view.php programming question

by Deleted user -

Thanks for the info TIm.

One more question about the id= and the q= parameter...

I am writing a hack to provide Quiz Locking (activity locking) for 1.6.4, so that they have to acheive a certain grade before they can attempt the next Quiz. I have written the code (so far it is working), but I have only taken into consideration the id= parameter. As far as I can tell, all places that a student can access their Quizzes from, always uses the id= parameter.

Are there any locations that a student would have access to, that would also use the q= parameter to get them into a Quiz? Clicking on the EDIT tab and then back to the INFO tab is not something I need to worry about, because a student doesn't have access to that area.

Thanks

In reply to Deleted user

Re: view.php programming question

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I think that however view.php is loaded, by about line 40, there will be a variable that contains the number you want. Probably $cm->id. If you test that, you should not have to worry about which parameters were passed in.