public function get($field) { if ($field == 'xml') { return $this->xml; } return parent::get($field); }
/** * Imports data for the personalinformation artefact type, by looking for * it in the persondata element */ public static function import_author_data(PluginImport $importer, $persondataid) { if ($persondataid) { $composites = array(); $person = $importer->get_entry_by_id($persondataid); $namespaces = $importer->get_namespaces(); $ns = $importer->get_leap2a_namespace(); $persondata = $person->xpath($namespaces[$ns] . ':persondata'); foreach ($persondata as $item) { $leapattributes = PluginImportLeap::get_attributes($item, $ns); if (!isset($leapattributes['field'])) { // 'Field' is required // http://wiki.cetis.ac.uk/2009-03/Leap2A_personal_data#field $importer->trace('WARNING: persondata element did not have leap2:field attribute'); continue; } if ($leapattributes['field'] == 'dob') { $composites['dateofbirth'] = (string) $item; } if ($leapattributes['field'] == 'gender') { $gender = (string) $item; if ($gender == '1') { $composites['gender'] = 'male'; } else { if ($gender == '2') { $composites['gender'] = 'female'; } else { $importer->trace('WARNING: gender found but not male or female - no gender stored for this user'); } } } $maharaattributes = PluginImportLeap::get_attributes($item, PluginImportLeap::NS_MAHARA); if (isset($maharaattributes['field'])) { if (in_array($maharaattributes['field'], array('placeofbirth', 'citizenship', 'visastatus', 'maritalstatus'))) { $composites[$maharaattributes['field']] = (string) $item; } } } if ($composites) { $importer->trace('Resume personal information:'); $importer->trace($composites); $artefact = new ArtefactTypePersonalinformation(0, array('owner' => $importer->get('usr'))); foreach ($composites as $key => $value) { $artefact->set_composite($key, $value); } $artefact->commit(); } } }
/** * Imports data for the "Personal Information" section of the resume. * TODO: Currently the user has to make one decision about all of it -- it would be nice if * they could make a separate decision about each field. * @param PluginImport $importer * @param array $entry_request * @return int The ID of the artefact created or updated, or 0 if none was touched */ private static function create_personalinformation_artefact_from_request(PluginImport $importer, $entry_request) { global $USER; $aid = 0; $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; case PluginImport::DECISION_REPLACE: $existingids = unserialize($entry_request->existingitemids); if (!empty($existingids)) { try { $a = artefact_instance_from_id($existingids[0]); if ($USER->get('id') != $a->get('owner')) { return 0; } } catch (Exception $e) { return 0; } } break; case PluginImport::DECISION_APPEND: // We will literally append the content of each text field to each existing text field // We ignore numeric and date fields $existingids = unserialize($entry_request->existingitemids); if (!empty($existingids)) { try { $a = artefact_instance_from_id($existingids[0]); if ($USER->get('id') != $a->get('owner')) { return 0; } foreach (array_keys(ArtefactTypePersonalinformation::get_composite_fields()) as $fieldname) { if (!empty($values[$fieldname]) && !is_numeric($values[$fieldname]) && $fieldname !== 'dateofbirth') { $values[$fieldname] = $a->get_composite($fieldname) . ' ' . $values[$fieldname]; } } } catch (ArtefactNotFoundException $e) { $a = new ArtefactTypePersonalinformation(0, array('owner' => $importer->get('usr'), 'title' => get_string($entry_request->entrytype, 'artefact.resume'))); $a->commit(); } catch (Exception $e) { return 0; } break; } break; case PluginImport::DECISION_ADDNEW: try { $a = artefact_instance_from_type('personalinformation', $USER->get('id')); $a->set('mtime', time()); } catch (ArtefactNotFoundException $e) { $a = new ArtefactTypePersonalinformation(0, array('owner' => $importer->get('usr'), 'title' => get_string($entry_request->entrytype, 'artefact.resume'))); } catch (Exception $e) { return 0; } break; default: break; } if (isset($a)) { foreach (array_keys(ArtefactTypePersonalinformation::get_composite_fields()) as $field) { if (!empty($values[$field])) { $a->set_composite($field, $values[$field]); } } $a->commit(); $aid = $a->get('id'); } if ($aid) { $importer->add_artefactmapping($entry_request->entryid, $aid); } return $aid; }
/** * Creates an artefact in the manner required to overwrite existing profile * artefacts * * @param PluginImport $importer The importer * @param string $artefacttype The type of artefact to create * @param string $title The title for the artefact (with profile * fields, this is the main data) * @return int The ID of the artefact created */ private static function create_artefact(PluginImport $importer, $artefacttype, $title) { $classname = 'ArtefactType' . ucfirst($artefacttype); $artefact = new $classname(0, array('owner' => $importer->get('usr'))); $artefact->set('title', $title); $artefact->commit(); return $artefact->get('id'); }