/** * get content */ public function get_content() { global $OUTPUT, $CFG; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; // get courses list in wich logged user was enrolled $courses = block_resources_get_all_resources(); if (!$courses) { $this->content->text .= 'There are no courses'; return $this->content; } // --------- cycle by courses foreach ($courses as $course) { if ($course->resources || $course->videoresources) { // render corse box $this->content->text .= $OUTPUT->box_start('coursebox', "course-{$course->id}") . html_writer::start_tag('div', array('class' => 'course_title')); $attributes = array('title' => $course->fullname); if ($course->id > 0) { if (empty($course->visible)) { $attributes['class'] = 'dimmed'; } $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); $link = html_writer::link($courseurl, $coursefullname, $attributes); $this->content->text .= $OUTPUT->heading($link, 2, 'title'); } else { $this->content->text .= $this->output->heading(html_writer::link(new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id=' . $course->remoteid)), format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); } // render resources foreach ($course->resources as $resource) { /// --- Render one resource item $this->content->text .= html_writer::start_div('resource_item') . html_writer::start_div('resource_body') . html_writer::start_div('resource_title') . html_writer::link($resource->url, $resource->title, array('target' => '_blank', 'class' => 'resourcelink', 'data-objectid' => $resource->id)); $this->content->text .= html_writer::end_div(); // end of resource_title // render Author and source if (!empty($resource->author)) { $this->content->text .= html_writer::start_div('resource_metadata') . html_writer::tag('strong', 'Author') . ': ' . $resource->author . html_writer::end_div(); } if (!empty($resource->source)) { $this->content->text .= html_writer::start_div('resource_metadata') . html_writer::tag('strong', 'Source') . ': ' . $resource->source . html_writer::end_div(); } if (!empty($resource->avgrate)) { $this->content->text .= html_writer::start_div('resource_metadata') . html_writer::tag('strong', 'AVG rating') . ': ' . $resource->avgrate . html_writer::end_div(); } //echo html_writer::div($resource->description, 'resource_description'); $this->content->text .= html_writer::end_div(); // end of Resource body --- $this->content->text .= html_writer::end_div(); // end of Resource Item --- } // render videoresources foreach ($course->videoresources as $videoresource) { /// --- Render one resource item $url = new moodle_url("{$CFG->wwwroot}/mod/videoresource/view.php", array('id' => $videoresource->id)); $this->content->text .= html_writer::start_div('resource_item') . html_writer::start_div('resource_body') . html_writer::start_div('resource_title') . html_writer::link($url->out(false), $videoresource->name, array('target' => '_blank', 'class' => 'resourcelink', 'data-objectid' => $videoresource->id)); $this->content->text .= html_writer::end_div(); // end of resource_title //echo html_writer::div($resource->description, 'resource_description'); $this->content->text .= html_writer::end_div(); // end of Resource body --- $this->content->text .= html_writer::end_div(); // end of Resource Item --- } //$this->content->text .= $OUTPUT->box('', 'flush'); $this->content->text .= html_writer::end_tag('div'); $this->content->text .= $OUTPUT->box_end(); } } if (!empty($this->content->text)) { $this->content->text .= html_writer::link($CFG->wwwroot . '/blocks/resources/tocsv.php', 'Download list (CSV)'); } else { $this->content->text .= 'There are no resources'; //$this->content->text .= $OUTPUT->notification(get_string('no_resources', 'resourcelib'), 'redirectmessage'); } return $this->content; }
*/ /// Includes require_once "../../config.php"; require_once 'locallib.php'; // ---settings $delimiter = ';'; $quote = '"'; $eol = "\r\n"; $fileName = 'resources.csv'; $mimeType = 'text/csv'; $terminate = true; $content = ''; // to prevent output before header ob_start(); // ---get course-resources structure $courses = block_resources_get_all_resources(); // ---build CSV string $ifHeader = false; foreach ($courses as $key => $course) { if (!$ifHeader && (!empty($course->resources) || !empty($course->videoresources))) { $content .= implode($delimiter, array('title', 'author', 'source', 'rating')) . $eol; $ifHeader = true; } foreach ($course->resources as $resource) { $content .= implode($delimiter, array($quote . str_replace('"', '""', $resource->title) . $quote, $quote . str_replace('"', '""', $resource->author) . $quote, $quote . str_replace('"', '""', $resource->source) . $quote, $quote . $resource->avgrate . $quote)) . $eol; } foreach ($course->videoresources as $resource) { $content .= implode($delimiter, array($quote . str_replace('"', '""', $resource->name) . $quote, $quote . $quote, $quote . $quote, $quote . $quote)) . $eol; } } // ---send content