Пример #1
0
 public function test_shortname_template()
 {
     global $DB;
     $this->resetAfterTest(true);
     $content = array("shortname,fullname,summary,idnumber", ",Course 1,C1 Summary,ID123");
     $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_NEW, 'shortnametemplate' => '%i: %f');
     $defaults = array('category' => '1');
     $p = new tool_uploadcourse_processor($cir, $options, $defaults);
     $this->assertFalse($DB->record_exists('course', array('idnumber' => 'ID123')));
     $p->execute();
     $this->assertTrue($DB->record_exists('course', array('idnumber' => 'ID123')));
     $c = $DB->get_record('course', array('idnumber' => 'ID123'));
     $this->assertEquals('ID123: Course 1', $c->shortname);
 }
Пример #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();