Ejemplo n.º 1
0
function personalinformation_submit(Pieform $form, $values)
{
    global $personalinformation, $USER;
    $userid = $USER->get('id');
    $errors = array();
    try {
        if (empty($personalinformation)) {
            $personalinformation = new ArtefactTypePersonalinformation(0, array('owner' => $userid, 'title' => get_string('personalinformation', 'artefact.resume')));
        }
        foreach (array_keys(ArtefactTypePersonalInformation::get_composite_fields()) as $field) {
            $personalinformation->set_composite($field, $values[$field]);
        }
        $personalinformation->commit();
    } catch (Exception $e) {
        $errors['personalinformation'] = true;
    }
    if (empty($errors)) {
        $form->json_reply(PIEFORM_OK, get_string('resumesaved', 'artefact.resume'));
    } else {
        $message = '';
        foreach (array_keys($errors) as $key) {
            $message .= get_string('resumesavefailed', 'artefact.resume') . "\n";
        }
        $form->json_reply(PIEFORM_ERR, $message);
    }
}
Ejemplo n.º 2
0
function resumelicense_submit(Pieform $form, $values)
{
    global $personalinformation, $USER;
    $userid = $USER->get('id');
    if (empty($personalinformation)) {
        $personalinformation = new ArtefactTypePersonalinformation(0, array('owner' => $userid, 'title' => get_string('personalinformation', 'artefact.resume')));
    }
    if (get_config('licensemetadata')) {
        $personalinformation->set('license', $values['license']);
        $personalinformation->set('licensor', $values['licensor']);
        $personalinformation->set('licensorurl', $values['licensorurl']);
    }
    $personalinformation->commit();
    $result = array('error' => false, 'message' => get_string('resumesaved', 'artefact.resume'), 'goto' => get_config('wwwroot') . 'artefact/resume/license.php');
    if ($form->submitted_by_js()) {
        $SESSION->add_ok_msg($result['message']);
        $form->json_reply(PIEFORM_OK, $result, false);
    }
    $form->reply(PIEFORM_OK, $result);
}
Ejemplo n.º 3
0
 /**
  * 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();
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }