コード例 #1
0
 public static function import_using_strategy(SimpleXMLElement $entry, PluginImportLeap $importer, $strategy, array $otherentries)
 {
     $artefactmapping = array();
     switch ($strategy) {
         case self::STRATEGY_IMPORT_AS_ENTRY:
         case self::STRATEGY_IMPORT_AS_ABILITY:
             // Based on the mahara:type, we might be able to import it as
             // something useful - otherwise, there is nothing we can do. The
             // entry already claimed it was mahara:plugin="resume", so it's
             // perfectly fine for us to not import it if we don't recognise it
             if ($strategy == self::STRATEGY_IMPORT_AS_ENTRY) {
                 $types = array('careergoal', 'academicgoal', 'personalgoal', 'interest', 'coverletter');
             } else {
                 $types = array('workskill', 'academicskill', 'personalskill');
             }
             $typexpath = join('" or @mahara:type="', $types);
             $artefactpluginelement = $entry->xpath('mahara:artefactplugin[@mahara:type="' . $typexpath . '"]');
             if (count($artefactpluginelement) == 1) {
                 $artefactpluginelement = $artefactpluginelement[0];
                 $maharaattributes = PluginImportLeap::get_attributes($artefactpluginelement, PluginImportLeap::NS_MAHARA);
                 if (isset($maharaattributes['type']) && in_array($maharaattributes['type'], $types)) {
                     $artefactmapping[(string) $entry->id] = array(self::create_artefact($importer, $maharaattributes['type'], $entry->title, PluginImportLeap::get_entry_content($entry, $importer)));
                 }
             }
             break;
         case self::STRATEGY_IMPORT_AS_ACHIEVEMENT:
             $dates = PluginImportLeap::get_leap_dates($entry, $importer->get_namespaces(), $importer->get_leap2a_namespace());
             $enddate = isset($dates['end']) ? self::convert_leap_date_to_resume_date($dates['end']) : '';
             $values = array('date' => $enddate, 'title' => $entry->title, 'description' => PluginImportLeap::get_entry_content($entry, $importer), 'displayorder' => self::get_display_order_for_entry($entry, $importer, 'certification'));
             ArtefactTypeResumeComposite::ensure_composite_value($values, 'certification', $importer->get('usr'));
             break;
         case self::STRATEGY_IMPORT_AS_EMPLOYMENT:
             $dates = PluginImportLeap::get_leap_dates($entry, $importer->get_namespaces(), $importer->get_leap2a_namespace());
             $startdate = isset($dates['start']) ? self::convert_leap_date_to_resume_date($dates['start']) : '';
             $enddate = isset($dates['end']) ? self::convert_leap_date_to_resume_date($dates['end']) : '';
             $employer = '';
             if (isset($otherentries['organization'])) {
                 $organization = $importer->get_entry_by_id($otherentries['organization']);
                 $employer = $organization->title;
             }
             $values = array('startdate' => $startdate, 'enddate' => $enddate, 'employer' => $employer, 'jobtitle' => $entry->title, 'positiondescription' => PluginImportLeap::get_entry_content($entry, $importer), 'displayorder' => self::get_display_order_for_entry($entry, $importer, 'employmenthistory'));
             ArtefactTypeResumeComposite::ensure_composite_value($values, 'employmenthistory', $importer->get('usr'));
             break;
         case self::STRATEGY_IMPORT_AS_BOOK:
             $dates = PluginImportLeap::get_leap_dates($entry, $importer->get_namespaces(), $importer->get_leap2a_namespace());
             $enddate = isset($dates['end']) ? self::convert_leap_date_to_resume_date($dates['end']) : '';
             $contribution = $description = '';
             if (count($otherentries)) {
                 $role = $importer->get_entry_by_id($otherentries[0]);
                 $contribution = $role->title;
                 $description = PluginImportLeap::get_entry_content($role, $importer);
             }
             // check if the import is of the version leap2a 2010-07. If it is then override the contribution and description
             if ($importer->get_leap2a_namespace() == PluginImportLeap::NS_LEAP) {
                 $myrole = PluginImportLeap::get_leap_myrole($entry, $importer->get_namespaces(), $importer->get_leap2a_namespace());
                 if ($myrole) {
                     $contribution = $myrole;
                 }
                 $description = PluginImportLeap::get_entry_content($entry, $importer);
             }
             $values = array('date' => $enddate, 'title' => $entry->title, 'contribution' => $contribution, 'description' => $description, 'displayorder' => self::get_display_order_for_entry($entry, $importer, 'book'));
             ArtefactTypeResumeComposite::ensure_composite_value($values, 'book', $importer->get('usr'));
             break;
         case self::STRATEGY_IMPORT_AS_EDUCATION:
             $dates = PluginImportLeap::get_leap_dates($entry, $importer->get_namespaces(), $importer->get_leap2a_namespace());
             $startdate = isset($dates['start']) ? self::convert_leap_date_to_resume_date($dates['start']) : '';
             $enddate = isset($dates['end']) ? self::convert_leap_date_to_resume_date($dates['end']) : '';
             $qualtype = $qualname = '';
             if (isset($otherentries['achievement'])) {
                 $qualification = $importer->get_entry_by_id($otherentries['achievement']);
                 $qualtype = $qualification->title;
                 $qualname = PluginImportLeap::get_entry_content($qualification, $importer);
             }
             $institution = '';
             if (isset($otherentries['organization'])) {
                 $organization = $importer->get_entry_by_id($otherentries['organization']);
                 $institution = $organization->title;
             }
             if (!$qualname) {
                 $qualname = $entry->title;
             }
             $values = array('startdate' => $startdate, 'enddate' => $enddate, 'qualtype' => $qualtype, 'qualname' => $qualname, 'institution' => $institution, 'qualdescription' => PluginImportLeap::get_entry_content($entry, $importer), 'displayorder' => self::get_display_order_for_entry($entry, $importer, 'educationhistory'));
             ArtefactTypeResumeComposite::ensure_composite_value($values, 'educationhistory', $importer->get('usr'));
             break;
         case self::STRATEGY_IMPORT_AS_MEMBERSHIP:
             $dates = PluginImportLeap::get_leap_dates($entry, $importer->get_namespaces(), $importer->get_leap2a_namespace());
             $startdate = isset($dates['start']) ? self::convert_leap_date_to_resume_date($dates['start']) : '';
             $enddate = isset($dates['end']) ? self::convert_leap_date_to_resume_date($dates['end']) : '';
             $values = array('startdate' => $startdate, 'enddate' => $enddate, 'title' => $entry->title, 'description' => PluginImportLeap::get_entry_content($entry, $importer), 'displayorder' => self::get_display_order_for_entry($entry, $importer, 'membership'));
             ArtefactTypeResumeComposite::ensure_composite_value($values, 'membership', $importer->get('usr'));
             break;
         case self::STRATEGY_IMPORT_AS_SELECTION:
             // This space intentionally left blank
             break;
         default:
             throw new ImportException($importer, 'TODO: get_string: unknown strategy chosen for importing entry');
     }
     return $artefactmapping;
 }
