예제 #1
0
파일: lib.php 프로젝트: vohung96/mahara
 public function __construct($id = 0, $data = null)
 {
     if (empty($id)) {
         $data['title'] = get_string('personalinformation', 'artefact.resume');
     }
     parent::__construct($id, $data);
     $this->composites = ArtefactTypePersonalinformation::get_composite_fields();
     if (!empty($id)) {
         $this->composites = (array) get_record('artefact_resume_personal_information', 'artefact', $id, null, null, null, null, '*, ' . db_format_tsfield('dateofbirth'));
     }
 }
예제 #2
0
파일: lib.php 프로젝트: sarahjcotton/mahara
 /**
  * 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;
 }