I am developing block called "block_mindmap". Block was working very well in Moodle 1.9.x. I am now migrating it to Moodle 2.0. I have a problem with creating file from string.
Code of my function is following:
global $CFG, $COURSE;
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$content = "somecontent";
//HERE IS OLD FUNCTION WHICH CREATES FILE
//$file = fopen($CFG->dataroot.'/'.$COURSE->id.'/'.$filename, "w");
$fs = get_file_storage();
$fileinfo = array(
'contextid' => $context->id, // ID of context
'component' => 'block_mindmap', // usually = table name
'filearea' => 'maps', // usually = table name
'itemid' => 0, // usually = ID of row in table
'filepath' => '/path/', // any path beginning and ending in /
'filename' => '$filename'); // any filename
When I invoke this function with uniqe $filename (diffrent from filename which was set on previous invoking) the function works propertly, I think. But I don't know where to find created file.
When I invoke this function with $filename equal two times in a row, i recieve error message:
Can not create file "829/block_mindmap/maps/0//path//mapY.mm"
So the file was created properly, because function create_file_from_string() can not override file.
I am not sure if I set parameters of $fileinfo array properly. I don't understand using $context in file API either. Notice double "/" in path to file around 'filepath' parameter.
The documentation of migrating code to Moodle 2.0 needs to be improved I think.
Can anybody help me to find created file, or improve my function?