Hi! I'm trying to get a list with all files from course which are set to visible and show it inside a block. Could anyone help with a piece of code for doing that or some advice?
Thank you!
John,
I recommend reading up on the documentation for the file API's
http://docs.moodle.org/dev/File_API
There is a section called "List area files" that may have what you need. Although the example is fetching the mod_assignment component and the submissions file area. You want the component to be course and the filearea to be "any."
Hope that helps get your started.
Thanks a lot for your reply! I tried the code but it doesn't output anything. Should this code work inside blocks?
Thank you!
Here is my code
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Blog Menu Block page.
*
* @package block
* @subpackage blog_menu
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* The blog menu block class
*/
class block_search_assistant extends block_base {
function init() {
$this->title = get_string('pluginname', 'block_search_assistant');
}
function instance_allow_multiple() {
return true;
}
function has_config() {
return false;
}
function applicable_formats() {
return array('all' => true, 'my' => false, 'tag' => false);
}
function instance_allow_config() {
return true;
}
function get_content() {
global $CFG;
// detect if blog enabled
if ($this->content !== NULL) {
return $this->content;
}
$fs = get_file_storage();
$files = $fs->get_area_files($contextid, 'course', 'any', $submission->id);
foreach ($files as $f) {
// $f is an instance of stored_file
echo $f->get_filename();
}
// Return the content object
return $this->content;
}
}
?>