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); } }
public static function render_fields(ArtefactTypePersonalInformation $a = null, $options = array(), $values = null) { $smarty = smarty_core(); $fields = array(); foreach (array_keys(ArtefactTypePersonalInformation::get_composite_fields()) as $field) { if ($values && isset($values[$field])) { $value = $values[$field]; // TODO: Make this be a call to a subclass instead of a hard-coded listing // of special behaviors for particular fields if ($field == 'dateofbirth') { if (empty($value)) { $value = ''; } else { $value = strtotime($value); } } } else { if ($a) { $value = $a->get_composite($field); } else { continue; } } if ($field == 'gender' && !empty($value)) { $value = get_string($value, 'artefact.resume'); } if ($field == 'dateofbirth' && !empty($value)) { $value = format_date($value + 3600, 'strftimedate'); } $fields[get_string($field, 'artefact.resume')] = $value; } $smarty->assign('fields', $fields); if ($a) { $a->render_license($options, $smarty); } return $smarty->fetch('artefact:resume:fragments/personalinformation.tpl'); }
public function render_self($options) { $smarty = smarty_core(); $fields = array(); foreach (array_keys(ArtefactTypePersonalInformation::get_composite_fields()) as $field) { $value = $this->get_composite($field); if ($field == 'gender' && !empty($value)) { $value = get_string($value, 'artefact.resume'); } if ($field == 'dateofbirth' && !empty($value)) { $value = strftime(get_string('strftimedate'), $value); } $fields[get_string($field, 'artefact.resume')] = $value; } $smarty->assign('fields', $fields); return array('html' => $smarty->fetch('artefact:resume:fragments/personalinformation.tpl')); }