From 5e4fffa013631ff73447f4da86769b092908bd59 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Tue, 30 Aug 2016 10:59:05 +0800 Subject: [PATCH] MDL-55767 tool_lpimportcsv: import/export competency fmwks --- .../tool/lpimportcsv/classes/form/export.php | 68 +++ .../tool/lpimportcsv/classes/form/import.php | 88 ++++ .../classes/form/import_confirm.php | 75 +++ .../classes/framework_exporter.php | 147 ++++++ .../classes/framework_importer.php | 455 ++++++++++++++++++ admin/tool/lpimportcsv/continue.php | 47 ++ admin/tool/lpimportcsv/export.php | 57 +++ admin/tool/lpimportcsv/index.php | 83 ++++ .../lpimportcsv/lang/en/tool_lpimportcsv.php | 53 ++ admin/tool/lpimportcsv/settings.php | 46 ++ .../lpimportcsv/tests/fixtures/example.csv | 209 ++++++++ admin/tool/lpimportcsv/tests/import_test.php | 62 +++ admin/tool/lpimportcsv/version.php | 32 ++ lib/classes/plugin_manager.php | 2 +- 14 files changed, 1423 insertions(+), 1 deletion(-) create mode 100644 admin/tool/lpimportcsv/classes/form/export.php create mode 100644 admin/tool/lpimportcsv/classes/form/import.php create mode 100644 admin/tool/lpimportcsv/classes/form/import_confirm.php create mode 100644 admin/tool/lpimportcsv/classes/framework_exporter.php create mode 100644 admin/tool/lpimportcsv/classes/framework_importer.php create mode 100644 admin/tool/lpimportcsv/continue.php create mode 100644 admin/tool/lpimportcsv/export.php create mode 100644 admin/tool/lpimportcsv/index.php create mode 100644 admin/tool/lpimportcsv/lang/en/tool_lpimportcsv.php create mode 100644 admin/tool/lpimportcsv/settings.php create mode 100644 admin/tool/lpimportcsv/tests/fixtures/example.csv create mode 100644 admin/tool/lpimportcsv/tests/import_test.php create mode 100644 admin/tool/lpimportcsv/version.php diff --git a/admin/tool/lpimportcsv/classes/form/export.php b/admin/tool/lpimportcsv/classes/form/export.php new file mode 100644 index 00000000000..1eac37f9a13 --- /dev/null +++ b/admin/tool/lpimportcsv/classes/form/export.php @@ -0,0 +1,68 @@ +. + +/** + * This file contains the form export a competency framework. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lpimportcsv\form; + +defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); + +use moodleform; +use context_system; +use core_competency\api; + +require_once($CFG->libdir.'/formslib.php'); + +/** + * Export Competency framework form. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class export extends moodleform { + + /** + * Define the form - called by parent constructor + */ + public function definition() { + $mform = $this->_form; + + $context = context_system::instance(); + $frameworks = api::list_frameworks('shortname', 'ASC', null, null, $context); + $options = array(); + foreach ($frameworks as $framework) { + + $options[$framework->get_id()] = $framework->get_shortname(); + } + if (empty($options)) { + $mform->addElement('static', 'frameworkid', '', get_string('noframeworks', 'tool_lpimportcsv')); + } else { + $mform->addElement('select', 'frameworkid', get_string('competencyframework', 'tool_lp'), $options); + $mform->setType('frameworkid', PARAM_INT); + $mform->addRule('frameworkid', null, 'required', null, 'client'); + $this->add_action_buttons(true, get_string('export', 'tool_lpimportcsv')); + } + $mform->setDisableShortforms(); + } + +} diff --git a/admin/tool/lpimportcsv/classes/form/import.php b/admin/tool/lpimportcsv/classes/form/import.php new file mode 100644 index 00000000000..d2c8071d42f --- /dev/null +++ b/admin/tool/lpimportcsv/classes/form/import.php @@ -0,0 +1,88 @@ +. + +/** + * This file contains the form for importing a framework from a file. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lpimportcsv\form; + +defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); + +use moodleform; +use core_competency\api; +use core_text; +use csv_import_reader; + +require_once($CFG->libdir.'/formslib.php'); + +/** + * Import Competency framework form. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class import extends moodleform { + + /** + * Define the form - called by parent constructor + */ + public function definition() { + global $CFG; + require_once($CFG->libdir . '/csvlib.class.php'); + + $mform = $this->_form; + $element = $mform->createElement('filepicker', 'importfile', get_string('importfile', 'tool_lpimportcsv')); + $mform->addElement($element); + $mform->addRule('importfile', null, 'required'); + $mform->addElement('hidden', 'confirm', 0); + $mform->setType('confirm', PARAM_BOOL); + + $choices = csv_import_reader::get_delimiter_list(); + $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_lpimportcsv'), $choices); + if (array_key_exists('cfg', $choices)) { + $mform->setDefault('delimiter_name', 'cfg'); + } else if (get_string('listsep', 'langconfig') == ';') { + $mform->setDefault('delimiter_name', 'semicolon'); + } else { + $mform->setDefault('delimiter_name', 'comma'); + } + $mform->addHelpButton('delimiter_name', 'csvdelimiter', 'tool_lpimportcsv'); + + $choices = core_text::get_encodings(); + $mform->addElement('select', 'encoding', get_string('encoding', 'tool_lpimportcsv'), $choices); + $mform->setDefault('encoding', 'UTF-8'); + $mform->addHelpButton('encoding', 'encoding', 'tool_lpimportcsv'); + + $this->add_action_buttons(false, get_string('import', 'tool_lpimportcsv')); + } + + /** + * Display an error on the import form. + * @param string $msg + */ + public function set_import_error($msg) { + $mform = $this->_form; + + $mform->setElementError('importfile', $msg); + } + +} diff --git a/admin/tool/lpimportcsv/classes/form/import_confirm.php b/admin/tool/lpimportcsv/classes/form/import_confirm.php new file mode 100644 index 00000000000..33d59188fbf --- /dev/null +++ b/admin/tool/lpimportcsv/classes/form/import_confirm.php @@ -0,0 +1,75 @@ +. + +/** + * This file contains the form to confirm the import options for a framework. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lpimportcsv\form; + +defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); + +use moodleform; +use core_competency\api; +use tool_lpimportcsv\framework_importer; + +require_once($CFG->libdir.'/formslib.php'); + +/** + * Import Competency framework form. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class import_confirm extends moodleform { + + /** + * Define the form - called by parent constructor + */ + public function definition() { + $importer = $this->_customdata; + + $mform = $this->_form; + $mform->addElement('hidden', 'confirm', 1); + $mform->setType('confirm', PARAM_BOOL); + $mform->addElement('hidden', 'importid', $importer->get_importid()); + $mform->setType('importid', PARAM_INT); + + $requiredheaders = $importer->list_required_headers(); + $foundheaders = $importer->list_found_headers(); + + if (empty($foundheaders)) { + $foundheaders = range(0, count($requiredheaders)); + } + $foundheaders[-1] = get_string('none'); + + foreach ($requiredheaders as $index => $requiredheader) { + $mform->addElement('select', 'header' . $index, $requiredheader, $foundheaders); + if (isset($foundheaders[$index])) { + $mform->setDefault('header' . $index, $index); + } else { + $mform->setDefault('header' . $index, -1); + } + } + + $this->add_action_buttons(true, get_string('confirm', 'tool_lpimportcsv')); + } +} diff --git a/admin/tool/lpimportcsv/classes/framework_exporter.php b/admin/tool/lpimportcsv/classes/framework_exporter.php new file mode 100644 index 00000000000..e507dd90f6b --- /dev/null +++ b/admin/tool/lpimportcsv/classes/framework_exporter.php @@ -0,0 +1,147 @@ +. + +/** + * This file contains the csv exporter for a competency framework. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lpimportcsv; + +defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); + +use core_competency\api; +use stdClass; +use csv_export_writer; + +/** + * Export Competency framework. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class framework_exporter { + + /** @var $framework \core_competency\competency_framework */ + protected $framework = null; + + /** @var $error string */ + protected $error = ''; + + /** + * Constructor + * @param int $frameworkid The framework id + */ + public function __construct($frameworkid) { + $this->framework = api::read_framework($frameworkid); + } + + /** + * Export all the competencies from this framework to a csv file. + */ + public function export() { + global $CFG; + require_once($CFG->libdir . '/csvlib.class.php'); + + $writer = new csv_export_writer(); + $filename = clean_param($this->framework->get_shortname() . '-' . $this->framework->get_idnumber(), PARAM_FILE); + $writer->set_filename($filename); + + $headers = framework_importer::list_required_headers(); + + $writer->add_data($headers); + + // Order and number of columns must match framework_importer::list_required_headers(). + $row = array( + '', + $this->framework->get_idnumber(), + $this->framework->get_shortname(), + $this->framework->get_description(), + $this->framework->get_descriptionformat(), + $this->framework->get_scale()->compact_items(), + $this->framework->get_scaleconfiguration(), + '', + '', + '', + '', + '', + true, + implode(',', $this->framework->get_taxonomies()) + ); + $writer->add_data($row); + + $filters = array('competencyframeworkid' => $this->framework->get_id()); + $competencies = api::list_competencies($filters); + // Index by id so we can lookup parents. + $indexed = array(); + foreach ($competencies as $competency) { + $indexed[$competency->get_id()] = $competency; + } + foreach ($competencies as $competency) { + $parentidnumber = ''; + if ($competency->get_parentid() > 0) { + $parent = $indexed[$competency->get_parentid()]; + $parentidnumber = $parent->get_idnumber(); + } + + $scalevalues = ''; + $scaleconfig = ''; + if ($competency->get_scaleid() !== null) { + $scalevalues = $competency->get_scale()->compact_items(); + $scaleconfig = $competency->get_scaleconfiguration(); + } + + $ruleconfig = $competency->get_ruleconfig(); + if ($ruleconfig === null) { + $ruleconfig = "null"; + } + + $allrelated = $competency->get_related_competencies(); + + $relatedidnumbers = array(); + foreach ($allrelated as $onerelated) { + $relatedidnumbers[] = str_replace(',', '%2C', $onerelated->get_idnumber()); + } + $relatedidnumbers = implode(',', $relatedidnumbers); + + // Order and number of columns must match framework_importer::list_required_headers(). + $row = array( + $parentidnumber, + $competency->get_idnumber(), + $competency->get_shortname(), + $competency->get_description(), + $competency->get_descriptionformat(), + $scalevalues, + $scaleconfig, + $competency->get_ruletype(), + $competency->get_ruleoutcome(), + $ruleconfig, + $relatedidnumbers, + $competency->get_id(), + false, + '' + ); + + $writer->add_data($row); + } + + $writer->download_file(); + } +} diff --git a/admin/tool/lpimportcsv/classes/framework_importer.php b/admin/tool/lpimportcsv/classes/framework_importer.php new file mode 100644 index 00000000000..66130728b89 --- /dev/null +++ b/admin/tool/lpimportcsv/classes/framework_importer.php @@ -0,0 +1,455 @@ +. + +/** + * This file contains the class to import a competency framework. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lpimportcsv; + +defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); + +use core_competency\api; +use grade_scale; +use stdClass; +use context_system; +use csv_import_reader; + +/** + * This file contains the class to import a competency framework. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class framework_importer { + + /** @var string $error The errors message from reading the xml */ + protected $error = ''; + + /** @var array $flat The flat competencies tree */ + protected $flat = array(); + /** @var array $framework The framework info */ + protected $framework = array(); + protected $mappings = array(); + protected $importid = 0; + protected $importer = null; + protected $foundheaders = array(); + + /** + * Store an error message for display later + * @param string $msg + */ + public function fail($msg) { + $this->error = $msg; + return false; + } + + /** + * Get the CSV import id + * @return string The import id. + */ + public function get_importid() { + return $this->importid; + } + + /** + * Get the list of headers required for import. + * @return array The headers (lang strings) + */ + public static function list_required_headers() { + return array( + get_string('parentidnumber', 'tool_lpimportcsv'), + get_string('idnumber', 'tool_lpimportcsv'), + get_string('shortname', 'tool_lpimportcsv'), + get_string('description', 'tool_lpimportcsv'), + get_string('descriptionformat', 'tool_lpimportcsv'), + get_string('scalevalues', 'tool_lpimportcsv'), + get_string('scaleconfiguration', 'tool_lpimportcsv'), + get_string('ruletype', 'tool_lpimportcsv'), + get_string('ruleoutcome', 'tool_lpimportcsv'), + get_string('ruleconfig', 'tool_lpimportcsv'), + get_string('relatedidnumbers', 'tool_lpimportcsv'), + get_string('exportid', 'tool_lpimportcsv'), + get_string('isframework', 'tool_lpimportcsv'), + get_string('taxonomy', 'tool_lpimportcsv'), + ); + } + + /** + * Get the list of headers found in the import. + * @return array The found headers (names from import) + */ + public function list_found_headers() { + return $this->foundheaders; + } + + /** + * Read the data from the mapping form. + * @param array The mapping data. + */ + protected function read_mapping_data($data) { + if ($data) { + return array( + 'parentidnumber' => $data->header0, + 'idnumber' => $data->header1, + 'shortname' => $data->header2, + 'description' => $data->header3, + 'descriptionformat' => $data->header4, + 'scalevalues' => $data->header5, + 'scaleconfiguration' => $data->header6, + 'ruletype' => $data->header7, + 'ruleoutcome' => $data->header8, + 'ruleconfig' => $data->header9, + 'relatedidnumbers' => $data->header10, + 'exportid' => $data->header11, + 'isframework' => $data->header12, + 'taxonomies' => $data->header13 + ); + } else { + return array( + 'parentidnumber' => 0, + 'idnumber' => 1, + 'shortname' => 2, + 'description' => 3, + 'descriptionformat' => 4, + 'scalevalues' => 5, + 'scaleconfiguration' => 6, + 'ruletype' => 7, + 'ruleoutcome' => 8, + 'ruleconfig' => 9, + 'relatedidnumbers' => 10, + 'exportid' => 11, + 'isframework' => 12, + 'taxonomies' => 13 + ); + } + } + + /** + * Get the a column from the imported data. + * @param array The imported raw row + * @param index The column index we want + * @return string The column data. + */ + protected function get_column_data($row, $index) { + if ($index < 0) { + return ''; + } + return isset($row[$index]) ? $row[$index] : ''; + } + + /** + * Constructor - parses the raw text for sanity. + * @param string $text The raw csv text. + * @param string $encoding The encoding of the csv file. + * @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. + */ + public function __construct($text = null, $encoding = null, $delimiter = null, $importid = 0, $mappingdata = null) { + global $CFG; + + // The format of our records is: + // Parent ID number, ID number, Shortname, Description, Description format, Scale values, Scale configuration, + // Rule type, Rule outcome, Rule config, Is framework, Taxonomy. + + // The idnumber is concatenated with the category names. + require_once($CFG->libdir . '/csvlib.class.php'); + + $type = 'competency_framework'; + + if (!$importid) { + if ($text === null) { + return; + } + $this->importid = csv_import_reader::get_new_iid($type); + + $this->importer = new csv_import_reader($this->importid, $type); + + if (!$this->importer->load_csv_content($text, $encoding, $delimiter)) { + $this->fail(get_string('invalidimportfile', 'tool_lpimportcsv')); + $this->importer->cleanup(); + return; + } + + } else { + $this->importid = $importid; + + $this->importer = new csv_import_reader($this->importid, $type); + } + + if (!$this->importer->init()) { + $this->fail(get_string('invalidimportfile', 'tool_lpimportcsv')); + $this->importer->cleanup(); + return; + } + + $this->foundheaders = $this->importer->get_columns(); + + $domainid = 1; + + $flat = array(); + $framework = null; + + while ($row = $this->importer->next()) { + $mapping = $this->read_mapping_data($mappingdata); + + $parentidnumber = $this->get_column_data($row, $mapping['parentidnumber']); + $idnumber = $this->get_column_data($row, $mapping['idnumber']); + $shortname = $this->get_column_data($row, $mapping['shortname']); + $description = $this->get_column_data($row, $mapping['description']); + $descriptionformat = $this->get_column_data($row, $mapping['descriptionformat']); + $scalevalues = $this->get_column_data($row, $mapping['scalevalues']); + $scaleconfiguration = $this->get_column_data($row, $mapping['scaleconfiguration']); + $ruletype = $this->get_column_data($row, $mapping['ruletype']); + $ruleoutcome = $this->get_column_data($row, $mapping['ruleoutcome']); + $ruleconfig = $this->get_column_data($row, $mapping['ruleconfig']); + $relatedidnumbers = $this->get_column_data($row, $mapping['relatedidnumbers']); + $exportid = $this->get_column_data($row, $mapping['exportid']); + $isframework = $this->get_column_data($row, $mapping['isframework']); + $taxonomies = $this->get_column_data($row, $mapping['taxonomies']); + + if ($isframework) { + $framework = new stdClass(); + $framework->idnumber = shorten_text(clean_param($idnumber, PARAM_TEXT), 100); + $framework->shortname = shorten_text(clean_param($shortname, PARAM_TEXT), 100); + $framework->description = clean_param($description, PARAM_RAW); + $framework->descriptionformat = clean_param($descriptionformat, PARAM_INT); + $framework->scalevalues = $scalevalues; + $framework->scaleconfiguration = $scaleconfiguration; + $framework->taxonomies = $taxonomies; + $framework->children = array(); + } else { + $competency = new stdClass(); + $competency->parentidnumber = clean_param($parentidnumber, PARAM_TEXT); + $competency->idnumber = shorten_text(clean_param($idnumber, PARAM_TEXT), 100); + $competency->shortname = shorten_text(clean_param($shortname, PARAM_TEXT), 100); + $competency->description = clean_param($description, PARAM_RAW); + $competency->descriptionformat = clean_param($descriptionformat, PARAM_INT); + $competency->ruletype = $ruletype; + $competency->ruleoutcome = clean_param($ruleoutcome, PARAM_INT); + $competency->ruleconfig = $ruleconfig; + $competency->relatedidnumbers = $relatedidnumbers; + $competency->exportid = $exportid; + $competency->scalevalues = $scalevalues; + $competency->scaleconfiguration = $scaleconfiguration; + $competency->children = array(); + $flat[$idnumber] = $competency; + } + } + $this->flat = $flat; + $this->framework = $framework; + + $this->importer->close(); + if ($this->framework == null) { + $this->fail(get_string('invalidimportfile', 'tool_lpimportcsv')); + return; + } else { + // Build a tree from this flat list. + $this->add_children($this->framework, ''); + } + } + + /** + * Add a competency to the parent with the specified idnumber. + * + * @param competency $node (pass by reference) + * @param string $parentidnumber Add this competency to the parent with this idnumber. + */ + public function add_children(& $node, $parentidnumber) { + foreach ($this->flat as $competency) { + if ($competency->parentidnumber == $parentidnumber) { + $node->children[] = $competency; + $this->add_children($competency, $competency->idnumber); + } + } + } + + /** + * Get parse errors. + * @return array of errors from parsing the xml. + */ + public function get_error() { + return $this->error; + } + + /** + * Recursive function to add a competency with all it's children. + * + * @param stdClass $record Raw data for the new competency + * @param competency $parent + * @param competency_framework $framework + */ + public function create_competency($record, $parent, $framework) { + $competency = new stdClass(); + $competency->competencyframeworkid = $framework->get_id(); + $competency->shortname = $record->shortname; + if (!empty($record->description)) { + $competency->description = $record->description; + $competency->descriptionformat = $record->descriptionformat; + } + if ($record->scalevalues) { + $competency->scaleid = $this->get_scale_id($record->scalevalues, $competency->shortname); + $competency->scaleconfiguration = $this->get_scale_configuration($competency->scaleid, $record->scaleconfiguration); + } + if ($parent) { + $competency->parentid = $parent->get_id(); + } else { + $competency->parentid = 0; + } + $competency->idnumber = $record->idnumber; + + if (!empty($competency->idnumber) && !empty($competency->shortname)) { + $comp = api::create_competency($competency); + if ($record->exportid) { + $this->mappings[$record->exportid] = $comp; + } + $record->createdcomp = $comp; + foreach ($record->children as $child) { + $this->create_competency($child, $comp, $framework); + } + + return $comp; + } + return false; + } + + /** + * Recreate the scale config to point to a new scaleid. + * @param int $scaleid + * @param string $config json encoded scale data. + */ + public function get_scale_configuration($scaleid, $config) { + $asarray = json_decode($config); + $asarray[0]->scaleid = $scaleid; + return json_encode($asarray); + } + + /** + * Search for a global scale that matches this set of scalevalues. + * If one is not found it will be created. + * @param array $scalevalues + * @param string $competencyname (Used to create a new scale if required) + * @return int The id of the scale + */ + public function get_scale_id($scalevalues, $competencyname) { + global $CFG, $USER; + + require_once($CFG->libdir . '/gradelib.php'); + + $allscales = grade_scale::fetch_all_global(); + $matchingscale = false; + foreach ($allscales as $scale) { + if ($scale->compact_items() == $scalevalues) { + $matchingscale = $scale; + } + } + if (!$matchingscale) { + // Create it. + $newscale = new grade_scale(); + $newscale->name = get_string('competencyscale', 'tool_lpimportcsv', $competencyname); + $newscale->courseid = 0; + $newscale->userid = $USER->id; + $newscale->scale = $scalevalues; + $newscale->description = get_string('competencyscaledescription', 'tool_lpimportcsv'); + $newscale->insert(); + return $newscale->id; + } + return $matchingscale->id; + } + + /** + * Walk through the idnumbers in the relatedidnumbers col and set the relations. + * @param stdClass $record + */ + protected function set_related($record) { + $comp = $record->createdcomp; + if ($record->relatedidnumbers) { + $allidnumbers = explode(',', $record->relatedidnumbers); + foreach ($allidnumbers as $rawidnumber) { + $idnumber = str_replace('%2C', ',', $rawidnumber); + + if (isset($this->flat[$idnumber])) { + $relatedcomp = $this->flat[$idnumber]->createdcomp; + api::add_related_competency($comp->get_id(), $relatedcomp->get_id()); + } + } + } + foreach ($record->children as $child) { + $this->set_related($child); + } + } + + /** + * Create any completion rule attached to this competency. + * @param stdClass $record + */ + protected function set_rules($record) { + $comp = $record->createdcomp; + if ($record->ruletype) { + $class = $record->ruletype; + if (class_exists($class)) { + $oldruleconfig = $record->ruleconfig; + if ($oldruleconfig == "null") { + $oldruleconfig = null; + } + $newruleconfig = $class::migrate_config($oldruleconfig, $this->mappings); + $comp->set_ruleconfig($newruleconfig); + $comp->set_ruletype($class); + $comp->set_ruleoutcome($record->ruleoutcome); + $comp->update(); + } + } + foreach ($record->children as $child) { + $this->set_rules($child); + } + } + + /** + * Do the job. + * @return competency_framework + */ + public function import() { + $record = clone $this->framework; + unset($record->children); + + $record->scaleid = $this->get_scale_id($record->scalevalues, $record->shortname); + $record->scaleconfiguration = $this->get_scale_configuration($record->scaleid, $record->scaleconfiguration); + unset($record->scalevalues); + $record->contextid = context_system::instance()->id; + + $framework = api::create_framework($record); + + // Now all the children. + foreach ($this->framework->children as $comp) { + $this->create_competency($comp, null, $framework); + } + + // Now create the rules. + foreach ($this->framework->children as $record) { + $this->set_rules($record); + $this->set_related($record); + } + + $this->importer->cleanup(); + return $framework; + } +} diff --git a/admin/tool/lpimportcsv/continue.php b/admin/tool/lpimportcsv/continue.php new file mode 100644 index 00000000000..ef98a4865b7 --- /dev/null +++ b/admin/tool/lpimportcsv/continue.php @@ -0,0 +1,47 @@ +. + +/** + * 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(); diff --git a/admin/tool/lpimportcsv/export.php b/admin/tool/lpimportcsv/export.php new file mode 100644 index 00000000000..a2d4b390a2c --- /dev/null +++ b/admin/tool/lpimportcsv/export.php @@ -0,0 +1,57 @@ +. + +/** + * Page to export a competency framework as a CSV. + * + * @package tool_lpimportcsv + * @copyright 2016 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('exportnavlink', 'tool_lpimportcsv'); + +$context = context_system::instance(); + +$url = new moodle_url("/admin/tool/lpimportcsv/export.php"); +$PAGE->set_context($context); +$PAGE->set_url($url); +$PAGE->set_title($pagetitle); +$PAGE->set_pagelayout('admin'); +$PAGE->set_heading($pagetitle); + +$form = new \tool_lpimportcsv\form\export($url->out(false), array('persistent' => null, 'context' => $context)); + +if ($form->is_cancelled()) { + redirect(new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $context->id))); +} else if ($data = $form->get_data()) { + require_sesskey(); + + $exporter = new \tool_lpimportcsv\framework_exporter($data->frameworkid); + + $exporter->export(); + die(); +} + +echo $OUTPUT->header(); +echo $OUTPUT->heading($pagetitle); + +$form->display(); + +echo $OUTPUT->footer(); diff --git a/admin/tool/lpimportcsv/index.php b/admin/tool/lpimportcsv/index.php new file mode 100644 index 00000000000..a2fc6cb5efa --- /dev/null +++ b/admin/tool/lpimportcsv/index.php @@ -0,0 +1,83 @@ +. + +/** + * Import a framework. + * + * @package tool_lpimportcsv + * @copyright 2016 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(); + +$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); + +$form = null; +if (optional_param('needsconfirm', 0, PARAM_BOOL)) { + $form = new \tool_lpimportcsv\form\import($url->out(false)); +} else if (optional_param('confirm', 0, PARAM_BOOL)) { + $importer = new \tool_lpimportcsv\framework_importer(); + $form = new \tool_lpimportcsv\form\import_confirm(null, $importer); +} else { + $form = new \tool_lpimportcsv\form\import($url->out(false)); +} + +if ($form->is_cancelled()) { + $form = new \tool_lpimportcsv\form\import($url->out(false)); +} else if ($data = $form->get_data()) { + require_sesskey(); + + if ($data->confirm) { + $importid = $data->importid; + $importer = new \tool_lpimportcsv\framework_importer(null, null, null, $importid, $data); + + $error = $importer->get_error(); + if ($error) { + $form = new \tool_lpimportcsv\form\import($url->out(false)); + $form->set_import_error($error); + } else { + $framework = $importer->import(); + redirect(new moodle_url('continue.php', array('id' => $framework->get_id()))); + die(); + } + } else { + $text = $form->get_file_content('importfile'); + $encoding = $data->encoding; + $delimiter = $data->delimiter_name; + $importer = new \tool_lpimportcsv\framework_importer($text, $encoding, $delimiter); + $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(); + +echo $OUTPUT->footer(); diff --git a/admin/tool/lpimportcsv/lang/en/tool_lpimportcsv.php b/admin/tool/lpimportcsv/lang/en/tool_lpimportcsv.php new file mode 100644 index 00000000000..813b09666bb --- /dev/null +++ b/admin/tool/lpimportcsv/lang/en/tool_lpimportcsv.php @@ -0,0 +1,53 @@ +. + +/** + * Strings for component 'tool_lpimportcsv', language 'en' + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['competencyscale'] = 'Competency Scale: {$a}'; +$string['competencyscaledescription'] = 'Competency scale created by import'; +$string['confirmcolumnmappings'] = 'Confirm the columns mappings'; +$string['confirm'] = 'Confirm'; +$string['csvdelimiter'] = 'CSV delimiter'; +$string['csvdelimiter_help'] = 'CSV delimiter of the CSV file.'; +$string['description'] = 'Description'; +$string['descriptionformat'] = 'Description format'; +$string['encoding'] = 'Encoding'; +$string['encoding_help'] = 'Encoding of the CSV file.'; +$string['export'] = 'Export'; +$string['exportid'] = 'Exported id (optional)'; +$string['exportnavlink'] = 'Export competency framework'; +$string['idnumber'] = 'Id number'; +$string['importfile'] = 'CSV framework description file'; +$string['import'] = 'Import'; +$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['relatedidnumbers'] = 'Cross referenced competency id numbers'; +$string['ruleconfig'] = 'Rule config (optional)'; +$string['ruleoutcome'] = 'Rule outcome (optional)'; +$string['ruletype'] = 'Rule type (optional)'; +$string['scaleconfiguration'] = 'Scale configuration'; +$string['scalevalues'] = 'Scale values'; +$string['shortname'] = 'Shortname'; +$string['taxonomy'] = 'Taxonomy'; diff --git a/admin/tool/lpimportcsv/settings.php b/admin/tool/lpimportcsv/settings.php new file mode 100644 index 00000000000..8cc12da850d --- /dev/null +++ b/admin/tool/lpimportcsv/settings.php @@ -0,0 +1,46 @@ +. + +/** + * Links and settings + * + * This file contains links and settings used by tool_lpimportcsv + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die; + +// Manage competency frameworks page. +$temp = new admin_externalpage( + 'toollpimportcsv', + get_string('pluginname', 'tool_lpimportcsv'), + new moodle_url('/admin/tool/lpimportcsv/index.php'), + 'moodle/competency:competencymanage' +); +$ADMIN->add('competencies', $temp); +// Export competency framework page. +$temp = new admin_externalpage( + 'toollpexportcsv', + get_string('exportnavlink', 'tool_lpimportcsv'), + new moodle_url('/admin/tool/lpimportcsv/export.php'), + 'moodle/competency:competencymanage' +); +$ADMIN->add('competencies', $temp); + +// No report settings. +$settings = null; diff --git a/admin/tool/lpimportcsv/tests/fixtures/example.csv b/admin/tool/lpimportcsv/tests/fixtures/example.csv new file mode 100644 index 00000000000..19c7b057ede --- /dev/null +++ b/admin/tool/lpimportcsv/tests/fixtures/example.csv @@ -0,0 +1,209 @@ +"Parent id number","Id number",Shortname,Description,"Description format","Scale values","Scale configuration","Rule type (optional)","Rule outcome (optional)","Rule config (optional)","Cross referenced competency id numbers","Exported id (optional)","Is framework",Taxonomy +,OECD-CORE,OECD,"

The Core Competencies summarise the capabilities that are important across all jobs and that we believe +collectively contribute to the OECD’s overall success. At the same time, the importance of Core +Competencies may vary according to the specific job duties and requirements. +The OECD Competency Framework displays fifteen Core Competencies grouped into three clusters.

• The delivery-related competencies
• The interpersonal competencies +
• The strategic competencies

",1,"Not yet competent,Competent","[{""scaleid"":""2""},{""id"":2,""scaledefault"":1,""proficient"":1}]",,,,,,1,"competency,competency,competency,competency" +,levels,Levels,"

Each level of the Core Competencies has behavioural indicators that highlight how an individual can +demonstrate that competency. Behavioural indicators are designed to show the requirements for successful +performance.

",1,,,,0,null,,1,, +levels,level-1,"Level 1","

Level 1 is typically associated with jobs such as Assistants, Secretaries and Operators.

",1,,,,0,null,"S-DT-1,S-DT-2,S-OA-1,S-OA-2,S-SN-1,S-SN-2,S-SN-3,S-ST-1,DR-AT1,DR-AT-2,DR-AF-1,DR-AF-2,DR-AF-3,DR-DS-1,DR-DS-2,DR-FT-1,DR-FT-2,DR-FT-3,DR-MR-1,DR-MR-2,DR-TW-1,DR-TW-2,DR-TW-3,I-CF-1,I-CF-2,I-CF-3,I-DS-1,I-DS-2,I-DS-3,I-DS-4,I-I-1,I-I-2,I-I-3,I-I-4,I-N-1,I-N-3,I-OK-1,I-OK-2,I-OK-3",2,, +levels,level-2,"Level 2","

Level 2 is typically associated with jobs such as Statisticians, Corporate Management and Administration +Assistants/Officers, Logistics Officers and Documentalists.

",1,,,,0,null,,3,, +levels,level-3,"Level 3","

Level 3 is typically associated with jobs such as Economists/Policy Analysts, IT Analysts and HR Advisers.

",1,,,,0,null,,4,, +levels,level-4,"Level 4","

Level 4 is typically associated with jobs such as Senior Economists/Policy Analysts or Managers

",1,,,,0,null,,5,, +levels,level-5,"Level 5","

Level 5 is typically associated with jobs such as Heads of Division, Counsellors, Deputy Directors and +Directors.

",1,,,,0,null,,6,, +,competencies,Competencies,,1,,,,0,null,,7,, +competencies,delivery,Delivery-related,"

Achieving Results

",1,,,,0,null,,8,, +competencies,interpersonal,Interpersonal,"

Building relationships

",1,,,,0,null,,9,, +competencies,strategic,Strategic,"

Planning for the future

",1,,,,0,null,,10,, +delivery,analytical-thinking,"Analytical Thinking","

Analytical Thinking is the ability to identify +patterns across situations that are not obviously +related, and to identify key or underlying issues in +complex situations.

",1,,,,0,null,,11,, +delivery,acheivement-focus,"Achievement Focus","

Achievement Focus is generating results by +assuming responsibility for one's performance +and the correctness of one's interventions, and +recognising opportunities and acting efficiently at +the appropriate moment and within the given +deadlines.

",1,,,,0,null,,12,, +delivery,drafting-skills,"Drafting Skills","

Drafting Skills are based on the ability to +respectfully communicate ideas and information +(often technical) in writing to ensure that +information and messages are understood and +have the desired impact.

",1,,,,0,null,,13,, +delivery,flexible-thinking,"Flexible Thinking","

Flexible Thinking involves the ability to +effectively adapt to a variety of situations, +individuals or groups. It is based on the ability to +understand and appreciate different and opposing perspectives on an issue, to adapt an approach +as the requirements of a situation change, and to +change or easily accept changes in one’s own +organisational or job requirements.

",1,,,,0,null,,14,, +delivery,managing-resources,"Managing Resources","

Managing Resources is about understanding +human, financial, and operational resource issues +to make decisions aimed at building and planning +efficient project workflows, and at improving +overall organisational performance.

",1,,,,0,null,,15,, +delivery,teamwork,"Teamwork and Team Leadership","

Teamwork and Team Leadership implies +working co-operatively with others, being a part of +a team, and assuming the role of leader of a +team. In the OECD, people work not only with +their own teams but also with teams and groups +across and outside the Organisation. Therefore +they need to work together effectively with +interdependent goals and common values and +norms to foster a collaborative environment and +drive teams in the same direction.

",1,,,,0,null,,16,, +interpersonal,client-focus,"Client Focus","

Client Focus is based on the ability to +understand internal/external clients’ (e.g. +Committees, working groups, country +representatives, etc.,) needs and concerns in the +short to long-term and to provide sound +recommendations and/or solutions.

",1,,,,0,null,,17,, +interpersonal,diplomatic-sensitivity,"Diplomatic Sensitivity","

Diplomatic Sensitivity implies understanding +other people. It includes the ability to hear +accurately and understand unspoken, partly +expressed thoughts, feelings and concerns of +others. Included in this competency is an +emphasis on cross-cultural sensitivity. +Proficiency in Diplomatic Sensitivity requires the +ability to keep one’s emotions under control and +restrain negative actions when faced with +opposition or hostility from others or when +working under stress.

",1,,,,0,null,,18,, +interpersonal,influencing,Influencing,"

Influencing implies an intention to convince +others in an honest, respectful and sensitive +manner in order to get them to go along with +one’s objectives. It can also be the desire to have +a specific impact or effect on others.

",1,,,,0,null,,19,, +interpersonal,negotiating,Negotiating,"

Negotiating involves the ability to work towards +win-win outcomes. At lower levels, this +competency assumes an understanding of one’s +counterparts and how to respond to them during +negotiations. At the higher levels, the competency +reflects a focus to achieve value-added results.

",1,,,,0,null,,20,, +interpersonal,organisational-knowledge,"Organisational Knowledge","

Organisational Knowledge is the ability to +understand the power relationships within the +Organisation and with other organisations. It +includes the ability to understand the formal rules +and structures including the ability to identify who +the real decision-makers are as well as the +individuals who can influence them.

",1,,,,0,null,,21,, +strategic,developing-talent,"Developing Talent","

Developing Talent means fostering an +environment that will encourage professional and +personal growth and the transfer of knowledge to +future talent.

",1,,,,0,null,,22,, +strategic,organisational-alignment,"Organisational Alignment","

Organisational Alignment is the ability and +willingness to align one’s own behaviour with the +needs, priorities, and goals of the Organisation, +and to act in ways that promote the +Organisation’s goals or meet organisational +needs. Organisational Alignment means focusing +on the Organisation's mission before one's own +preferences or professional priorities.

",1,,,,0,null,,23,, +strategic,strategic-networking,"Strategic Networking","

Strategic Networking involves working to build +and maintain friendly, trustworthy and open +internal and external relationships and networks +with people who are, or might become, important +actors in achieving strategic-related goals.

",1,,,,0,null,,24,, +strategic,strategic-thinking,"Strategic Thinking","

Strategic Thinking is the ability to develop a +broad, big-picture view of the Organisation and its +mission. Competitive advantage and threats, +industry trends, emerging technology, market +opportunities, stakeholder focus – Strategic +Thinking is where these all come together. +Strategic Thinking keeps individuals and groups +focused and helps decide where to invest critical +resources. It includes the ability to link long-range +visions and concepts to daily work.

",1,,,,0,null,,25,, +analytical-thinking,DR-AT1,"Distinguishes between critical and irrelevant pieces of information","

Distinguishes between critical and irrelevant +pieces of information

",1,,,,0,null,level-1,26,, +analytical-thinking,DR-AT-2,"Gathers information from a variety of sources to reach a conclusion.","

Gathers information from a variety of sources +to reach a conclusion.

",1,,,,0,null,level-1,27,, +acheivement-focus,DR-AF-1,"Defines ambitious, but realistic, personal goals.","

Defines ambitious, but realistic, personal +goals.

",1,,,,0,null,level-1,28,, +acheivement-focus,DR-AF-2,"Works while meeting quality and performance standards","

Works while meeting quality and performance +standards

",1,,,,0,null,level-1,29,, +acheivement-focus,DR-AF-3,"Promptly and efficiently completes work assignments.","

Promptly and efficiently completes work +assignments.

",1,,,,0,null,level-1,30,, +drafting-skills,DR-DS-1,"Tailors communication (e.g. content, style and medium) to diverse audiences. ","

Tailors communication (e.g. content, style and +medium) to diverse audiences.

",1,,,,0,null,level-1,31,, +drafting-skills,DR-DS-2,"Writes and presents factual material in a concise manner. ","

Writes and presents factual material in a +concise manner.

",1,,,,0,null,level-1,32,, +flexible-thinking,DR-FT-1,"Proposes ways to do things differently.","

Proposes ways to do things differently.

",1,,,,0,null,level-1,33,, +flexible-thinking,DR-FT-2,"Understands and recognises the value of other points of view and ways of doing things","

Understands and recognises the value of +other points of view and ways of doing things

",1,,,,0,null,level-1,34,, +flexible-thinking,DR-FT-3,"Displays a positive attitude in the face of ambiguity and change.","

Displays a positive attitude in the face of +ambiguity and change.

",1,,,,0,null,level-1,35,, +managing-resources,DR-MR-1,"Organises the use of resources to meet expectations and identifies difficulties. ","

Organises the use of resources to meet +expectations and identifies difficulties.

",1,,,,0,null,level-1,36,, +managing-resources,DR-MR-2,"Plans, coordinates and manages internal and external resources to accomplish assignments within the ","

Plans, coordinates and manages internal and +external resources to accomplish +assignments within the given deadlines.

",1,,,,0,null,level-1,37,, +teamwork,DR-TW-1,"Initiates collaboration with others and spontaneously assists others in the delivery of their work","

Initiates collaboration with others and +spontaneously assists others in the delivery of +their work

",1,,,,0,null,level-1,38,, +teamwork,DR-TW-2,"Shares all relevant information with others and seeks others' input. ","

Shares all relevant information with others +and seeks others' input.

",1,,,,0,null,level-1,39,, +teamwork,DR-TW-3,"Expresses own opinion while remaining factual and respectful.","

Expresses own opinion while remaining +factual and respectful.

",1,,,,0,null,level-1,40,, +client-focus,I-CF-1,"Responds to and anticipates client needs in a timely, professional, helpful and courteous manner, re","

Responds to and anticipates client needs in a +timely, professional, helpful and courteous +manner, regardless of client attitude.

",1,,,,0,null,level-1,41,, +client-focus,I-CF-2,"Clearly shows clients that their perspectives are valued","

Clearly shows clients that their perspectives +are valued

",1,,,,0,null,level-1,42,, +client-focus,I-CF-3,"Strives to consistently meet service standards.","

Strives to consistently meet service +standards.

",1,,,,0,null,level-1,43,, +diplomatic-sensitivity,I-DS-1,"Listens actively, considers people’s concerns and adjusts own behaviour in a helpful manner.","

Listens actively, considers people’s concerns +and adjusts own behaviour in a helpful +manner.

",1,,,,0,null,level-1,44,, +diplomatic-sensitivity,I-DS-2,"Understands the reason behind, or motivation for someone’s actions.","

Understands the reason behind, or motivation +for someone’s actions.

",1,,,,0,null,level-1,45,, +diplomatic-sensitivity,I-DS-3,"Is attentive when doing projects and assignments, or when interacting with people from different cou","

Is attentive when doing projects and +assignments, or when interacting with people +from different countries and backgrounds.

",1,,,,0,null,level-1,46,, +diplomatic-sensitivity,I-DS-4,"Expresses negative feelings constructively.","

Expresses negative feelings constructively.

",1,,,,0,null,level-1,47,, +influencing,I-I-1,"Checks own understanding of others' communication (e.g. paraphrases, asks questions).","

Checks own understanding of others' +communication (e.g. paraphrases, asks +questions).

",1,,,,0,null,level-1,48,, +influencing,I-I-2,"Maintains continuous, open and consistent communication with others.","

Maintains continuous, open and consistent +communication with others.

",1,,,,0,null,level-1,49,, +influencing,I-I-3,"Builds on successful initiatives to gain support for ideas.","

Builds on successful initiatives to gain support +for ideas.

",1,,,,0,null,level-1,50,, +influencing,I-I-4,"Adapts arguments to others' needs/interests. ","

Adapts arguments to others' needs/interests.

",1,,,,0,null,level-1,51,, +negotiating,I-N-1,"Identifies main negotiating points of a given issue and engages in negotiation.","

Identifies main negotiating points of a given +issue and engages in negotiation.

",1,,,,0,null,level-1,52,, +negotiating,I-N-3,"Listens to differing points of view and promotes mutual understanding.","

Listens to differing points of view and +promotes mutual understanding.

",1,,,,0,null,level-1,53,, +organisational-knowledge,I-OK-1,"Demonstrates understanding of the general environment in which the Organisation operates.","

Demonstrates understanding of the general +environment in which the Organisation +operates.

",1,,,,0,null,level-1,54,, +organisational-knowledge,I-OK-2,"Understands and uses the Organisation's structures, rules and networks.","

Understands and uses the Organisation's +structures, rules and networks.

",1,,,,0,null,level-1,55,, +organisational-knowledge,I-OK-3,"Knows and respects the Organisation’s Code of Conduct and values.","

Knows and respects the Organisation’s Code +of Conduct and values.

",1,,,,0,null,level-1,56,, +developing-talent,S-DT-1,"Takes advantage of learning opportunities provided (e.g. courses, feedback from supervisor or peers)","

Takes advantage of learning opportunities +provided (e.g. courses, feedback from +supervisor or peers) to meet requirements of +current job.

",1,,,,0,null,level-1,57,, +developing-talent,S-DT-2,"Sets clear self-development expectations.","

Sets clear self-development expectations.

",1,,,,0,null,level-1,58,, +organisational-alignment,S-OA-1,"Explains the role and goals of the Organisation and how they relate to own area of work.","

Explains the role and goals of the +Organisation and how they relate to own area +of work.

",1,,,,0,null,level-1,59,, +organisational-alignment,S-OA-2,"Is able to explain how own work relates to the work of the Organisation.","

Is able to explain how own work relates to the +work of the Organisation.

",1,,,,0,null,level-1,60,, +strategic-networking,S-SN-1,"Actively nurtures both formal and informal contacts to facilitate the progress of work by proactivel","

Actively nurtures both formal and informal +contacts to facilitate the progress of work by +proactively sharing information, best +practices, respective interests and areas of +expertise.

",1,,,,0,null,level-1,61,, +strategic-networking,S-SN-2,"Identifies current or past contacts that can provide work-related information or assistance","

Identifies current or past contacts that can +provide work-related information or +assistance

",1,,,,0,null,level-1,62,, +strategic-networking,S-SN-3,"Fosters two-way trust in dealing with contacts (e.g. maintains confidentiality regarding sensitive i","

Fosters two-way trust in dealing with contacts +(e.g. maintains confidentiality regarding +sensitive information).

",1,,,,0,null,level-1,63,, +strategic-thinking,S-ST-1,"Identifies new information or data to key decision-makers or stakeholders to support their understan","

Identifies new information or data to key +decision-makers or stakeholders to support +their understanding and decisions.

",1,,,,0,null,level-1,64,, diff --git a/admin/tool/lpimportcsv/tests/import_test.php b/admin/tool/lpimportcsv/tests/import_test.php new file mode 100644 index 00000000000..3063b54fa11 --- /dev/null +++ b/admin/tool/lpimportcsv/tests/import_test.php @@ -0,0 +1,62 @@ +. +/** + * External learning plans webservice API tests. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +use tool_lpimportcsv\framework_importer; +use tool_lpimportcsv\framework_exporter; +use core_competency\api; + +/** + * External learning plans webservice API tests. + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class tool_lpimportcsv_import_testcase extends advanced_testcase { + + public function test_import_framework() { + $this->resetAfterTest(true); + $this->setAdminUser(); + + $importer = new framework_importer(file_get_contents(__DIR__ . '/fixtures/example.csv')); + + $this->assertEquals('', $importer->get_error()); + + $framework = $importer->import(); + $this->assertEmpty('', $importer->get_error()); + + $this->assertGreaterThan(0, $framework->get_id()); + + $filters = [ + 'competencyframeworkid' => $framework->get_id() + ]; + $count = api::count_competencies($filters); + $this->assertEquals(64, $count); + + // We can't test the exporter because it sends force-download headers. + } + + +} diff --git a/admin/tool/lpimportcsv/version.php b/admin/tool/lpimportcsv/version.php new file mode 100644 index 00000000000..e17aa4a382a --- /dev/null +++ b/admin/tool/lpimportcsv/version.php @@ -0,0 +1,32 @@ +. + +/** + * Plugin version info + * + * @package tool_lpimportcsv + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + + +$plugin->version = 2016083000; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2016051900; // Requires this Moodle version. +$plugin->component = 'tool_lpimportcsv'; // Full name of the plugin (used for diagnostics). +$plugin->dependencies = array('tool_lp' => 2016052300); + diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index dde3c25c67e..31663737070 100644 --- a/lib/classes/plugin_manager.php +++ b/lib/classes/plugin_manager.php @@ -1906,7 +1906,7 @@ class core_plugin_manager { 'tool' => array( 'assignmentupgrade', 'availabilityconditions', 'behat', 'capability', 'cohortroles', 'customlang', 'dbtransfer', 'filetypes', 'generator', 'health', 'innodb', 'installaddon', - 'langimport', 'log', 'lp', 'lpmigrate', 'messageinbound', 'mobile', 'multilangupgrade', 'monitor', + 'langimport', 'log', 'lp', 'lpimportcsv', 'lpmigrate', 'messageinbound', 'mobile', 'multilangupgrade', 'monitor', 'phpunit', 'profiling', 'recyclebin', 'replace', 'spamcleaner', 'task', 'templatelibrary', 'unittest', 'uploadcourse', 'uploaduser', 'unsuproles', 'xmldb' ),