Get Picture out questiontext

Get Picture out questiontext

by Mathias Kohs -
Number of replies: 7

Hello together,

I'm used to work with Moodle1.9 but in Moodle2.x it's different.

I try to get the picture from questions questiontext.
I want to develop a block which uses this pictures.

In the Version 1.9 I extrakted the path and thats it.

In Version 2.3 there is a path like:

I don't now how can i get the file oder filepath out of this path.
The path is used by Quiz like that: www.mymoodle123.com/pluginfile.php?file=/453/question/questiontext/98/1/815/LFILFI.png

I understand:
- 453: is contextid
- question: links to table question
- questiontext links to column

but I can agree with the other params.

Can someone tell me where I finde the other params?
Or it there a better way, to get the picture?

Average of ratings: -
In reply to Mathias Kohs

Re: Get Picture out questiontext

by Joseph Rézeau -
Core developers को तस्बिर Particularly helpful Moodlers को तस्बिर Plugin developers को तस्बिर Testers को तस्बिर Translators को तस्बिर

Hi Mathias,

Yes, the way that files (and picture files) are handled has completely changed in Moodle 2.

It is now much more complicated, but you can do it, with the help of the documentation here:

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

Joseph

In reply to Mathias Kohs

Re: Get Picture out questiontext

by Tim Hunt -
Core developers को तस्बिर Documentation writers को तस्बिर Particularly helpful Moodlers को तस्बिर Peer reviewers को तस्बिर Plugin developers को तस्बिर

Generally, in Moodle 2.x, you should not use an image belonging to one bit of content in an unrelated place. What are you acutally trying to do?

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Get Picture out questiontext

by Mathias Kohs -

I trying to build a Block which deals the quizz-content to a mobile-app.
The block generades ZIP-files. If the app ist asking for, it will get the content.

The app should be used local so it's important that the block get the pictures.

In reply to Mathias Kohs

Re: Get Picture out questiontext

by Tim Hunt -
Core developers को तस्बिर Documentation writers को तस्बिर Particularly helpful Moodlers को तस्बिर Peer reviewers को तस्बिर Plugin developers को तस्बिर

Ah, I see. You are not really creating a block at all. Would it not be better to do this using web services, like the official Moodle mobile app does?

In reply to Tim Hunt

Re: Get Picture out questiontext

by Mathias Kohs -

The Block for Moodle 1.9 which deals the Data is allrady finished.

And for this Block are some Apps build and in use. 

If I want to change the plugin-interface from block to service, it would be more clear but my colleagues would kill me. wink

In reply to Mathias Kohs

Re: Get Picture out questiontext

by Mathias Kohs -

Thanks for showing me the link to File-API.

Where can I find the params for usering the File-API?

I tried to get the File via File-API:

$fs = get_file_storage();
$file = $fs->get_file(453, "question", "questiontext", 814, "/", 'iOS%20Simulator%20Bildschirmfoto%2004.12.2012%2009.42.23.png');

if ($file) {

  $contents = $file->get_content();
  syslog(LOG_INFO, "!TOP!: ");
  $datei = fopen($CFG->dirroot."/blocks/quizztwogo/TEST.png", "w");
  fwrite($datei, $contents);
  fclose($datei);

} else {

  syslog(LOG_INFO, "TEST dont fitt");
}

The problem is, this code don't fit and the $file doesn't exist, after $fs->get_file...

 

In reply to Mathias Kohs

Re: Get Picture out questiontext

by Mathias Kohs -

I have fixxed the Problem.

$file = $fs->get_file(453, "question", "questiontext", 814, "/", 'iOS%20Simulator%20Bildschirmfoto%2004.12.2012%2009.42.23.png');

=>is wrong

I need use $file = $fs->get_file(453, "question", "questiontext", 814, "/", 'iOS 20Simulator 20Bildschirmfoto 2004.12.2012 2009.42.23.png');