Detailsicht StudentIn, Speichern

This commit is contained in:
ma0068
2023-09-28 08:45:54 +02:00
parent 9eeaeb2a14
commit 41ff430464
4 changed files with 231 additions and 60 deletions
@@ -10,28 +10,27 @@ class Student extends FHC_Controller
parent::__construct();
}
public function getPerson($person_id)
public function get($prestudent_id)
{
$this->load->model('person/Person_model', 'PersonModel');
// TODO(chris): stdSem from Variable
$studiensemester_kurzbz='SS2023';
$result = $this->PersonModel->load($person_id);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$this->outputJson(getError($result));
} elseif (!hasData($result)) {
$this->output->set_status_header(REST_Controller::HTTP_NOT_FOUND);
$this->outputJson('NOT FOUND');
} else {
$this->outputJson(current(getData($result)));
}
}
public function getStudent($student_uid)
{
// TODO(chris): this is wrong
$this->load->model('crm/Student_model', 'StudentModel');
$result = $this->StudentModel->load([$student_uid]);
$this->StudentModel->addSelect('p.*');
$this->StudentModel->addSelect('tbl_student.student_uid');
$this->StudentModel->addSelect('matrikelnr');
$this->StudentModel->addSelect('b.aktiv');
$this->StudentModel->addSelect('v.semester');
$this->StudentModel->addSelect('v.verband');
$this->StudentModel->addSelect('v.gruppe');
$this->StudentModel->addSelect('b.alias');
$this->StudentModel->addJoin('public.tbl_benutzer b', 'student_uid = uid');
$this->StudentModel->addJoin('public.tbl_studentlehrverband v', 'b.uid = v.student_uid AND v.studiensemester_kurzbz = ' . $this->StudentModel->escape($studiensemester_kurzbz), 'LEFT');
$this->StudentModel->addJoin('public.tbl_person p', 'person_id');
$result = $this->StudentModel->loadWhere(['prestudent_id' => $prestudent_id]);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$this->outputJson(getError($result));
@@ -90,5 +89,133 @@ class Student extends FHC_Controller
} else {
$this->outputJson(getData($result) ?: []);
}
}
public function save($prestudent_id)
{
// TODO(chris): stdSem from Variable
$studiensemester_kurzbz='SS2023';
$this->load->model('person/Person_model', 'PersonModel');
$this->load->model('crm/Student_model', 'StudentModel');
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
$this->load->model('education/Studentlehrverband_model', 'StudentlehrverbandModel');
$data = json_decode(utf8_encode($this->input->raw_input_stream), true);
$result = $this->StudentModel->loadWhere(['prestudent_id' =>$prestudent_id]);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
return $this->outputJson(getError($result));
} elseif (!hasData($result)) {
$uid = null;
} else {
$student = current(getData($result));
$uid = $student->student_uid;
}
$result = $this->PrestudentModel->loadWhere(['prestudent_id' =>$prestudent_id]);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
return $this->outputJson(getError($result));
} elseif (!hasData($result)) {
$person_id= null;
} else {
$person = current(getData($result));
$person_id = $person->person_id;
}
$array_allowed_props = ['verband','semester','gruppe'];
$update = array();
foreach ($array_allowed_props as $prop)
{
if(isset($data[$prop])){
$update[$prop] = $data[$prop];
}
}
//TODO(chris): form validation verband
if (count($update))
{
if($uid === null)
{
$this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST);
return $this->outputJson("Kein/e StudentIn vorhanden!");
}
$this->StudentlehrverbandModel->update([
'studiensemester_kurzbz' => $studiensemester_kurzbz,
'student_uid' => $uid],
$update
);
}
$array_allowed_props = [
'anrede',
'bpk',
'titelpre',
'titelpost',
'nachname',
'vorname',
'vornamen',
'wahlname',
'geburtsdatum',
'gebort',
'geburtsnation',
'svnr',
'ersatzkennzeichen',
'staatsbuergerschaft',
'matr_nr',
'sprache',
'geschlecht',
'familienstand',
'foto',
'anmerkung',
'homepage'
];
$update = array();
foreach ($array_allowed_props as $prop)
{
if(isset($data[$prop])){
$update[$prop] = $data[$prop];
}
}
if (count($update))
{
if($person_id === null)
{
$this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST);
return $this->outputJson("Keine Person vorhanden!");
}
$this->PersonModel->update(
$person_id,
$update
);
}
$array_allowed_props = ['matrikelnr'];
$update = array();
foreach ($array_allowed_props as $prop)
{
if(isset($data[$prop])){
$update[$prop] = $data[$prop];
}
}
if (count($update))
{
if ($uid === null) {
$this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST);
return $this->outputJson("Kein/e StudentIn vorhanden!");
}
$this->StudentModel->update(
[$uid],
$update
);
}
}
}
@@ -283,7 +283,8 @@ class Students extends FHC_Controller
$this->PrestudentModel->addJoin('public.tbl_benutzer b', 's.student_uid=b.uid');
$this->PrestudentModel->addJoin(
'public.tbl_studentlehrverband v',
'v.student_uid=s.student_uid AND v.studiensemester_kurzbz=' . $this->PrestudentModel->escape($studiensemester_kurzbz)
'v.student_uid=s.student_uid AND v.studiensemester_kurzbz=' . $this->PrestudentModel->escape($studiensemester_kurzbz),
'LEFT'
);
$this->PrestudentModel->addSelect('p.person_id');
@@ -18,13 +18,21 @@ export default {
}
}
},
computed: {
hasNoStudent() {
return !this.student || (Object.keys(this.student).length === 0 && this.student.constructor === Object);
}
},
template: `
<div class="stv-details h-100 pb-3">
<ul class="nav nav-tabs">
<li v-for="(title, comp) in tabs" class="nav-item" :key="comp">
<a class="nav-link" :class="{active: comp == component}" :aria-current="comp == component ? 'page' : ''" href="#" @click="component=comp">{{title}}</a>
</li>
</ul>
<component :is="component" :student="student"></component>
<div v-if="hasNoStudent" class="justify-content-center d-flex h-100 align-items-center">Bitte StudentIn auswählen!</div>
<template v-else>
<ul class="nav nav-tabs">
<li v-for="(title, comp) in tabs" class="nav-item" :key="comp">
<a class="nav-link" :class="{active: comp == component}" :aria-current="comp == component ? 'page' : ''" href="#" @click="component=comp">{{title}}</a>
</li>
</ul>
<component :is="component" :student="student"></component>
</template>
</div>`
};
@@ -22,25 +22,30 @@ export default {
"v": "verheiratet",
"w": "verwitwet"
},
person: null,
data: null,
studentIn: null
}
},
watch: {
student(n) {
this.updateStudent(n);
}
},
methods: {
updateStudent(n) {
CoreRESTClient
.get('components/stv/Student/getPerson/' + this.student.person_id)
.get('components/stv/Student/get/' + n.prestudent_id)
.then(result => result.data)
.then(result => {
this.person = result;
if (!this.person.familienstand)
this.person.familienstand = '';
this.data = result;
if (!this.data.familienstand)
this.data.familienstand = '';
})
.catch(err => {
console.error(err.response.data || err.message);
});
CoreRESTClient
.get('components/stv/Student/getStudent/' + this.student.uid)
/*CoreRESTClient
.get('components/stv/Student/getStudent/' + n.uid)
.then(result => result.data)
.then(result => {
// TODO(chris): IMPLEMENT HERE!
@@ -49,7 +54,11 @@ export default {
})
.catch(err => {
console.error(err.response.data || err.message);
});
});*/
},
save() {
CoreRESTClient
.post('components/stv/Student/save/' + this.student.prestudent_id, this.data)
}
},
created() {
@@ -77,68 +86,71 @@ export default {
.catch(err => {
console.error(err.response.data || err.message);
});
this.updateStudent(this.student);
},
//TODO(chris): Felder student_uid, person_id sperren, Personenkz
//TODO(chris): Logik Feld Zugangscode
template: `
<div class="stv-details-details h-100 pb-3">
<fieldset>
<legend>Person</legend>
<template v-if="person">
<template v-if="data">
<div class="row mb-3">
<label for="stv-details-person_id" class="col-sm-1 col-form-label">Person ID</label>
<div class="col-sm-3">
<input id="stv-details-person_id" type="text" class="form-control" v-model="person.person_id">
<input id="stv-details-person_id" type="text" class="form-control" v-model="data.person_id">
</div>
<label for="stv-details-bpk" class="col-sm-1 col-form-label">BPK</label>
<div class="col-sm-3">
<input id="stv-details-bpk" type="text" class="form-control" v-model="person.bpk">
<input id="stv-details-bpk" type="text" class="form-control" v-model="data.bpk">
</div>
</div>
<div class="row mb-3">
<label for="stv-details-anrede" class="col-sm-1 col-form-label">Anrede</label>
<div class="col-sm-3">
<input id="stv-details-anrede" type="text" class="form-control" v-model="person.anrede">
<input id="stv-details-anrede" type="text" class="form-control" v-model="data.anrede">
</div>
<label for="stv-details-titelpre" class="col-sm-1 col-form-label">Titel Pre</label>
<div class="col-sm-3">
<input id="stv-details-titelpre" type="text" class="form-control" v-model="person.titelpre">
<input id="stv-details-titelpre" type="text" class="form-control" v-model="data.titelpre">
</div>
<label for="stv-details-titelpost" class="col-sm-1 col-form-label">Titel Post</label>
<div class="col-sm-3">
<input id="stv-details-titelpost" type="text" class="form-control" v-model="person.titelpost">
<input id="stv-details-titelpost" type="text" class="form-control" v-model="data.titelpost">
</div>
</div>
<div class="row mb-3">
<label for="stv-details-nachname" class="col-sm-1 col-form-label">Nachname</label>
<div class="col-sm-3">
<input id="stv-details-nachname" type="text" class="form-control" v-model="person.nachname">
<input id="stv-details-nachname" type="text" class="form-control" v-model="data.nachname">
</div>
<label for="stv-details-vorname" class="col-sm-1 col-form-label">Vorname</label>
<div class="col-sm-3">
<input id="stv-details-vorname" type="text" class="form-control" v-model="person.vorname">
<input id="stv-details-vorname" type="text" class="form-control" v-model="data.vorname">
</div>
<label for="stv-details-vornamen" class="col-sm-1 col-form-label">Vornamen</label>
<div class="col-sm-3">
<input id="stv-details-vornamen" type="text" class="form-control" v-model="person.vornamen">
<input id="stv-details-vornamen" type="text" class="form-control" v-model="data.vornamen">
</div>
</div>
<div class="row mb-3">
<label for="stv-details-wahlname" class="col-sm-1 col-form-label">Wahlname</label>
<div class="col-sm-3">
<input id="stv-details-wahlname" type="text" class="form-control" v-model="person.wahlname">
<input id="stv-details-wahlname" type="text" class="form-control" v-model="data.wahlname">
</div>
</div>
<div class="row mb-3">
<label for="dp-input-stv-details-gebdatum" class="col-sm-1 col-form-label">Geburtsdatum</label>
<div class="col-sm-3">
<vue-date-picker uid="stv-details-gebdatum" v-model="person.gebdatum" :clearable="false" no-today auto-apply :enable-time-picker="false" format="dd.MM.yyyy" preview-format="dd.MM.yyyy"></vue-date-picker>
<vue-date-picker uid="stv-details-gebdatum" v-model="data.gebdatum" :clearable="false" no-today auto-apply :enable-time-picker="false" format="dd.MM.yyyy" preview-format="dd.MM.yyyy"></vue-date-picker>
</div>
<label for="stv-details-gebort" class="col-sm-1 col-form-label">Geburtsort</label>
<div class="col-sm-3">
<input id="stv-details-gebort" type="text" class="form-control" v-model="person.gebort">
<input id="stv-details-gebort" type="text" class="form-control" v-model="data.gebort">
</div>
<label for="stv-details-geburtsnation" class="col-sm-1 col-form-label">Geburtsnation</label>
<div class="col-sm-3">
<select id="stv-details-geburtsnation" class="form-control" v-model="person.geburtsnation">
<select id="stv-details-geburtsnation" class="form-control" v-model="data.geburtsnation">
<option value="">-- keine Auswahl --</option>
<!-- TODO(chris): gesperrte nationen können nicht ausgewählt werden! Um das zu realisieren müsste man ein pseudo select machen -->
<option v-for="nation in nations" :key="nation.nation_code" :value="nation.nation_code" :disabled="nation.sperre">{{nation.kurztext}}</option>
@@ -148,17 +160,17 @@ export default {
<div class="row mb-3">
<label for="stv-details-svnr" class="col-sm-1 col-form-label">SVNR</label>
<div class="col-sm-3">
<input id="stv-details-svnr" type="text" class="form-control" v-model="person.svnr">
<input id="stv-details-svnr" type="text" class="form-control" v-model="data.svnr">
</div>
<label for="stv-details-ersatzkennzeichen" class="col-sm-1 col-form-label">Ersatzkennzeichen</label>
<div class="col-sm-3">
<input id="stv-details-ersatzkennzeichen" type="text" class="form-control" v-model="person.ersatzkennzeichen">
<input id="stv-details-ersatzkennzeichen" type="text" class="form-control" v-model="data.ersatzkennzeichen">
</div>
</div>
<div class="row mb-3">
<label for="stv-details-staatsbuergerschaft" class="col-sm-1 col-form-label">Staatsbürgerschaft</label>
<div class="col-sm-3">
<select id="stv-details-staatsbuergerschaft" class="form-control" v-model="person.staatsbuergerschaft">
<select id="stv-details-staatsbuergerschaft" class="form-control" v-model="data.staatsbuergerschaft">
<option value="">-- keine Auswahl --</option>
<!-- TODO(chris): gesperrte nationen können nicht ausgewählt werden! Um das zu realisieren müsste man ein pseudo select machen -->
<option v-for="nation in nations" :key="nation.nation_code" :value="nation.nation_code" :disabled="nation.sperre">{{nation.kurztext}}</option>
@@ -166,11 +178,11 @@ export default {
</div>
<label for="stv-details-matr_nr" class="col-sm-1 col-form-label">Matrikelnummer</label>
<div class="col-sm-3">
<input id="stv-details-matr_nr" type="text" class="form-control" v-model="person.matr_nr">
<input id="stv-details-matr_nr" type="text" class="form-control" v-model="data.matr_nr">
</div>
<label for="stv-details-sprache" class="col-sm-1 col-form-label">Sprache</label>
<div class="col-sm-3">
<select id="stv-details-sprache" class="form-control" v-model="person.sprache">
<select id="stv-details-sprache" class="form-control" v-model="data.sprache">
<option v-for="sprache in sprachen" :key="sprache.sprache" :value="sprache.sprache">{{sprache.sprache}}</option>
</select>
</div>
@@ -178,13 +190,13 @@ export default {
<div class="row mb-3">
<label for="stv-details-geschlecht" class="col-sm-1 col-form-label">Geschlecht</label>
<div class="col-sm-3">
<select id="stv-details-geschlecht" class="form-control" v-model="person.geschlecht">
<select id="stv-details-geschlecht" class="form-control" v-model="data.geschlecht">
<option v-for="geschlecht in geschlechter" :key="geschlecht.geschlecht" :value="geschlecht.geschlecht">{{geschlecht.bezeichnung}}</option>
</select>
</div>
<label for="stv-details-familienstand" class="col-sm-1 col-form-label">Familienstand</label>
<div class="col-sm-3">
<select id="stv-details-familienstand" class="form-control" v-model="person.familienstand">
<select id="stv-details-familienstand" class="form-control" v-model="data.familienstand">
<option v-for="(bezeichnung, key) in familienstaende" :key="key" :value="key">{{bezeichnung}}</option>
</select>
</div>
@@ -192,7 +204,7 @@ export default {
<div class="row mb-3">
<label for="stv-details-foto" class="col-sm-1 col-form-label">Foto</label>
<div class="col-sm-3">
<form-upload-image id="stv-details-foto" v-model="person.foto"></form-upload-image>
<form-upload-image id="stv-details-foto" v-model="data.foto"></form-upload-image>
</div>
<label for="stv-details-anmerkung" class="col-sm-1 col-form-label">Anmerkung</label>
<div class="col-sm-3">
@@ -200,7 +212,7 @@ export default {
</div>
<label for="stv-details-homepage" class="col-sm-1 col-form-label">Homepage</label>
<div class="col-sm-3">
<input id="stv-details-homepage" type="text" class="form-control" v-model="person.homepage">
<input id="stv-details-homepage" type="text" class="form-control" v-model="data.homepage">
</div>
</div>
</template>
@@ -210,23 +222,46 @@ export default {
</fieldset>
<fieldset>
<legend>StudentIn</legend>
<template v-if="studentIn">
<div class="row mb-3">
<template v-if="data">
<div class="row mb-3 align-items-center">
<label for="stv-details-student_uid" class="col-sm-1 col-form-label">UID</label>
<div class="col-sm-3">
<input id="stv-details-student_uid" type="text" class="form-control" v-model="studentIn.student_uid">
<input id="stv-details-student_uid" type="text" class="form-control" v-model="data.student_uid">
</div>
<label for="stv-details-personenkennzeichen" class="col-sm-1 col-form-label">Personenkennzeichen</label>
<div class="col-sm-3">
<input id="stv-details-personenkennzeichen" type="text" class="form-control" v-model="studentIn.personenkennzeichen">
<input id="stv-details-personenkennzeichen" type="text" class="form-control" v-model="data.matrikelnr">
</div>
<label for="stv-details-aktiv" class="col-sm-1 col-form-label">Aktiv</label>
<div class="col-sm-3">
<div class="form-check">
<input id="stv-details-aktiv" type="checkbox" class="form-check-input" v-model="studentIn.aktiv">
<input id="stv-details-aktiv" type="checkbox" class="form-check-input" v-model="data.aktiv">
</div>
</div>
</div>
<div class="row mb-3 align-items-center">
<label for="stv-details-semester" class="col-sm-1 col-form-label">Semester</label>
<div class="col-sm-3">
<input id="stv-details-semester" type="text" class="form-control" v-model="data.semester">
</div>
<label for="stv-details-verband" class="col-sm-1 col-form-label">Verband</label>
<div class="col-sm-3">
<input id="stv-details-verband" type="text" class="form-control" v-model="data.verband">
</div>
<label for="stv-details-gruppe" class="col-sm-1 col-form-label">Gruppe</label>
<div class="col-sm-3">
<input id="stv-details-gruppe" type="text" class="form-control" v-model="data.gruppe">
</div>
</div>
<div class="row mb-3 align-items-center">
<label for="stv-details-alias" class="col-sm-1 col-form-label">Alias</label>
<div class="col-sm-3">
<input id="stv-details-alias" type="text" class="form-control" v-model="data.alias">
</div>
</div>
<div>
<button type="button" class="btn btn-primary" @click="save">Speichern</button>
</div>
</template>
<div v-else>
Loading...