Commit 7e8629e3 authored by Nigel McNie's avatar Nigel McNie
Browse files

Add a hook for dealing with importing the persondata element.

Use this hook instead of hard coding a call to the Internal plugin's
import_author_data method.

This allows the resume to also hook in and grab the personalinformation
fields out.
parent e96f654d
......@@ -43,18 +43,11 @@ defined('INTERNAL') || die();
*/
class LeapImportInternal extends LeapImportArtefactPlugin {
/**
* Dummy strategy used to bags the person entry corresponding to the author
*/
const STRATEGY_DUMMY = 1;
/**
* For grabbing entries representing profile data that can't be exported as
* persondata
*/
const STRATEGY_IMPORT_AS_PROFILE_FIELD = 2;
private static $persondataid = null;
const STRATEGY_IMPORT_AS_PROFILE_FIELD = 1;
/**
* Lookup table for some of the persondata fields.
......@@ -155,41 +148,18 @@ class LeapImportInternal extends LeapImportArtefactPlugin {
public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImport $importer) {
$strategies = array();
if (is_null(self::$persondataid)) {
$author = $importer->get('xml')->xpath('//a:feed/a:author[1]');
$author = $author[0];
if (isset($author->uri) && $importer->get_entry_by_id((string)$author->uri)) {
self::$persondataid = (string)$author->uri;
}
else {
self::$persondataid = false;
}
}
// TODO: also check other element has the right leaptype (person)
//$correctrdftype = count($entry->xpath('rdf:type['
// . $importer->curie_xpath('@rdf:resource', PluginImportLeap::NS_LEAPTYPE, 'selection') . ']')) == 1;
if ((string)$entry->id == self::$persondataid) {
// If it's a raw entry with the right mahara:plugin and mahara:type
// we should be able to import it
$correctrdftype = count($entry->xpath('rdf:type['
. $importer->curie_xpath('@rdf:resource', PluginImportLeap::NS_LEAPTYPE, 'entry') . ']')) == 1;
$correctplugintype = count($entry->xpath('mahara:artefactplugin[@mahara:plugin="internal"]')) == 1;
if ($correctrdftype && $correctplugintype) {
$strategies[] = array(
'strategy' => self::STRATEGY_DUMMY,
'strategy' => self::STRATEGY_IMPORT_AS_PROFILE_FIELD,
'score' => 100,
'other_required_entries' => array(),
);
}
else {
// If it's a raw entry with the right mahara:plugin and mahara:type
// we should be able to import it
$correctrdftype = count($entry->xpath('rdf:type['
. $importer->curie_xpath('@rdf:resource', PluginImportLeap::NS_LEAPTYPE, 'entry') . ']')) == 1;
$correctplugintype = count($entry->xpath('mahara:artefactplugin[@mahara:plugin="internal"]')) == 1;
if ($correctrdftype && $correctplugintype) {
$strategies[] = array(
'strategy' => self::STRATEGY_IMPORT_AS_PROFILE_FIELD,
'score' => 100,
'other_required_entries' => array(),
);
}
}
return $strategies;
}
......@@ -197,9 +167,6 @@ class LeapImportInternal extends LeapImportArtefactPlugin {
public static function import_using_strategy(SimpleXMLElement $entry, PluginImport $importer, $strategy, array $otherentries) {
$artefactmapping = array();
switch ($strategy) {
case self::STRATEGY_DUMMY:
// This space intentionally left blank
break;
case self::STRATEGY_IMPORT_AS_PROFILE_FIELD:
// Based on the mahara:type, we might be able to import it as
// something useful - otherwise, there is nothing we can do. The
......@@ -241,10 +208,10 @@ class LeapImportInternal extends LeapImportArtefactPlugin {
*
* @param PluginImport $importer The importer
*/
public static function import_author_data(PluginImport $importer) {
if (self::$persondataid) {
public static function import_author_data(PluginImport $importer, $persondataid) {
if ($persondataid) {
// Grab all the leap:persondata elements and import them
$person = $importer->get_entry_by_id(self::$persondataid);
$person = $importer->get_entry_by_id($persondataid);
// The introduction comes from the entry content
$introduction = new ArtefactTypeIntroduction(0, array('owner' => $importer->get('usr')));
......
......@@ -40,6 +40,8 @@ class PluginImportLeap extends PluginImport {
private $loadmapping = array();
private $artefactids = array();
protected $persondataid = null;
protected $loglevel = 0;
protected $logtargets = LOG_TARGET_ERRORLOG;
protected $profile = false;
......@@ -122,11 +124,32 @@ class PluginImportLeap extends PluginImport {
*/
private function create_strategy_listing() {
$this->trace("-------------------------\ncreate_strategy_listing()");
// First, try to establish whether there is an element representing the
// author of the feed
// TODO: also check this element has the right leaptype (person)
if (is_null($this->persondataid)) {
$author = $this->get('xml')->xpath('//a:feed/a:author[1]');
$author = $author[0];
if (isset($author->uri) && $this->get_entry_by_id((string)$author->uri)) {
$this->persondataid = (string)$author->uri;
}
else {
$this->persondataid = false;
}
}
// Generate strategy listing
foreach ($this->xml->xpath('//a:feed/a:entry') as $entry) {
$this->registerXpathNamespaces($entry);
$entryid = (string)$entry->id;
$this->trace(" * $entryid ({$entry->title})");
if ($this->persondataid && $entryid == $this->persondataid) {
// We don't offer this element to any plugin to be imported
continue;
}
foreach (plugins_installed('artefact') as $plugin) {
$plugin = $plugin->name;
if (safe_require('import', 'leap/' . $plugin, 'lib.php', 'require_once', true)) {
......@@ -288,13 +311,14 @@ class PluginImportLeap extends PluginImport {
$loadedentries[] = $entryid;
}
// The internal artefact plugin needs to deal with the <author> tag
// plus persondata for the author.
// Note: I don't feel guilty doing this in this way because a) internal
// artefact plugin is required and b) it's the only one that needs this
// Give plugins a chance to import stuff about the feed author from the
// persondata entry
// TODO: this should return an artefact mapping so things can create
// links to profile fields, but nothing actually needs it yet
LeapImportInternal::import_author_data($this);
foreach (plugins_installed('artefact') as $plugin) {
$classname = 'LeapImport' . ucfirst($plugin->name);
$strategies = call_static_method($classname, 'import_author_data', $this, $this->persondataid);
}
// Now all artefacts are loaded, allow each plugin to load
// relationships for them if they need to
......@@ -628,6 +652,12 @@ abstract class LeapImportArtefactPlugin {
*/
abstract public static function import_using_strategy(SimpleXMLElement $entry, PluginImport $importer, $strategy, array $otherentries);
/**
* Gives plugins a chance to import author data
*/
public static function import_author_data(PluginImport $importer, $persondataid) {
}
/**
* Gives plugins a chance to construct relationships between the newly
* created artefacts.
......
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