mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'wip-MDL-57292-master' of git://github.com/abgreeve/moodle
This commit is contained in:
commit
83c7b312cd
@ -53,6 +53,10 @@ class framework_importer {
|
||||
protected $importer = null;
|
||||
protected $foundheaders = array();
|
||||
protected $scalecache = array();
|
||||
/** @var bool $useprogressbar Control whether importing should use progress bars or not. */
|
||||
protected $useprogressbar = false;
|
||||
/** @var \core\progress\display_if_slow|null $progress The progress bar instance. */
|
||||
protected $progress = null;
|
||||
|
||||
/**
|
||||
* Store an error message for display later
|
||||
@ -164,8 +168,11 @@ class framework_importer {
|
||||
* @param string delimiter The specified delimiter for the file.
|
||||
* @param string importid The id of the csv import.
|
||||
* @param array mappingdata The mapping data from the import form.
|
||||
* @param bool $useprogressbar Whether progress bar should be displayed, to avoid html output on CLI.
|
||||
*/
|
||||
public function __construct($text = null, $encoding = null, $delimiter = null, $importid = 0, $mappingdata = null) {
|
||||
public function __construct($text = null, $encoding = null, $delimiter = null, $importid = 0, $mappingdata = null,
|
||||
$useprogressbar = false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
// The format of our records is:
|
||||
@ -204,7 +211,7 @@ class framework_importer {
|
||||
}
|
||||
|
||||
$this->foundheaders = $this->importer->get_columns();
|
||||
|
||||
$this->useprogressbar = $useprogressbar;
|
||||
$domainid = 1;
|
||||
|
||||
$flat = array();
|
||||
@ -264,8 +271,19 @@ class framework_importer {
|
||||
$this->fail(get_string('invalidimportfile', 'tool_lpimportcsv'));
|
||||
return;
|
||||
} else {
|
||||
// We are calling from browser, display progress bar.
|
||||
if ($this->useprogressbar === true) {
|
||||
$this->progress = new \core\progress\display_if_slow(get_string('processingfile', 'tool_lpimportcsv'));
|
||||
$this->progress->start_html();
|
||||
} else {
|
||||
// Avoid html output on CLI scripts.
|
||||
$this->progress = new \core\progress\none();
|
||||
}
|
||||
$this->progress->start_progress('', count($this->flat));
|
||||
// Build a tree from this flat list.
|
||||
raise_memory_limit(MEMORY_EXTRA);
|
||||
$this->add_children($this->framework, '');
|
||||
$this->progress->end_progress();
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,6 +296,7 @@ class framework_importer {
|
||||
public function add_children(& $node, $parentidnumber) {
|
||||
foreach ($this->flat as $competency) {
|
||||
if ($competency->parentidnumber == $parentidnumber) {
|
||||
$this->progress->increment_progress();
|
||||
$node->children[] = $competency;
|
||||
$this->add_children($competency, $competency->idnumber);
|
||||
}
|
||||
@ -443,17 +462,28 @@ class framework_importer {
|
||||
$record->contextid = context_system::instance()->id;
|
||||
|
||||
$framework = api::create_framework($record);
|
||||
if ($this->useprogressbar === true) {
|
||||
$this->progress = new \core\progress\display_if_slow(get_string('importingfile', 'tool_lpimportcsv'));
|
||||
$this->progress->start_html();
|
||||
} else {
|
||||
$this->progress = new \core\progress\none();
|
||||
}
|
||||
|
||||
$this->progress->start_progress('', (count($this->framework->children) * 2));
|
||||
raise_memory_limit(MEMORY_EXTRA);
|
||||
// Now all the children.
|
||||
foreach ($this->framework->children as $comp) {
|
||||
$this->progress->increment_progress();
|
||||
$this->create_competency($comp, null, $framework);
|
||||
}
|
||||
|
||||
// Now create the rules.
|
||||
foreach ($this->framework->children as $record) {
|
||||
$this->progress->increment_progress();
|
||||
$this->set_rules($record);
|
||||
$this->set_related($record);
|
||||
}
|
||||
$this->progress->end_progress();
|
||||
|
||||
$this->importer->cleanup();
|
||||
return $framework;
|
||||
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Page to continue after an action.
|
||||
*
|
||||
* @package tool_lpimportcsv
|
||||
* @copyright 2015 Damyon Wiese
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$pagetitle = get_string('pluginname', 'tool_lpimportcsv');
|
||||
|
||||
$context = context_system::instance();
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$url = new moodle_url("/admin/tool/lpimportcsv/index.php");
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_title($pagetitle);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_heading($pagetitle);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($pagetitle);
|
||||
$urlparams = ['competencyframeworkid' => $id, 'pagecontextid' => $context->id];
|
||||
$frameworksurl = new moodle_url('/admin/tool/lp/competencies.php', $urlparams);
|
||||
echo $OUTPUT->notification(get_string('competencyframeworkcreated', 'tool_lp'), 'notifysuccess');
|
||||
echo $OUTPUT->continue_button($frameworksurl);
|
||||
|
||||
echo $OUTPUT->footer();
|
@ -37,6 +37,7 @@ $PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_heading($pagetitle);
|
||||
|
||||
$form = null;
|
||||
echo $OUTPUT->header();
|
||||
if (optional_param('needsconfirm', 0, PARAM_BOOL)) {
|
||||
$form = new \tool_lpimportcsv\form\import($url->out(false));
|
||||
} else if (optional_param('confirm', 0, PARAM_BOOL)) {
|
||||
@ -53,7 +54,7 @@ if ($form->is_cancelled()) {
|
||||
|
||||
if ($data->confirm) {
|
||||
$importid = $data->importid;
|
||||
$importer = new \tool_lpimportcsv\framework_importer(null, null, null, $importid, $data);
|
||||
$importer = new \tool_lpimportcsv\framework_importer(null, null, null, $importid, $data, true);
|
||||
|
||||
$error = $importer->get_error();
|
||||
if ($error) {
|
||||
@ -61,21 +62,23 @@ if ($form->is_cancelled()) {
|
||||
$form->set_import_error($error);
|
||||
} else {
|
||||
$framework = $importer->import();
|
||||
redirect(new moodle_url('continue.php', array('id' => $framework->get_id())));
|
||||
$urlparams = ['competencyframeworkid' => $framework->get_id(), 'pagecontextid' => $context->id];
|
||||
$frameworksurl = new moodle_url('/admin/tool/lp/competencies.php', $urlparams);
|
||||
echo $OUTPUT->notification(get_string('competencyframeworkcreated', 'tool_lp'), 'notifysuccess');
|
||||
echo $OUTPUT->continue_button($frameworksurl);
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
$text = $form->get_file_content('importfile');
|
||||
$encoding = $data->encoding;
|
||||
$delimiter = $data->delimiter_name;
|
||||
$importer = new \tool_lpimportcsv\framework_importer($text, $encoding, $delimiter);
|
||||
$importer = new \tool_lpimportcsv\framework_importer($text, $encoding, $delimiter, 0, null, true);
|
||||
$confirmform = new \tool_lpimportcsv\form\import_confirm(null, $importer);
|
||||
$form = $confirmform;
|
||||
$pagetitle = get_string('confirmcolumnmappings', 'tool_lpimportcsv');
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($pagetitle);
|
||||
|
||||
$form->display();
|
||||
|
@ -38,11 +38,13 @@ $string['importfile'] = 'CSV framework description file';
|
||||
$string['importfile_help'] = 'A competency framework may be imported via text file. The format of the file can be determined by creating a new competency framework on the site and then exporting it.';
|
||||
$string['importfile_link'] = 'admin/tool/lpimportcsv';
|
||||
$string['import'] = 'Import';
|
||||
$string['importingfile'] = 'Importing file data';
|
||||
$string['invalidimportfile'] = 'File format is invalid.';
|
||||
$string['isframework'] = 'Is framework';
|
||||
$string['noframeworks'] = 'No competency frameworks have been created yet';
|
||||
$string['parentidnumber'] = 'Parent ID number';
|
||||
$string['pluginname'] = 'Import competency framework';
|
||||
$string['processingfile'] = 'Processing file';
|
||||
$string['relatedidnumbers'] = 'Cross-referenced competency ID numbers';
|
||||
$string['ruleconfig'] = 'Rule config (optional)';
|
||||
$string['ruleoutcome'] = 'Rule outcome (optional)';
|
||||
|
Loading…
x
Reference in New Issue
Block a user