Commit 13b0ebd0 authored by Nigel McNie's avatar Nigel McNie
Browse files

Add is_correct_category scheme, for refactoring some duplicate code.



Use it everywhere we're looking for category schemes.
Signed-off-by: default avatarNigel McNie <nigel@catalyst.net.nz>
parent 311df835
......@@ -53,10 +53,8 @@ class LeapImportBlog extends LeapImportArtefactPlugin {
public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImport $importer) {
$strategies = array();
$correctcategoryscheme = count($entry->xpath('a:category[('
. $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'selection_type#') . ') and @term="Blog"]')) == 1;
if (PluginImportLeap::is_rdf_type($entry, $importer, 'selection') && $correctcategoryscheme) {
if (PluginImportLeap::is_rdf_type($entry, $importer, 'selection')
&& PluginImportLeap::is_correct_category_scheme($entry, $importer, 'selection_type', 'Blog')) {
$otherrequiredentries = array();
// Get entries that this blog feels are a part of it
......@@ -246,9 +244,7 @@ class LeapImportBlog extends LeapImportArtefactPlugin {
$blogpost->set('mtime', $updated);
}
$draftpost = count($entry->xpath('a:category[('
. $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'readiness#')
. ') and @term="Unready"]')) == 1;
$draftpost = PluginImportLeap::is_correct_category_scheme($entry, $importer, 'readiness', 'Unready');
$blogpost->set('published', $draftpost ? 0 : 1);
$blogpost->set('owner', $importer->get('usr'));
......
......@@ -121,9 +121,8 @@ class LeapImportFile extends LeapImportArtefactPlugin {
if (isset($cache[$id])) {
return $cache[$id];
}
$correctcategoryscheme = count($entry->xpath('a:category[('
. $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'selection_type#') . ') and @term="Folder"]')) == 1;
return ($cache[$id] = PluginImportLeap::is_rdf_type($entry, $importer, 'selection') && $correctcategoryscheme);
return ($cache[$id] = PluginImportLeap::is_rdf_type($entry, $importer, 'selection')
&& PluginImportLeap::is_correct_category_scheme($entry, $importer, 'selection_type', 'Folder'));
}
/**
......
......@@ -124,9 +124,7 @@ class LeapImportResume extends LeapImportArtefactPlugin {
// Employment
$other_required_entries = array();
$correctcategoryscheme = count($entry->xpath('a:category[('
. $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'life_area#') . ') and @term="Work"]')) == 1;
if ($isactivity && $correctcategoryscheme) {
if ($isactivity && PluginImportLeap::is_correct_category_scheme($entry, $importer, 'life_area', 'Work')) {
foreach ($entry->link as $link) {
if (!isset($other_required_entries['organisation'])
&& $organisation = self::check_for_supporting_organisation($importer, $link)) {
......@@ -143,9 +141,7 @@ class LeapImportResume extends LeapImportArtefactPlugin {
// Books
$other_required_entries = array();
$correctcategoryscheme = count($entry->xpath('a:category[('
. $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'resource_type#') . ') and @term="Printed"]')) == 1;
if ($isresource && $correctcategoryscheme) {
if ($isresource && PluginImportLeap::is_correct_category_scheme($entry, $importer, 'resource_type', 'Printed')) {
// If it exists, the related achievement will be the user's role in
// relation to the book
foreach ($entry->link as $link) {
......@@ -169,9 +165,7 @@ class LeapImportResume extends LeapImportArtefactPlugin {
// Education
$other_required_entries = array();
$correctcategoryscheme = count($entry->xpath('a:category[('
. $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'life_area#') . ') and @term="Education"]')) == 1;
if ($isactivity && $correctcategoryscheme) {
if ($isactivity && PluginImportLeap::is_correct_category_scheme($entry, $importer, 'life_area', 'Education')) {
// If this entry supports an achievement, that achievement will be
// the qualification the user gained in relation to this entry
foreach ($entry->link as $link) {
......@@ -496,8 +490,7 @@ class LeapImportResume extends LeapImportArtefactPlugin {
}
else if ($potentialselection = $importer->get_entry_by_id($href)) {
if (PluginImportLeap::is_rdf_type($potentialselection, $importer, 'selection')) {
if (count($potentialselection->xpath('a:category[('
. $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'selection_type#') . ') and @term="Grouping"]')) == 1) {
if (PluginImportLeap::is_correct_category_scheme($potentialselection, $importer, 'selection_type', 'Grouping')) {
if (count($potentialselection->xpath('mahara:artefactplugin[@mahara:type="' . $selectiontype . '"]')) == 1) {
$cache[$href] = true;
$found = true;
......
......@@ -503,6 +503,21 @@ class PluginImportLeap extends PluginImport {
return isset($result[0]) && $result[0] instanceof SimpleXMLElement;
}
/**
* Returns if the entry has the given term in the given category
*
* @param SimpleXMLElement $entry The entry to check
* $param PluginImportLeap $importer The importer
* @param string $category The category to look in. See http://wiki.cetis.ac.uk/2009-03/LEAP2A_categories
* @param string $term The term to look for (see the docs for the appropriate category)
* @return boolean Whether the entry has the term in the category
*/
public static function is_correct_category_scheme(SimpleXMLElement $entry, PluginImportLeap $importer, $category, $term) {
$result = $entry->xpath('a:category[('
. $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, $category . '#') . ') and @term="' . $term . '"]');
return isset($result[0]) && $result[0] instanceof SimpleXMLElement;
}
/**
* Returns the <content> for a given entry, stripping off any transport
* encoding and respecting the content type.
......
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