コード例 #2
0
 /**
  * Creates a plan or task from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the plan or task from
  * @param PluginImportLeap $importer The importer
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  */
 private static function create_plan(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     // First decide if it's going to be a plan or a task depending
     // on whether it has any ancestral plans.
     if (self::get_ancestor_entryid($entry, $importer)) {
         $artefact = new ArtefactTypeTask();
     } else {
         $artefact = new ArtefactTypePlan();
     }
     $artefact->set('title', (string) $entry->title);
     $artefact->set('description', PluginImportLeap::get_entry_content($entry, $importer));
     $artefact->set('owner', $importer->get('usr'));
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $artefact->set('authorname', $entry->author->name);
     } else {
         $artefact->set('author', $importer->get('usr'));
     }
     if ($published = strtotime((string) $entry->published)) {
         $artefact->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $artefact->set('mtime', $updated);
     }
     $artefact->set('tags', PluginImportLeap::get_entry_tags($entry));
     // Set completiondate and completed status if we can find them
     if ($artefact instanceof ArtefactTypeTask) {
         $namespaces = $importer->get_namespaces();
         $ns = $importer->get_leap2a_namespace();
         $dates = PluginImportLeap::get_leap_dates($entry, $namespaces, $ns);
         if (!empty($dates['target']['value'])) {
             $completiondate = strtotime($dates['target']['value']);
         }
         $artefact->set('completiondate', empty($completiondate) ? $artefact->get('mtime') : $completiondate);
         if ($entry->xpath($namespaces[$ns] . ':status[@' . $namespaces[$ns] . ':stage="completed"]')) {
             $artefact->set('completed', 1);
         }
     }
     $artefact->commit();
     return array($artefact->get('id'));
 }
コード例 #3
0
 /**
  * Creates a cpd or activity from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the cpd or activity from
  * @param PluginImportLeap $importer The importer
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  */
 private static function create_cpd(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     // First decide if it's going to be a cpd or a activity depending
     // on whether it has any ancestral cpds.
     if (self::get_ancestor_entryid($entry, $importer)) {
         $artefact = new ArtefactTypeActivity();
     } else {
         $artefact = new ArtefactTypeCPD();
     }
     $artefact->set('title', (string) $entry->title);
     $artefact->set('description', PluginImportLeap::get_entry_content($entry, $importer));
     $artefact->set('owner', $importer->get('usr'));
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $artefact->set('authorname', $entry->author->name);
     } else {
         $artefact->set('author', $importer->get('usr'));
     }
     if ($published = strtotime((string) $entry->published)) {
         $artefact->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $artefact->set('mtime', $updated);
     }
     $artefact->set('tags', PluginImportLeap::get_entry_tags($entry));
     // Set startdate and hours status if we can find them
     if ($artefact instanceof ArtefactTypeActivity) {
         $namespaces = $importer->get_namespaces();
         $ns = $importer->get_leap2a_namespace();
         $startdate = $enddate = null;
         $dates = PluginImportLeap::get_leap_dates($entry, $namespaces, $ns);
         if (!empty($dates['start']['value'])) {
             $startdate = strtotime($dates['start']['value']);
         }
         if (!empty($dates['end']['value'])) {
             $enddate = strtotime($dates['end']['value']);
         }
         $artefact->set('startdate', empty($startdate) ? $artefact->get('mtime') : $startdate);
         $artefact->set('enddate', $enddate);
         $location = $entry->xpath($namespaces[$ns] . ':spatial');
         if (is_array($location) && count($location) == 1) {
             $artefact->set('location', $location[0]);
         }
         $hours = $entry->xpath($namespaces[PluginImportLeap::NS_MAHARA] . ':hours');
         if (is_array($hours) && count($hours) == 1) {
             $artefact->set('hours', $hours[0]);
         }
     }
     $artefact->commit();
     return array($artefact->get('id'));
 }