3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * This file contains backup and restore output renderers
22 * @copyright 2010 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 * The primary renderer for the backup.
29 * Can be retrieved with the following code:
31 * $renderer = $PAGE->get_renderer('core','backup');
34 * @copyright 2010 Sam Hemelryk
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class core_backup_renderer extends plugin_renderer_base {
39 * Renderers a progress bar for the backup or restore given the items that
41 * @param array $items An array of items
44 public function progress_bar(array $items) {
45 foreach ($items as &$item) {
46 $text = $item['text'];
48 if (array_key_exists('link', $item)) {
49 $link = $item['link'];
51 $item = html_writer::link($link, $text, $item);
53 $item = html_writer::tag('span', $text, $item);
56 return html_writer::tag('div', join(get_separator(), $items), array('class'=>'backup_progress clearfix'));
59 * Prints a dependency notification
60 * @param string $message
63 public function dependency_notification($message) {
64 return html_writer::tag('div', $message, array('class'=>'notification dependencies_enforced'));
68 * Displays the details of a backup file
70 * @param stdClass $details
71 * @param moodle_url $nextstageurl
74 public function backup_details($details, $nextstageurl) {
75 $yestick = $this->output->pix_icon('i/tick_green_big', get_string('yes'));
76 $notick = $this->output->pix_icon('i/cross_red_big', get_string('no'));
78 $html = html_writer::start_tag('div', array('class'=>'backup-restore'));
80 $html .= html_writer::start_tag('div', array('class'=>'backup-section'));
81 $html .= $this->output->heading(get_string('backupdetails', 'backup'), 2, array('class'=>'header'));
82 $html .= $this->backup_detail_pair(get_string('backuptype', 'backup'), get_string('backuptype'.$details->type, 'backup'));
83 $html .= $this->backup_detail_pair(get_string('backupformat', 'backup'), get_string('backupformat'.$details->format, 'backup'));
84 $html .= $this->backup_detail_pair(get_string('backupmode', 'backup'), get_string('backupmode'.$details->mode, 'backup'));
85 $html .= $this->backup_detail_pair(get_string('backupdate', 'backup'), userdate($details->backup_date));
86 $html .= $this->backup_detail_pair(get_string('moodleversion', 'backup'),
87 html_writer::tag('span', $details->moodle_release, array('class'=>'moodle_release')).
88 html_writer::tag('span', '['.$details->moodle_version.']', array('class'=>'moodle_version sub-detail')));
89 $html .= $this->backup_detail_pair(get_string('backupversion', 'backup'),
90 html_writer::tag('span', $details->backup_release, array('class'=>'moodle_release')).
91 html_writer::tag('span', '['.$details->backup_version.']', array('class'=>'moodle_version sub-detail')));
92 $html .= $this->backup_detail_pair(get_string('originalwwwroot', 'backup'),
93 html_writer::tag('span', $details->original_wwwroot, array('class'=>'originalwwwroot')).
94 html_writer::tag('span', '['.$details->original_site_identifier_hash.']', array('class'=>'sitehash sub-detail')));
95 $html .= html_writer::end_tag('div');
97 $html .= html_writer::start_tag('div', array('class'=>'backup-section settings-section'));
98 $html .= $this->output->heading(get_string('backupsettings', 'backup'), 2, array('class'=>'header'));
99 foreach ($details->root_settings as $label=>$value) {
100 if ($label == 'filename') continue;
101 $html .= $this->backup_detail_pair(get_string('rootsetting'.str_replace('_','',$label), 'backup'), $value?$yestick:$notick);
103 $html .= html_writer::end_tag('div');
105 $html .= html_writer::start_tag('div', array('class'=>'backup-section'));
106 $html .= $this->output->heading(get_string('backupcoursedetails', 'backup'), 2, array('class'=>'header'));
107 $html .= $this->backup_detail_pair(get_string('coursetitle', 'backup'), $details->course->title);
108 $html .= $this->backup_detail_pair(get_string('courseid', 'backup'), $details->course->courseid);
110 $html .= html_writer::start_tag('div', array('class'=>'backup-sub-section'));
111 $html .= $this->output->heading(get_string('backupcoursesections', 'backup'), 3, array('class'=>'subheader'));
112 foreach ($details->sections as $key=>$section) {
113 $included = $key.'_included';
114 $userinfo = $key.'_userinfo';
115 if ($section->settings[$included] && $section->settings[$userinfo]) {
116 $value = get_string('sectionincanduser','backup');
117 } else if ($section->settings[$included]) {
118 $value = get_string('sectioninc','backup');
122 $html .= $this->backup_detail_pair(get_string('backupcoursesection', 'backup', $section->title), $value);
124 foreach ($details->activities as $activitykey=>$activity) {
125 if ($activity->sectionid != $section->sectionid) {
129 $table = new html_table();
130 $table->head = array('Module', 'Title', 'Userinfo');
131 $table->colclasses = array('modulename', 'moduletitle', 'userinfoincluded');
132 $table->align = array('left','left', 'center');
133 $table->attributes = array('class'=>'activitytable generaltable');
134 $table->data = array();
136 $table->data[] = array(
137 get_string('pluginname', $activity->modulename),
139 ($activity->settings[$activitykey.'_userinfo'])?$yestick:$notick,
142 if (!empty($table)) {
143 $html .= $this->backup_detail_pair(get_string('sectionactivities','backup'), html_writer::table($table));
147 $html .= html_writer::end_tag('div');
148 $html .= html_writer::end_tag('div');
149 $html .= html_writer::end_tag('div');
151 $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post');
157 * Displays a course selector for restore
159 * @param moodle_url $nextstageurl
160 * @param stdClass $details
161 * @param restore_category_search $categories
162 * @param restore_course_search $courses
163 * @param int $currentcourse
166 public function course_selector(moodle_url $nextstageurl, $details, restore_category_search $categories = null, restore_course_search $courses=null, $currentcourse = null) {
168 require_once($CFG->dirroot.'/course/lib.php');
170 $nextstageurl->param('sesskey', sesskey());
172 $form = html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring()));
173 foreach ($nextstageurl->params() as $key=>$value) {
174 $form .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value));
177 $html = html_writer::start_tag('div', array('class'=>'backup-course-selector backup-restore'));
180 if (!empty($currentcourse)) {
182 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'targetid', 'value'=>$currentcourse));
183 $html .= html_writer::start_tag('div', array('class'=>'bcs-current-course backup-section'));
184 $html .= $this->output->heading(get_string('restoretocurrentcourse', 'backup'), 2, array('class'=>'header'));
185 $html .= $this->backup_detail_input(get_string('restoretocurrentcourseadding', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_ADDING, array('checked'=>'checked'));
186 $html .= $this->backup_detail_input(get_string('restoretocurrentcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_DELETING);
187 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
188 $html .= html_writer::end_tag('div');
189 $html .= html_writer::end_tag('form');
192 if (!empty($categories) && ($categories->get_resultscount() > 0 || $categories->get_search() == '')) {
195 $html .= html_writer::start_tag('div', array('class'=>'bcs-new-course backup-section'));
196 $html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header'));
197 $html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked'));
198 //$html .= $this->backup_detail_select(get_string('coursecategory', 'backup'), 'targetid', $categories);
199 $html .= $this->backup_detail_pair(get_string('selectacategory', 'backup'), $this->render($categories));
200 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
201 $html .= html_writer::end_tag('div');
202 $html .= html_writer::end_tag('form');
205 if (!empty($courses) && ($courses->get_resultscount() > 0 || $courses->get_search() == '')) {
208 $html .= html_writer::start_tag('div', array('class'=>'bcs-existing-course backup-section'));
209 $html .= $this->output->heading(get_string('restoretoexistingcourse', 'backup'), 2, array('class'=>'header'));
210 $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING, array('checked'=>'checked'));
211 $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING);
212 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
213 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
214 $html .= html_writer::end_tag('div');
215 $html .= html_writer::end_tag('form');
218 $html .= html_writer::end_tag('div');
223 * Displays the import course selector
225 * @param moodle_url $nextstageurl
226 * @param import_course_search $courses
229 public function import_course_selector(moodle_url $nextstageurl, import_course_search $courses=null) {
230 $html = html_writer::start_tag('div', array('class'=>'import-course-selector backup-restore'));
231 $html .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring()));
232 foreach ($nextstageurl->params() as $key=>$value) {
233 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value));
235 $html .= html_writer::start_tag('div', array('class'=>'ics-existing-course backup-section'));
236 $html .= $this->output->heading(get_string('importdatafrom'), 2, array('class'=>'header'));
237 $html .= $this->backup_detail_input(get_string('importadding', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_ADDING, array('checked'=>'checked'), get_string('importaddingdesc', 'backup'));
238 $html .= $this->backup_detail_input(get_string('importdeleting', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_DELETING, array(), get_string('importdeletingdesc', 'backup'));
239 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
240 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
241 $html .= html_writer::end_tag('div');
242 $html .= html_writer::end_tag('form');
243 $html .= html_writer::end_tag('div');
248 * Creates a detailed pairing (key + value)
250 * @staticvar int $count
251 * @param string $label
252 * @param string $value
255 protected function backup_detail_pair($label, $value) {
258 $html = html_writer::start_tag('div', array('class'=>'detail-pair'));
259 $html .= html_writer::tag('label', $label, array('class'=>'detail-pair-label', 'for'=>'detail-pair-value-'.$count));
260 $html .= html_writer::tag('div', $value, array('class'=>'detail-pair-value', 'name'=>'detail-pair-value-'.$count));
261 $html .= html_writer::end_tag('div');
266 * Created a detailed pairing with an input
268 * @param string $label
269 * @param string $type
270 * @param string $name
271 * @param string $value
272 * @param array $attributes
273 * @param string|null $description
276 protected function backup_detail_input($label, $type, $name, $value, array $attributes=array(), $description=null) {
277 if (!empty ($description)) {
278 $description = html_writer::tag('span', $description, array('class'=>'description'));
282 return $this->backup_detail_pair($label, html_writer::empty_tag('input', $attributes+array('name'=>$name, 'type'=>$type, 'value'=>$value)).$description);
286 * Creates a detailed pairing with a select
288 * @param string $label
289 * @param string $name
290 * @param array $options
291 * @param string $selected
292 * @param bool $nothing
293 * @param array $attributes
294 * @param string|null $description
297 protected function backup_detail_select($label, $name, $options, $selected='', $nothing=false, array $attributes=array(), $description=null) {
298 if (!empty ($description)) {
299 $description = html_writer::tag('span', $description, array('class'=>'description'));
303 return $this->backup_detail_pair($label, html_writer::select($options, $name, $selected, false, $attributes).$description);
307 * Displays precheck notices
309 * @param array $results
312 public function precheck_notices($results) {
313 $output = html_writer::start_tag('div', array('class'=>'restore-precheck-notices'));
314 if (array_key_exists('errors', $results)) {
315 foreach ($results['errors'] as $error) {
316 $output .= $this->output->notification($error);
319 if (array_key_exists('warnings', $results)) {
320 foreach ($results['warnings'] as $warning) {
321 $output .= $this->output->notification($warning, 'notifywarning notifyproblem');
324 return $output.html_writer::end_tag('div');
328 * Displays substage buttons
330 * @param bool $haserrors
333 public function substage_buttons($haserrors) {
334 $output = html_writer::start_tag('div', array('continuebutton'));
336 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')));
338 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'cancel', 'value'=>get_string('cancel')));
339 $output .= html_writer::end_tag('div');
344 * Displays a role mapping interface
346 * @param array $rolemappings
347 * @param array $roles
350 public function role_mappings($rolemappings, $roles) {
351 $roles[0] = get_string('none');
352 $output = html_writer::start_tag('div', array('class'=>'restore-rolemappings'));
353 $output .= $this->output->heading(get_string('restorerolemappings', 'backup'), 2);
354 foreach ($rolemappings as $id=>$mapping) {
355 $label = $mapping->name;
356 $name = 'mapping'.$id;
357 $selected = $mapping->targetroleid;
358 $output .= $this->backup_detail_select($label, $name, $roles, $mapping->targetroleid, false, array(), $mapping->description);
360 $output .= html_writer::end_tag('div');
365 * Displays a continue button
367 * @param string|moodle_url $url
368 * @param string $method
371 public function continue_button($url, $method='post') {
372 if (!($url instanceof moodle_url)) {
373 $url = new moodle_url($url);
375 if ($method != 'post') {
378 $url->param('sesskey', sesskey());
379 $button = new single_button($url, get_string('continue'), $method);
380 $button->class = 'continuebutton';
381 return $this->render($button);
384 * Print a backup files tree
385 * @param array $options
388 public function backup_files_viewer(array $options = null) {
389 $tree = new backup_files_viewer($options);
390 return $this->render($tree);
394 * Displays a backup files viewer
396 * @global stdClass $USER
397 * @param backup_files_viewer $tree
400 public function render_backup_files_viewer(backup_files_viewer $tree) {
402 $user_context = get_context_instance(CONTEXT_USER, $USER->id);
403 $options = new stdclass;
404 $module = array('name'=>'backup_files_tree', 'fullpath'=>'/backup/util/ui/module.js', 'requires'=>array('yui2-treeview', 'yui2-json'), 'strings'=>array(array('restore', 'moodle')));
405 $htmlid = 'backup-treeview-'.uniqid();
406 $options->htmlid = $htmlid;
407 $options->usercontextid = $user_context->id;
408 $options->currentcontextid = $tree->options['context']->id;
409 $this->page->requires->js_init_call('M.core_backup_files_tree.init', array($options), false, $module);
412 foreach($tree->path as $path) {
418 $html .= '<div id="'.$htmlid.'" class="filemanager-container">';
419 if (empty($tree->tree)) {
420 $html .= get_string('nofilesavailable', 'repository');
423 foreach($tree->tree as $node) {
424 $link_attributes = array();
425 if (!empty($node['isdir'])) {
426 $class = ' class="file-tree-folder"';
429 $class = ' class="file-tree-file"';
430 $link_attributes['target'] = '_blank';
431 $restore_link = html_writer::link($node['restoreurl'], get_string('restore', 'moodle'), $link_attributes);
433 $html .= '<li '.$class.'>';
434 $html .= html_writer::link($node['url'], $node['filename'], $link_attributes);
435 // when js is off, use this restore link
436 // otherwise, yui treeview will generate a restore link in js
437 $html .= ' '.$restore_link;
447 * Renders a restore course search object
449 * @param restore_course_search $component
452 public function render_restore_course_search(restore_course_search $component) {
453 $url = $component->get_url();
455 $output = html_writer::start_tag('div', array('class' => 'restore-course-search'));
456 if ($component->get_totalcount() === 0) {
457 $output .= $this->output->notification(get_string('nomatchingcourses', 'backup'));
458 $output .= html_writer::end_tag('div');
462 $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_totalcount()), array('class'=>'rcs-totalresults'));
464 $output .= html_writer::start_tag('div', array('class' => 'rcs-results'));
465 if ($component->get_totalpages()>1) {
466 $pagingbar = new paging_bar($component->get_totalcount(), $component->get_page(), $component->get_pagelimit(), new moodle_url($url, array('searchcourses'=>1)), restore_course_search::$VAR_PAGE);
467 $output .= $this->output->render($pagingbar);
470 $table = new html_table();
471 $table->head = array('', get_string('shortname'), get_string('fullname'));
472 $table->data = array();
473 foreach ($component->get_results() as $course) {
474 $row = new html_table_row();
475 $row->attributes['class'] = 'rcs-course';
476 if (!$course->visible) {
477 $row->attributes['class'] .= ' dimmed';
480 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$course->id)),
484 $table->data[] = $row;
486 $output .= html_writer::table($table);
487 if (isset($pagingbar)) {
488 $output .= $this->output->render($pagingbar);
490 $output .= html_writer::end_tag('div');
492 $output .= html_writer::start_tag('div', array('class'=>'rcs-search'));
493 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
494 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
495 $output .= html_writer::end_tag('div');
497 $output .= html_writer::end_tag('div');
502 * Renders an import course search object
504 * @param import_course_search $component
507 public function render_import_course_search(import_course_search $component) {
508 $url = $component->get_url();
510 $output = html_writer::start_tag('div', array('class' => 'import-course-search'));
511 if ($component->get_totalcount() === 0) {
512 $output .= $this->output->notification(get_string('nomatchingcourses', 'backup'));
513 $output .= html_writer::end_tag('div');
517 $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_totalcount()), array('class'=>'ics-totalresults'));
519 $output .= html_writer::start_tag('div', array('class' => 'ics-results'));
520 if ($component->get_totalpages()>1) {
521 $pagingbar = new paging_bar($component->get_totalcount(), $component->get_page(), $component->get_pagelimit(), new moodle_url($url, array('searchcourses'=>1)), restore_course_search::$VAR_PAGE);
522 $output .= $this->output->render($pagingbar);
525 $table = new html_table();
526 $table->head = array('', get_string('shortname'), get_string('fullname'));
527 $table->data = array();
528 foreach ($component->get_results() as $course) {
529 $row = new html_table_row();
530 $row->attributes['class'] = 'ics-course';
531 if (!$course->visible) {
532 $row->attributes['class'] .= ' dimmed';
535 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'importid', 'value'=>$course->id)),
539 $table->data[] = $row;
541 $output .= html_writer::table($table);
542 if (isset($pagingbar)) {
543 $output .= $this->output->render($pagingbar);
545 $output .= html_writer::end_tag('div');
547 $output .= html_writer::start_tag('div', array('class'=>'ics-search'));
548 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
549 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
550 $output .= html_writer::end_tag('div');
552 $output .= html_writer::end_tag('div');
557 * Renders a restore category search object
559 * @param restore_category_search $component
562 public function render_restore_category_search(restore_category_search $component) {
563 $url = $component->get_url();
565 $output = html_writer::start_tag('div', array('class' => 'restore-course-search'));
566 if ($component->get_totalcount() === 0) {
567 $output .= $this->output->notification(get_string('nomatchingcourses', 'backup'));
568 $output .= html_writer::end_tag('div');
572 $output .= html_writer::tag('div', get_string('totalcategorysearchresults', 'backup', $component->get_totalcount()), array('class'=>'rcs-totalresults'));
574 $output .= html_writer::start_tag('div', array('class' => 'rcs-results'));
575 if ($component->get_totalpages()>1) {
576 $pagingbar = new paging_bar($component->get_totalcount(), $component->get_page(), $component->get_pagelimit(), new moodle_url($url, array('searchcourses'=>1)), restore_category_search::$VAR_PAGE);
577 $output .= $this->output->render($pagingbar);
580 $table = new html_table();
581 $table->head = array('', get_string('name'), get_string('description'));
582 $table->data = array();
583 foreach ($component->get_results() as $category) {
584 $row = new html_table_row();
585 $row->attributes['class'] = 'rcs-course';
586 if (!$category->visible) {
587 $row->attributes['class'] .= ' dimmed';
590 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$category->id)),
592 format_text($category->description, $category->descriptionformat)
594 $table->data[] = $row;
596 $output .= html_writer::table($table);
597 if (isset($pagingbar)) {
598 $output .= $this->output->render($pagingbar);
600 $output .= html_writer::end_tag('div');
602 $output .= html_writer::start_tag('div', array('class'=>'rcs-search'));
603 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_category_search::$VAR_SEARCH, 'value'=>$component->get_search()));
604 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
605 $output .= html_writer::end_tag('div');
607 $output .= html_writer::end_tag('div');
612 * Data structure representing backup files viewer
614 * @copyright 2010 Dongsheng Cai
615 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
618 class backup_files_viewer implements renderable {
623 * Constructor of backup_files_viewer class
624 * @param array $options
626 public function __construct(array $options = null) {
628 $browser = get_file_browser();
629 $file_info = $browser->get_file_info($options['filecontext'], $options['component'], $options['filearea'], $options['itemid'], $options['filepath'], $options['filename']);
630 $this->options = (array)$options;
632 $this->tree = array();
634 $this->path = array();
635 $this->tree = array();
638 $children = $file_info->get_children();
639 $parent_info = $file_info->get_parent();
641 $level = $parent_info;
642 $this->path = array();
644 $params = $level->get_params();
645 $context = get_context_instance_by_id($params['contextid']);
646 // lock user in course level
647 if ($context->contextlevel == CONTEXT_COURSECAT or $context->contextlevel == CONTEXT_SYSTEM) {
650 $url = new moodle_url('/backup/restorefile.php', $params);
651 $this->path[] = html_writer::link($url->out(false), $level->get_visible_name());
652 $level = $level->get_parent();
654 $this->path = array_reverse($this->path);
655 $this->path[] = $file_info->get_visible_name();
657 $this->add_to_tree($children);
659 if (!empty($options['show_user_backup'])) {
660 $browser = get_file_browser();
661 $user_context = get_context_instance(CONTEXT_USER, $USER->id);
662 $fileinfo = $browser->get_file_info($user_context, null, null, null, null, null);
663 $children = $fileinfo->get_children();
664 $this->add_to_tree($children);
668 function add_to_tree($children) {
669 foreach ($children as $child) {
670 $filedate = $child->get_timemodified();
671 $filesize = $child->get_filesize();
672 $mimetype = $child->get_mimetype();
673 $params = $child->get_params();
676 'filename' => $child->get_visible_name(),
677 'filedate' => $filedate ? userdate($filedate) : '',
678 'filesize' => $filesize ? display_size($filesize) : ''
680 $is_coursebackup = ($params['component'] == 'backup' && in_array($params['filearea'], array('course', 'section', 'activity', 'backup')));
681 $is_userbackup = ($params['component'] == 'user' && $params['filearea'] == 'backup');
682 if ($is_userbackup) {
683 // XXX: hacky, current context
684 $params['contextid'] = $this->options['context']->id;
686 if ($child->is_directory()) {
687 // ignore all other fileares except backup_course backup_section and backup_activity
688 if (!$is_coursebackup and !$is_userbackup) {
691 $fileitem['isdir'] = true;
692 // link to this folder
693 $folderurl = new moodle_url('/backup/restorefile.php', $params);
694 $fileitem['url'] = $folderurl->out(false);
696 $restoreurl = new moodle_url('/backup/restorefile.php', array_merge($params, array('action'=>'choosebackupfile')));
698 $fileitem['url'] = $child->get_url();
699 $fileitem['restoreurl'] = $restoreurl->out(false);
701 $this->tree[] = $fileitem;