Commit 4072e4a8 authored by Nigel McNie's avatar Nigel McNie
Browse files

Allow all types of resume artefact in the resumefield blocktype to be imported.



This was broken because contactinformation is a "fake" artefact that
just ties together some profile artefacts, so we have to create one at
import time for the user. We also have to export the fields by name
instead of artefact ID in the Mahara config, as the contactinformation
artefact isn't exported at all.
Signed-off-by: default avatarNigel McNie <nigel@catalyst.net.nz>
parent e7a7bc23
......@@ -153,6 +153,71 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
return $view->get('owner') != null;
}
/**
* Export the name of the resume field being exported instead of a
* reference to the artefact ID - mainly so that the fake "contact
* information" field (which isn't exported) gets handled properly.
*
* @param BlockInstance $bi The blockinstance to export the config for.
* @return array The config for the blockinstance
*/
public static function export_blockinstance_config_leap(BlockInstance $bi) {
$configdata = $bi->get('configdata');
$result = array();
if (!empty($configdata['artefactid'])) {
if ($artefacttype = get_field('artefact', 'artefacttype', 'id', $configdata['artefactid'])) {
$result['artefacttype'] = json_encode(array($artefacttype));
}
}
return $result;
}
/**
* Load the artefact ID for the field based on the field name that is in
* the config (see export_blockinstance_config_leap).
*
* @param array $biconfig The block instance config
* @param array $viewconfig The view config
* @return BlockInstance The newly made block instance
*/
public static function import_create_blockinstance_leap(array $biconfig, array $viewconfig) {
$configdata = array();
// This blocktype is only allowed in personal views
if (empty($viewconfig['owner'])) {
return;
}
$owner = $viewconfig['owner'];
if (isset($biconfig['config']) && is_array($biconfig['config'])) {
$impcfg = $biconfig['config'];
if (!empty($impcfg['artefacttype'])) {
if ($artefactid = get_field_sql("SELECT id
FROM {artefact}
WHERE owner = ?
AND artefacttype = ?
AND artefacttype IN (
SELECT name
FROM {artefact_installed_type}
WHERE plugin = 'resume'
)", array($owner, $impcfg['artefacttype']))) {
$configdata['artefactid'] = $artefactid;
}
}
}
$bi = new BlockInstance(0,
array(
'blocktype' => $biconfig['type'],
'configdata' => $configdata,
)
);
return $bi;
}
}
?>
......@@ -78,6 +78,15 @@ class LeapImportResume extends LeapImportArtefactPlugin {
*/
const STRATEGY_IMPORT_AS_SELECTION = 8;
/**
* All users need one of these, but it's a "fake" artefact - it just
* represents profile information. It's not exported. So we create one here
* for imported users.
*/
public static function setup(PluginImportLeap $importer) {
ArtefactTypeContactinformation::setup_new($importer->get('usr'));
}
/**
* Description of strategies used
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment