Exemplo n.º 1
0
 public function test_preview()
 {
     global $DB;
     $this->resetAfterTest(true);
     $content = array("shortname,fullname,summary", "c1,Course 1,Course 1 summary", "c2,Course 2,Course 2 summary");
     $content = implode("\n", $content);
     $iid = csv_import_reader::get_new_iid('uploadcourse');
     $cir = new csv_import_reader($iid, 'uploadcourse');
     $cir->load_csv_content($content, 'utf-8', 'comma');
     $cir->init();
     $options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_ALL);
     $defaults = array('category' => '1');
     $p = new tool_uploadcourse_processor($cir, $options, $defaults);
     // Nothing special to expect here, just make sure no exceptions are thrown.
     $p->preview();
 }
Exemplo n.º 2
0
        $defaults = (array) $form2data->defaults;
        // Restorefile deserves its own logic because formslib does not really appreciate
        // when the name of a filepicker is an array...
        $options['restorefile'] = '';
        if (!empty($form2data->restorefile)) {
            $options['restorefile'] = $mform2->save_temp_file('restorefile');
        }
        $processor = new tool_uploadcourse_processor($cir, $options, $defaults);
        echo $OUTPUT->header();
        if (isset($form2data->showpreview)) {
            echo $OUTPUT->heading(get_string('uploadcoursespreview', 'tool_uploadcourse'));
            $processor->preview($previewrows, new tool_uploadcourse_tracker(tool_uploadcourse_tracker::OUTPUT_HTML));
            $mform2->display();
        } else {
            echo $OUTPUT->heading(get_string('uploadcoursesresult', 'tool_uploadcourse'));
            $processor->execute(new tool_uploadcourse_tracker(tool_uploadcourse_tracker::OUTPUT_HTML));
            echo $OUTPUT->continue_button($returnurl);
        }
        // Deleting the file after processing or preview.
        if (!empty($options['restorefile'])) {
            @unlink($options['restorefile']);
        }
    } else {
        $processor = new tool_uploadcourse_processor($cir, $form1data->options, array());
        echo $OUTPUT->header();
        echo $OUTPUT->heading(get_string('uploadcoursespreview', 'tool_uploadcourse'));
        $processor->preview($previewrows, new tool_uploadcourse_tracker(tool_uploadcourse_tracker::OUTPUT_HTML));
        $mform2->display();
    }
}
echo $OUTPUT->footer();