Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * Create or update a composite artefact for resume from an import entry request
  * @param PluginImport $importer
  * @param unknown_type $entry_request
  */
 private static function create_composite_artefact_from_request(PluginImport $importer, $entry_request)
 {
     global $USER;
     $aid = 0;
     $classname = generate_artefact_class_name($entry_request->entrytype);
     $values = unserialize($entry_request->entrycontent);
     switch ($entry_request->decision) {
         case PluginImport::DECISION_IGNORE:
             $duplicatedids = unserialize($entry_request->duplicateditemids);
             if (!empty($duplicatedids)) {
                 $aid = $duplicatedids[0];
             }
             break;
             // For composite artefacts, it only makes sense to ignore or replace them, and those are
             // the only options the form should have shown! To make things less crashy, though, we'll
             // just default to the same behavior as long as you specified anything other than
             // DECISION_IGNORE
         // For composite artefacts, it only makes sense to ignore or replace them, and those are
         // the only options the form should have shown! To make things less crashy, though, we'll
         // just default to the same behavior as long as you specified anything other than
         // DECISION_IGNORE
         case PluginImport::DECISION_REPLACE:
         case PluginImport::DECISION_ADDNEW:
         case PluginImport::DECISION_APPEND:
         default:
             $result = ArtefactTypeResumeComposite::ensure_composite_value($values, $entry_request->entrytype, $USER->get('id'));
             $aid = isset($result['error']) ? 0 : $result['artefactid'];
             break;
     }
     if ($aid) {
         $importer->add_artefactmapping($entry_request->entryid, $aid);
         return $aid;
     }
     return null;
 }