trying to understand moodle's .php files

trying to understand moodle's .php files

by pritish jain -
Number of replies: 25

hello I am new to moodle and i want to learn how it works i just want to what does core.php actually does? any help will be appreciated. i am workin on moodle 2.0

Average of ratings: -
In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

Hello everyone

One more thing i would like to ask. how images uploaded are stored in moodle . which directotry they use and how it works, actually i want to download these images using other files  and I need to know where  they actually go.

In reply to pritish jain

Re: trying to understand moodle's .php files

by Justin Wyllie -

Hi Pritish

On your second question:

if you are using the file picker to upload and save images via a form ( http://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms) they will likely get stored in Moodle's file system.   However I don't see why you could not capture the uploaded files and save them to a directory of your choice. Though you not then get the benefits of using the FIle API.

If the files you want are in Moodle's file system you'll need to use the API to get them back - for low-level access the relevant files  are /lib/filestorage.php and /lib/stored_file. The table is prefix_files.  Moodle has some way of storing files in a directory system under your moodle data directory with names based on a hash of the contents -  which makes it sensible to use the API rather than try to extract them directly. I *think* there is a higher level API file browser in /lib/filelib.php.

These doc links seem to apply:

http://docs.moodle.org/dev/File_API

http://docs.moodle.org/dev/Using_the_file_API

These are only pointers

Justin Wyllie

In reply to Justin Wyllie

Re: trying to understand moodle's .php files

by pritish jain -

thanks justin i think i can get it now

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -
hi all, I found that moodle uses hexadecimal format to store path of a file how it retrieves the path i have gone through the API but there are only function like get_file_path i tried to use that but i am not able to retrive path. Please help.
In reply to pritish jain

Re: trying to understand moodle's .php files

by Justin Wyllie -

Hi Pritish

I had the same problem. The problem is that the stored_file class will not tell you what the file directory is.  It obtains it from file_storage class - which gets it when it is instantiated by the core function get_file_storage (in moodlelib.php).

So to get the file path given a stored_file object $file what I've done is this:

//this is the same code as in get_file_storage

if (isset($CFG->filedir)) {
$filedir = $CFG->filedir;
} else {
$filedir = $CFG->dataroot.'/filedir';
}

//this copied from the protected function get_content_file_location

$contenthash = $file->get_contenthash();
$l1 = $contenthash[0].$contenthash[1];
$l2 = $contenthash[2].$contenthash[3];

$filepath = $filedir.'/'.$l1.'/'.$l2.'/'.$contenthash;

 

But I'm not totally happy with this as I don't like relying on the File API continuing to use that way of determining the file directory.

SO - the other way I can think of would be to use stored_file -> get_content_file_handle() to get a file handle and use that or if I have to have a path then using get_content which gets the file contents and then writing them to a temp file - and then I've got my path. (Or better use copy_content_to($templfilepath)).

 

Justin Wyllie

Average of ratings: Useful (1)
In reply to Justin Wyllie

Re: trying to understand moodle's .php files

by pritish jain -

hello everyone

I have one more question

I want to make a select menu in modeedit.php using moodle API such that data came from that can be stored in mysql in a different table which i have already created . any help is appreciated.

Thanks

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

$choices = $DB->get_records_menu('other_table', ...);

In reply to Tim Hunt

Re: trying to understand moodle's .php files

by pritish jain -

Hi everyone,

I want to upload a file to moodle in which answers of some questions are stored.

and after uploading student must get review of attempt (inckude answers , score)

Any sugestions.

Thanks

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

Hello everyone,

I got the code how to upload a file and start a new attempt using startattempt.php now I am able to to get the records from user . now I need page to be redirected to processattempt.php such i can match the answers and show the review. but I am stuck at this point . I am not able to redirect to processattempt.php. whenever i try to do that i get error like "required parameter attempt is missing" i created an object which retrieve parameter attempt but still it is showing error. Please help

Thanks in advance

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

Hello everyone,

I want to redirect my page from startattempt to processattempt.php in moodle how can i do it . Please help .

Thanks in advance

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

Hello everyone,

Please ignore previous post because now i am able to go to processattempt by passing hidden values. Now can anyone explain how processattempt.php check for answers ? Please help . any help would be deeply appreciated .

Thanks in advance

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

Hi everyone, I need help regarding in which format submitted answers from attempt.php are send to processattempt.php actually i am trying to give the answers from a file . so in which format answers are posted to proceesattempt.php In the same format I would write data in a file and submit it processattempt which will automatically take care of data after that.

Is it in CVS format in question is followed by answers or any other format . for example i tried that suppose question no. is 9 and it's answer id is 30 and another question 10 and its answer id 35 then i wrote like 9,30,10,35 and I also tried 9,answer of 9,10,answer of 10. Is that correct ? actually it restart attempt when i send the data to processattemp.php and question page loads I want that it should process the data and should give review off submiitted answers to student .

any help will be appreciated,

Thanks

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Remember that Moodle is a web application that users access via there web browser.

No data is sent from attempts.php to processattempt.php.

attempt.php generates HTML output that is displayed by the Student's web browser.

When the student clicks the Next button, or equivalent, the user's browser does a form submission (a HTTP POST request) to processattempt.php.

In reply to Tim Hunt

Re: trying to understand moodle's .php files

by pritish jain -

thanks tim for your reply actually i am sending data using post request via form submiision but it is not received at processattempt that is the point where i need help i created a new function called required_param1 in which it post the data otherwise throws a error and it is throwing error like

A required parameter ({$a}) was missing that's where i am stuck

Please help

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi pritish,

It worries me slightly that you've created your own required_param1 function - why aren't you using the built-in required_param?

In reply to Mark Johnson

Re: trying to understand moodle's .php files

by pritish jain -

hi mark

i got my error now i realize i don't need to use my own function.

thanks for reply

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

hi all,

my actual doubt is still not solved in which format answers are submiited either their ids are submiitted or complete answer(in case of multichoice) when next button is pressed.

thanks

pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

hi all,

I got this by printing the object submittedquestionids that only question no. is passed during the post method. then it creates a session where it stores the responses temporarily and check them from data base but i couldn't find the function where it is done please help me in getting the name of function where it temporarily store the data then process it.

Thanks

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

Hi all,

when answer of quiz are submitted to processattempt in which variable they are posted.

Please reply

Thanks

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

Hi all, I got the solution of my own problem name of submitted answer type is

resp(question no.)_ whose value is set which answer user choose and it flagged by resp(question no.)_flagged whise value is 0. they are submitted to processattempt.php in object $responses and are processed further.

Thanks

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

hi all,

I am getting a new problem whenever I try to make a new quiz  i get a error no such attempt id exist.

Please help

regards

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

Hi all,

I have solved my problem . I was using attemptid even before starting the attempt.

regards

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

Hi all,

I want to ask when we select random question from some category in the quiz. then how moodle select random questions . I have seen in database that it create new id and give them type as question and while submiiting the question it gives the same id of answer which is already present in database ? for example it selected question no.2 from databse then it give new id to question. but while posting data id of answer posted remain same as it was previously present in database? please help.

Regards

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

hi all,

I am trying to make a quiz which select question from category randomly. i want to know how random question are selected . if possible please tell me the function and its location then i will be able to do it.

 

Regards

Pritish

In reply to pritish jain

Re: trying to understand moodle's .php files

by pritish jain -

hello all,

I want to create a new string identifier in quiz module. please tell me where to define it.(and help icon too)

Regards

Pritish