Exemplo n.º 1
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();
Exemplo n.º 2
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.º 3
0
// Course template.
if (isset($options['templatecourse'])) {
    $processoroptions['templatecourse'] = $options['templatecourse'];
}
// Restore file.
if ($options['restorefile']) {
    $options['restorefile'] = realpath($options['restorefile']);
}
if ($options['restorefile'] && !file_exists($options['restorefile'])) {
    echo get_string('invalidrestorefile', 'tool_uploadcourse') . "\n";
    echo $help;
    die;
}
$processoroptions['restorefile'] = $options['restorefile'];
// Emulate normal session.
cron_setup_user();
// Let's get started!
$content = file_get_contents($options['file']);
$importid = csv_import_reader::get_new_iid('uploadcourse');
$cir = new csv_import_reader($importid, 'uploadcourse');
$readcount = $cir->load_csv_content($content, $options['encoding'], $options['delimiter']);
unset($content);
if ($readcount === false) {
    print_error('csvfileerror', 'tool_uploadcourse', '', $cir->get_error());
} else {
    if ($readcount == 0) {
        print_error('csvemptyfile', 'error', '', $cir->get_error());
    }
}
$processor = new tool_uploadcourse_processor($cir, $processoroptions, $defaults);
$processor->execute(new tool_uploadcourse_tracker(tool_uploadcourse_tracker::OUTPUT_PLAIN));